lkml.org 
[lkml]   [2023]   [Jan]   [28]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH-next v2 1/2] driver core: introduce get_device_unless_zero()
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

\
 
 \ /
  Last update: 2023-03-27 00:00    [W:0.073 / U:0.336 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site