Skip to content

Commit fd81bc5

Browse files
bmarzinsmartinkpetersen
authored andcommitted
scsi: device_handler: Return error pointer in scsi_dh_attached_handler_name()
If scsi_dh_attached_handler_name() fails to allocate the handler name, dm-multipath (its only caller) assumes there is no attached device handler, and sets the device up incorrectly. Return an error pointer instead, so multipath can distinguish between failure, success where there is no attached device handler, or when the path device is not a SCSI device at all. Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com> Reviewed-by: Martin Wilck <mwilck@suse.com> Link: https://patch.msgid.link/20251206010015.1595225-1-bmarzins@redhat.com Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent d2875b8 commit fd81bc5

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

drivers/md/dm-mpath.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,19 @@ static struct pgpath *parse_path(struct dm_arg_set *as, struct path_selector *ps
962962

963963
q = bdev_get_queue(p->path.dev->bdev);
964964
attached_handler_name = scsi_dh_attached_handler_name(q, GFP_KERNEL);
965+
if (IS_ERR(attached_handler_name)) {
966+
if (PTR_ERR(attached_handler_name) == -ENODEV) {
967+
if (m->hw_handler_name) {
968+
DMERR("hardware handlers are only allowed for SCSI devices");
969+
kfree(m->hw_handler_name);
970+
m->hw_handler_name = NULL;
971+
}
972+
attached_handler_name = NULL;
973+
} else {
974+
r = PTR_ERR(attached_handler_name);
975+
goto bad;
976+
}
977+
}
965978
if (attached_handler_name || m->hw_handler_name) {
966979
INIT_DELAYED_WORK(&p->activate_path, activate_path_work);
967980
r = setup_scsi_dh(p->path.dev->bdev, m, &attached_handler_name, &ti->error);

drivers/scsi/scsi_dh.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,8 @@ EXPORT_SYMBOL_GPL(scsi_dh_attach);
353353
* that may have a device handler attached
354354
* @gfp - the GFP mask used in the kmalloc() call when allocating memory
355355
*
356-
* Returns name of attached handler, NULL if no handler is attached.
356+
* Returns name of attached handler, NULL if no handler is attached, or
357+
* and error pointer if an error occurred.
357358
* Caller must take care to free the returned string.
358359
*/
359360
const char *scsi_dh_attached_handler_name(struct request_queue *q, gfp_t gfp)
@@ -363,10 +364,11 @@ const char *scsi_dh_attached_handler_name(struct request_queue *q, gfp_t gfp)
363364

364365
sdev = scsi_device_from_queue(q);
365366
if (!sdev)
366-
return NULL;
367+
return ERR_PTR(-ENODEV);
367368

368369
if (sdev->handler)
369-
handler_name = kstrdup(sdev->handler->name, gfp);
370+
handler_name = kstrdup(sdev->handler->name, gfp) ? :
371+
ERR_PTR(-ENOMEM);
370372
put_device(&sdev->sdev_gendev);
371373
return handler_name;
372374
}

0 commit comments

Comments
 (0)