On Fri, Feb 26, 2016 at 8:06 PM, Bamvor Jian Zhang <bamv2005@xxxxxxxxx> wrote: > From: Bamvor Jian Zhang <bamvor.zhangjian@xxxxxxxxxx> > > In my gpiochip mockup driver, after call gpiochip_remove, the > gpipchip is not actually removed even if there is no clients in > userspace. It could be removed if remove the corresonding reference > count in this patch. > > But such gpiochip will be removed even if user space open the > corresponding chardev. I am not sure If I do not right thing. > Please correct me if I am wrong. > > Signed-off-by: Bamvor Jian Zhang <bamvor.zhangjian@xxxxxxxxxx> I think you're onto the right thing, thank you for looking into this. My idea was that the gdev->dev and gdev->cdev should stay around until the last userspace user is gone, even if the gpiochip_remove() was called. Maybe I just got the refcounts wrong :( It'd be great if you can come up with a patch that has the following properties: gpiochip_add_data(), no userspace users, gpiochip_remove() -> refcount goes to zero and gpiodevice_release() gets called gpiochip_add_data(), add some userspace users, gpiochip_remove() -> refcount does not go to zero and gpiodevice_release() is not called Then remove the userspace users: -> refcount goes to zero and gpiodevice_release() gets called It might be that using device_add(), device_del() directly like I'm doing cannot really solve this :( then we need to rethink the mechanism in terms of device_register()/device_unregister(), but I couldn't get that to work with the way chardevs are added. Yours, Linus Walleij -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html