]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commitdiff
cdrom: don't attempt to fiddle with cdo->capability
authorJens Axboe <axboe@kernel.dk>
Sun, 14 Oct 2018 19:20:48 +0000 (13:20 -0600)
committerJens Axboe <axboe@kernel.dk>
Sun, 14 Oct 2018 19:20:48 +0000 (13:20 -0600)
We can't modify cdo->capability as it is defined as a const.
Change the modification hack to just WARN_ON_ONCE() if we hit
any of the invalid combinations.

This fixes a regression for pcd, which doesn't work after the
constify patch.

Fixes: 853fe1bf7554 ("cdrom: Make device operations read-only")
Tested-by: Ondrej Zary <linux@rainbow-software.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/cdrom/cdrom.c

index 10802d1fc554c02a696371639a3869f22c06736c..614ecdbb4ab7a3d98cf2092c57fb3ce0a8826580 100644 (file)
@@ -410,10 +410,10 @@ static int cdrom_get_disc_info(struct cdrom_device_info *cdi,
  * hack to have the capability flags defined const, while we can still
  * change it here without gcc complaining at every line.
  */
-#define ENSURE(call, bits)                     \
-do {                                           \
-       if (cdo->call == NULL)                  \
-               *change_capability &= ~(bits);  \
+#define ENSURE(cdo, call, bits)                                        \
+do {                                                           \
+       if (cdo->call == NULL)                                  \
+               WARN_ON_ONCE((cdo)->capability & (bits));       \
 } while (0)
 
 /*
@@ -589,7 +589,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
 {
        static char banner_printed;
        const struct cdrom_device_ops *cdo = cdi->ops;
-       int *change_capability = (int *)&cdo->capability; /* hack */
 
        cd_dbg(CD_OPEN, "entering register_cdrom\n");
 
@@ -601,16 +600,16 @@ int register_cdrom(struct cdrom_device_info *cdi)
                cdrom_sysctl_register();
        }
 
-       ENSURE(drive_status, CDC_DRIVE_STATUS);
+       ENSURE(cdo, drive_status, CDC_DRIVE_STATUS);
        if (cdo->check_events == NULL && cdo->media_changed == NULL)
-               *change_capability = ~(CDC_MEDIA_CHANGED | CDC_SELECT_DISC);
-       ENSURE(tray_move, CDC_CLOSE_TRAY | CDC_OPEN_TRAY);
-       ENSURE(lock_door, CDC_LOCK);
-       ENSURE(select_speed, CDC_SELECT_SPEED);
-       ENSURE(get_last_session, CDC_MULTI_SESSION);
-       ENSURE(get_mcn, CDC_MCN);
-       ENSURE(reset, CDC_RESET);
-       ENSURE(generic_packet, CDC_GENERIC_PACKET);
+               WARN_ON_ONCE(cdo->capability & (CDC_MEDIA_CHANGED | CDC_SELECT_DISC));
+       ENSURE(cdo, tray_move, CDC_CLOSE_TRAY | CDC_OPEN_TRAY);
+       ENSURE(cdo, lock_door, CDC_LOCK);
+       ENSURE(cdo, select_speed, CDC_SELECT_SPEED);
+       ENSURE(cdo, get_last_session, CDC_MULTI_SESSION);
+       ENSURE(cdo, get_mcn, CDC_MCN);
+       ENSURE(cdo, reset, CDC_RESET);
+       ENSURE(cdo, generic_packet, CDC_GENERIC_PACKET);
        cdi->mc_flags = 0;
        cdi->options = CDO_USE_FFLAGS;