From: Wenchao Hao <haowenchao@huawei.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: <fmdefrancesco@gmail.com>, <axboe@kernel.dk>,
<jejb@linux.ibm.com>, <linux-block@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <linux-scsi@vger.kernel.org>,
<martin.petersen@oracle.com>,
<syzbot+f08c77040fa163a75a46@syzkaller.appspotmail.com>,
<syzkaller-bugs@googlegroups.com>, <linfeilong@huawei.com>
Subject: Re: [PATCH] scsi: sd: call device_del() if device_add_disk() fails
Date: Thu, 31 Mar 2022 20:14:52 +0800 [thread overview]
Message-ID: <fdebdbd3-575b-b30e-d37f-dcc6d53a4f53@huawei.com> (raw)
In-Reply-To: <20220331054156.GI3293@kadam>
On 2022/3/31 13:41, Dan Carpenter wrote:
> On Thu, Mar 31, 2022 at 11:26:22AM -0400, 'Wenchao Hao' via syzkaller-bugs wrote:
>> I do not think it's necessary to call device_del() on this path. If the device
>> has been added, put_device() would delete it from sysfs. So the origin error
>> handle is ok with me.
>>
>
> No. The original is buggy and it was detected at runtime by syzbot.
> It's not static analysis, it is an actual bug found in testing.
>
Yes, it's a bug, but the root reason is not we forget to call
device_del(sdkp->disk_dev). It's because we did not cleanup gendisk.
The leak memory is allocated in elevator_init_mq(), we should clean
this memory via blk_cleanup_queue().
I summit a patch which would fix this memory leak:
https://lore.kernel.org/linux-scsi/20220401011018.1026553-1-haowenchao@huawei.com/T/#u
> The device_put() unwinds device_initialize(). The device_del() unwinds
> device_add(). Take a look at the comments to device_add() or take a
> look at how device_register/unregister() work.
>
You may read the implement of put_device(), it is based on kobj_xxx.
If the kobj is still in sysfs, a cleanup would be performed.
And device_del() seems would not decrease the reference count of kobj,
the main aim is to make it invisibleto sysfs.
next prev parent reply other threads:[~2022-03-31 12:14 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-29 15:49 [PATCH] scsi: sd: call device_del() if device_add_disk() fails Fabio M. De Francesco
2022-03-30 4:30 ` Dan Carpenter
2022-03-31 15:26 ` Wenchao Hao
2022-03-31 5:41 ` Dan Carpenter
2022-03-31 5:45 ` Christoph Hellwig
2022-03-31 9:07 ` Fabio M. De Francesco
2022-03-31 9:13 ` Christoph Hellwig
2022-03-31 10:13 ` Fabio M. De Francesco
2022-03-31 12:14 ` Wenchao Hao [this message]
2022-03-31 13:42 ` Dan Carpenter
2022-03-31 14:19 ` James Bottomley
2022-03-31 15:11 ` Dan Carpenter
2022-03-31 16:14 ` Fabio M. De Francesco
2022-03-31 16:24 ` Dan Carpenter
2022-03-31 17:21 ` Fabio M. De Francesco
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=fdebdbd3-575b-b30e-d37f-dcc6d53a4f53@huawei.com \
--to=haowenchao@huawei.com \
--cc=axboe@kernel.dk \
--cc=dan.carpenter@oracle.com \
--cc=fmdefrancesco@gmail.com \
--cc=jejb@linux.ibm.com \
--cc=linfeilong@huawei.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=syzbot+f08c77040fa163a75a46@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.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