Re: [PATCH v5 22/27] scsi: sd: add multipath disk class

John Garry <[email protected]>
Newsgroups org.kernel.vger.linux-scsi,dev.linux.lists.sashiko-reviews
Organization Oracle Corporation
Message-ID <[email protected]>
On 27/07/2026 16:14, [email protected] wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Medium] Empty device release function `sd_mpath_disk_release` violates kobject API rules, masking a future memory leak or Use-After-Free.
> --
> 
> --- Patch [22]: [PATCH v5 22/27] scsi: sd: add multipath disk class ---
> commit f2a48f7b23ab293ee7178e9c9e97a979e61dbc55
> Author: John Garry <[email protected]>
> 
> scsi: sd: add multipath disk class
>      
> This commit adds a new class, sd_mpath_disk_class, which acts as the
> multipath version of the scsi_disk class. It also introduces the
> sd_mpath_disk structure to manage the multipath gendisk.
> 
>> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
>> index 599e75f333343..242a15bc2c5bb 100644
>> --- a/drivers/scsi/sd.c
>> +++ b/drivers/scsi/sd.c
> 
> [ ... ]
> 
>> @@ -113,6 +114,39 @@ static mempool_t *sd_page_pool;
>>   static mempool_t *sd_large_page_pool;
>>   static atomic_t sd_large_page_pool_users = ATOMIC_INIT(0);
>>   static struct lock_class_key sd_bio_compl_lkclass;
>> +#ifdef CONFIG_SCSI_MULTIPATH
>> +struct sd_mpath_disk {
>> +	struct scsi_mpath_head		*scsi_mpath_head;
>> +};
>> +
> 
> [Severity: Medium]
> Does this empty release function violate the device lifecycle rules?

it's added later

> 
> The kernel core API strictly forbids empty device release functions (often
> referred to as 'mocking kobjects'). An empty release callback prevents the
> proper freeing of the structure containing the device, which forces the
> memory to either be leaked when the reference count drops to zero, or freed
> synchronously elsewhere leading to a Use-After-Free.
> 
>> +static void sd_mpath_disk_release(struct device *dev)
>> +{
>> +}
>> +
>> +static const struct class sd_mpath_disk_class = {
>> +	.name = "scsi_mpath_disk",
>> +	.dev_release = sd_mpath_disk_release,
>> +};
> 
> [ ... ]
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.