Re: [PATCH-next v2 1/2] driver core: introduce get_device_unless_zero()
From: Greg KH
Date: Sat Jan 28 2023 - 05:43:38 EST
On Sat, Jan 28, 2023 at 05:41:45PM +0800, Zhong Jinghua wrote:
> When the dev reference count is 0, calling get_device will go from 0 to 1,
You can NOT have a device reference count that is 0. If you do, you are
doing something really really wrong, and there's a bug somewhere else.
> which will cause errors in some place of the kernel.
It's already an error in the kernel that tries to increment a reference
count of 0 as that device is already freed and you are working with
memory that is not present.
> So introduce a
> get_devcie_unless_zero method that returns NULL when the dev reference
> count is 0.
No, this is not ok, sorry, please never do this. Fix the caller.
thanks,
greg k-h