public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Zhong Jinghua <zhongjinghua@huawei.com>
Cc: jejb@linux.ibm.com, martin.petersen@oracle.com, hare@suse.de,
	bvanassche@acm.org, emilne@redhat.com,
	linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org,
	yi.zhang@huawei.com, yukuai3@huawei.com
Subject: Re: [PATCH-next v2 1/2] driver core: introduce get_device_unless_zero()
Date: Sat, 28 Jan 2023 11:43:20 +0100	[thread overview]
Message-ID: <Y9T8SION2vDlmaSa@kroah.com> (raw)
In-Reply-To: <20230128094146.205858-2-zhongjinghua@huawei.com>

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

  reply	other threads:[~2023-01-28 10:43 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-28  9:41 [PATCH-next v2 0/2] scsi, driver core: fix iscsi rescan fails to create block device Zhong Jinghua
2023-01-28  9:41 ` [PATCH-next v2 1/2] driver core: introduce get_device_unless_zero() Zhong Jinghua
2023-01-28 10:43   ` Greg KH [this message]
2023-01-28  9:41 ` [PATCH-next v2 2/2] scsi: fix iscsi rescan fails to create block device Zhong Jinghua
2023-01-28 10:45   ` Greg KH
2023-01-29  1:13     ` Yu Kuai
2023-01-29  6:46       ` Greg KH
2023-01-29  6:55         ` Yu Kuai
2023-01-29 17:30   ` James Bottomley
2023-01-30  3:07     ` Yu Kuai
2023-01-30  3:29       ` James Bottomley
2023-01-30  3:46         ` Yu Kuai
2023-01-30 13:17           ` James Bottomley
2023-01-31  1:43             ` Yu Kuai
2023-01-31  3:25               ` James Bottomley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y9T8SION2vDlmaSa@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=bvanassche@acm.org \
    --cc=emilne@redhat.com \
    --cc=hare@suse.de \
    --cc=jejb@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=yi.zhang@huawei.com \
    --cc=yukuai3@huawei.com \
    --cc=zhongjinghua@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox