On Sat, Mar 5, 2022 at 10:28 PM Nuno Sá <noname.nuno@xxxxxxxxx> wrote: > > On Fri, 2022-03-04 at 19:32 +0200, Andy Shevchenko wrote: > > Some of the fwnode APIs might return an error pointer instead of NULL > > or valid fwnode handle. The result of such API call may be considered > > optional and hence the test for it is usually done in a form of > > > > fwnode = fwnode_find_reference(...); > > if (IS_ERR_OR_NULL(fwnode)) > > ...error handling... > > > > Nevertheless the resulting fwnode may have bumped reference count and > > hence caller of the above API is obliged to call fwnode_handle_put(). > > Since fwnode may be not valid either as NULL or error pointer the > > check > > has to be performed there. This approach uglifies the code and adds > > a point of making a mistake, i.e. forgetting about error point case. > > > > To prevent this allow error pointer to be passed to the fwnode APIs. ... > > ret = fwnode_call_int_op(fwnode, property_read_string_array, > > propname, > > val, nval); > > - if (ret == -EINVAL && !IS_ERR_OR_NULL(fwnode) && > > - !IS_ERR_OR_NULL(fwnode->secondary)) > > + if (ret == -EINVAL && !IS_ERR_OR_NULL(fwnode->secondary)) > > ret = fwnode_call_int_op(fwnode->secondary, > > property_read_string_array, > > Isn't !IS_ERR_OR_NULL(fwnode->secondary)) redundant? AFAIU, > fwnode_call_int_op() will already check the fwnode and only call the op > if the pointer is valid... It will shadow the error code, but it seems currently it's the same error code. So, the question here is if we hide something important with that change. I dunno what is the best approach here (esp. taking into account that this is a fix), but ideally we should open code those macros to avoid double test for fwnode being valid. Because it seems that validation of fwnode and validation of the operation of the fwnode are orthogonal and here we mix them. I made this way for the sake of easier backporting and kicking off a discussion (as you already did). TL;DR: I think the introduction of the macros was a controversial move, for which I see pros and cons. -- With Best Regards, Andy Shevchenko