Thread (45 messages) flat view 45 messages, 4 authors, 2024-10-16

Re: [PATCH v8 4/8] i2c: Introduce OF component probe function

From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Date: 2024-10-16 10:29:45
Also in: chrome-platform, linux-devicetree, linux-i2c, linux-mediatek, lkml

On Wed, Oct 16, 2024 at 05:28:05PM +0800, Chen-Yu Tsai wrote:
On Wed, Oct 16, 2024 at 3:01 PM Chen-Yu Tsai [off-list ref] wrote:
quoted
On Wed, Oct 16, 2024 at 1:58 AM Doug Anderson [off-list ref] wrote:
quoted
On Tue, Oct 8, 2024 at 12:35 AM Chen-Yu Tsai [off-list ref] wrote:
...
quoted
quoted
...which means it'll call of_node_put() to free "i2c_node" when it
goes out of scope. of_node_put() handles NULL pointers but _not_ ERR
pointers. So I think that if you get an error back and then return via
the PTR_ERR(i2c_node) then it'll crash because it will try to free an
ERR pointer. Did I get that right? Presumably you need to instead do:

  return PTR_ERR(no_free_ptr(i2c_node));

...or change of_node_put() to be a noop for error pointers?
Good catch! As Andy suggested, it should be updated to handle both.
I'll add a patch for this.
On second thought, it might be better to change i2c_of_probe_get_i2c_node()
to return NULL on errors. That seems to be what most functions do. I only
found a handful of exceptions.
It seems that OF has been written in the assumption that device node pointer
is never an error pointer. So, probably fixing your function is the best
approach right now.

-- 
With Best Regards,
Andy Shevchenko


Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help