On Mon, Jul 4, 2022 at 11:13 AM Liang He <windhl@xxxxxxx> wrote: > > We should use of_node_get() when a new reference of device_node > is created. It is noted that the old reference stored in > 'mm_gc->gc.of_node' should also be decreased. > > Fixes: f141ed65f256 ("gpio: Move DT support code into drivers/gpio") > Signed-off-by: Liang He <windhl@xxxxxxx> > --- > drivers/gpio/gpiolib-of.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c > index 3d6c3ffd5576..de100b0217da 100644 > --- a/drivers/gpio/gpiolib-of.c > +++ b/drivers/gpio/gpiolib-of.c > @@ -860,7 +860,8 @@ int of_mm_gpiochip_add_data(struct device_node *np, > if (mm_gc->save_regs) > mm_gc->save_regs(mm_gc); > > - mm_gc->gc.of_node = np; > + of_node_put(mm_gc->gc.of_node); > + mm_gc->gc.of_node = of_node_get(np); > > ret = gpiochip_add_data(gc, data); > if (ret) > @@ -868,6 +869,7 @@ int of_mm_gpiochip_add_data(struct device_node *np, > > return 0; > err2: > + of_node_put(np); > iounmap(mm_gc->regs); > err1: > kfree(gc->label); > -- > 2.25.1 > Have you noticed any issue with reference counting that made you post this patch? We typically "borrow" the reference to the platform device's of_node in GPIO drivers (and everywhere I can think of too). Bart