Skip to content

Commit 12b4c19

Browse files
PhilPotterkawasaki
authored andcommitted
cdrom: Call cdrom_mrw_exit from cdrom_release function
Remove the cdrom_mrw_exit call from unregister_cdrom, as it invokes block commands that can fail due to a NULL pointer dereference from the call happening too late, during the unloading of the driver (e.g. unplugging of USB optical drives). Instead perform the call inside cdrom_release, thus also removing the need for the exit function pointer inside the cdrom_device_info struct. Reported-by: Sergey Senozhatsky <[email protected]> Closes: https://lore.kernel.org/linux-block/uxgzea5ibqxygv3x7i4ojbpvcpv2wziorvb3ns5cdtyvobyn7h@y4g4l5ezv2ec Suggested-by: Jens Axboe <[email protected]> Link: https://lore.kernel.org/linux-block/[email protected] Tested-by: Phillip Potter <[email protected]> Signed-off-by: Phillip Potter <[email protected]>
1 parent 81f31a4 commit 12b4c19

3 files changed

Lines changed: 2 additions & 8 deletions

File tree

Documentation/cdrom/cdrom-standard.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,6 @@ The drive-specific, minor-like information that is registered with
273273
__u8 media_written; /* dirty flag, DVD+RW bookkeeping */
274274
unsigned short mmc3_profile; /* current MMC3 profile */
275275
int for_data; /* unknown:TBD */
276-
int (*exit)(struct cdrom_device_info *);/* unknown:TBD */
277276
int mrw_mode_page; /* which MRW mode page is in use */
278277
};
279278

drivers/cdrom/cdrom.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -624,9 +624,6 @@ int register_cdrom(struct gendisk *disk, struct cdrom_device_info *cdi)
624624
if (check_media_type == 1)
625625
cdi->options |= (int) CDO_CHECK_TYPE;
626626

627-
if (CDROM_CAN(CDC_MRW_W))
628-
cdi->exit = cdrom_mrw_exit;
629-
630627
if (cdi->ops->read_cdda_bpc)
631628
cdi->cdda_method = CDDA_BPC_FULL;
632629
else
@@ -651,9 +648,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
651648
list_del(&cdi->list);
652649
mutex_unlock(&cdrom_mutex);
653650

654-
if (cdi->exit)
655-
cdi->exit(cdi);
656-
657651
cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
658652
}
659653
EXPORT_SYMBOL(unregister_cdrom);
@@ -1264,6 +1258,8 @@ void cdrom_release(struct cdrom_device_info *cdi)
12641258
cd_dbg(CD_CLOSE, "Use count for \"/dev/%s\" now zero\n",
12651259
cdi->name);
12661260
cdrom_dvd_rw_close_write(cdi);
1261+
if (CDROM_CAN(CDC_MRW_W))
1262+
cdrom_mrw_exit(cdi);
12671263

12681264
if ((cdo->capability & CDC_LOCK) && !cdi->keeplocked) {
12691265
cd_dbg(CD_CLOSE, "Unlocking door!\n");

include/linux/cdrom.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ struct cdrom_device_info {
6262
__u8 last_sense;
6363
__u8 media_written; /* dirty flag, DVD+RW bookkeeping */
6464
unsigned short mmc3_profile; /* current MMC3 profile */
65-
int (*exit)(struct cdrom_device_info *);
6665
int mrw_mode_page;
6766
bool opened_for_data;
6867
__s64 last_media_change_ms;

0 commit comments

Comments
 (0)