2014-11-10 20:22:11

by Fabian Frédérick

[permalink] [raw]
Subject: [PATCH v2 00/10 linux-next] cdrom: sysctl export + clean-up

This patchset moves sysctl functions to a new file cdrom_sysctl.c
and tries to solve small code / coding style issues.

V2:
-Use cdrom_ prefix for global variables
(suggested by Joe Perches)
-Add 2 patches

Fabian Frederick (10):
cdrom: include linux/uaccess.h instead of asm/uaccess.h
cdrom: use static const char * const where possible
cdrom: fix spaces required errors
cdrom: move EXPORT_SYMBOL after functions
cdrom: remove bool comparison/assignment to 0/1
cdrom: use bool for true/false initialized variable
cdrom: export sysctl code
cdrom: fix init_cdrom_command in dvd_do_auth
cdrom: remove unnecessary status
cdrom: uniformize lba command initialization

drivers/cdrom/Makefile | 1 +
drivers/cdrom/cdrom.c | 471 +++++++------------------------------------
drivers/cdrom/cdrom_sysctl.c | 297 +++++++++++++++++++++++++++
include/linux/cdrom.h | 33 +++
4 files changed, 401 insertions(+), 401 deletions(-)
create mode 100644 drivers/cdrom/cdrom_sysctl.c

--
1.9.1


2014-11-10 20:22:17

by Fabian Frédérick

[permalink] [raw]
Subject: [PATCH v2 02/10 linux-next] cdrom: use static const char * const where possible

Both mrw_format_status and mrw_address_space strings are
only read in pr_info.

Signed-off-by: Fabian Frederick <[email protected]>
---
drivers/cdrom/cdrom.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
index c7fa0e2..c311e0d 100644
--- a/drivers/cdrom/cdrom.c
+++ b/drivers/cdrom/cdrom.c
@@ -302,14 +302,14 @@ module_param(mrw_format_restart, bool, 0);

static DEFINE_MUTEX(cdrom_mutex);

-static const char *mrw_format_status[] = {
+static const char * const mrw_format_status[] = {
"not mrw",
"bgformat inactive",
"bgformat active",
"mrw complete",
};

-static const char *mrw_address_space[] = { "DMA", "GAA" };
+static const char * const mrw_address_space[] = { "DMA", "GAA" };

#if (ERRLOGMASK != CD_NOTHING)
#define cd_dbg(type, fmt, ...) \
--
1.9.1

2014-11-10 20:22:34

by Fabian Frédérick

[permalink] [raw]
Subject: [PATCH v2 01/10 linux-next] cdrom: include linux/uaccess.h instead of asm/uaccess.h

Signed-off-by: Fabian Frederick <[email protected]>
---
drivers/cdrom/cdrom.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
index 5d28a45..c7fa0e2 100644
--- a/drivers/cdrom/cdrom.c
+++ b/drivers/cdrom/cdrom.c
@@ -281,8 +281,7 @@
#include <linux/fcntl.h>
#include <linux/blkdev.h>
#include <linux/times.h>
-
-#include <asm/uaccess.h>
+#include <linux/uaccess.h>

/* used to tell the module to turn on full debugging messages */
static bool debug;
--
1.9.1

2014-11-10 20:23:09

by Fabian Frédérick

[permalink] [raw]
Subject: [PATCH v2 03/10 linux-next] cdrom: fix spaces required errors

Signed-off-by: Fabian Frederick <[email protected]>
---
drivers/cdrom/cdrom.c | 38 +++++++++++++++++++-------------------
1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
index c311e0d..deda0f1 100644
--- a/drivers/cdrom/cdrom.c
+++ b/drivers/cdrom/cdrom.c
@@ -286,7 +286,7 @@
/* used to tell the module to turn on full debugging messages */
static bool debug;
/* default compatibility mode */
-static bool autoclose=1;
+static bool autoclose = 1;
static bool autoeject;
static bool lockdoor = 1;
/* will we ever get to use this... sigh. */
@@ -535,7 +535,7 @@ static int cdrom_mrw_exit(struct cdrom_device_info *cdi)
int ret;

ret = cdrom_get_disc_info(cdi, &di);
- if (ret < 0 || ret < (int)offsetof(typeof(di),disc_type))
+ if (ret < 0 || ret < (int)offsetof(typeof(di), disc_type))
return 1;

ret = 0;
@@ -699,7 +699,7 @@ static int cdrom_get_random_writable(struct cdrom_device_info *cdi,
if ((ret = cdi->ops->generic_packet(cdi, &cgc)))
return ret;

- memcpy(rfd, &buffer[sizeof(struct feature_header)], sizeof (*rfd));
+ memcpy(rfd, &buffer[sizeof(struct feature_header)], sizeof(*rfd));
return 0;
}

@@ -787,7 +787,7 @@ static int cdrom_mrw_open_write(struct cdrom_device_info *cdi)
}

ret = cdrom_get_disc_info(cdi, &di);
- if (ret < 0 || ret < offsetof(typeof(di),disc_type))
+ if (ret < 0 || ret < offsetof(typeof(di), disc_type))
return 1;

if (!di.erasable)
@@ -1048,7 +1048,7 @@ int open_for_data(struct cdrom_device_info *cdi)
if (CDROM_CAN(CDC_CLOSE_TRAY) &&
cdi->options & CDO_AUTO_CLOSE) {
cd_dbg(CD_OPEN, "trying to close the tray\n");
- ret=cdo->tray_move(cdi,0);
+ ret = cdo->tray_move(cdi, 0);
if (ret) {
cd_dbg(CD_OPEN, "bummer. tried to close the tray but failed.\n");
/* Ignore the error from the low
@@ -1056,27 +1056,27 @@ int open_for_data(struct cdrom_device_info *cdi)
couldn't close the tray. We only care
that there is no disc in the drive,
since that is the _REAL_ problem here.*/
- ret=-ENOMEDIUM;
+ ret = -ENOMEDIUM;
goto clean_up_and_return;
}
} else {
cd_dbg(CD_OPEN, "bummer. this drive can't close the tray.\n");
- ret=-ENOMEDIUM;
+ ret = -ENOMEDIUM;
goto clean_up_and_return;
}
/* Ok, the door should be closed now.. Check again */
ret = cdo->drive_status(cdi, CDSL_CURRENT);
- if ((ret == CDS_NO_DISC) || (ret==CDS_TRAY_OPEN)) {
+ if ((ret == CDS_NO_DISC) || (ret == CDS_TRAY_OPEN)) {
cd_dbg(CD_OPEN, "bummer. the tray is still not closed.\n");
cd_dbg(CD_OPEN, "tray might not contain a medium\n");
- ret=-ENOMEDIUM;
+ ret = -ENOMEDIUM;
goto clean_up_and_return;
}
cd_dbg(CD_OPEN, "the tray is now closed\n");
}
/* the door should be closed now, check for the disc */
ret = cdo->drive_status(cdi, CDSL_CURRENT);
- if (ret!=CDS_DISC_OK) {
+ if (ret != CDS_DISC_OK) {
ret = -ENOMEDIUM;
goto clean_up_and_return;
}
@@ -1084,19 +1084,19 @@ int open_for_data(struct cdrom_device_info *cdi)
cdrom_count_tracks(cdi, &tracks);
if (tracks.error == CDS_NO_DISC) {
cd_dbg(CD_OPEN, "bummer. no disc.\n");
- ret=-ENOMEDIUM;
+ ret = -ENOMEDIUM;
goto clean_up_and_return;
}
/* CD-Players which don't use O_NONBLOCK, workman
* for example, need bit CDO_CHECK_TYPE cleared! */
- if (tracks.data==0) {
+ if (tracks.data == 0) {
if (cdi->options & CDO_CHECK_TYPE) {
/* give people a warning shot, now that CDO_CHECK_TYPE
is the default case! */
cd_dbg(CD_OPEN, "bummer. wrong media type.\n");
cd_dbg(CD_WARNING, "pid %d must open device O_NONBLOCK!\n",
(unsigned int)task_pid_nr(current));
- ret=-EMEDIUMTYPE;
+ ret = -EMEDIUMTYPE;
goto clean_up_and_return;
}
else {
@@ -1213,7 +1213,7 @@ static int check_for_audio_disc(struct cdrom_device_info * cdi,
if (CDROM_CAN(CDC_CLOSE_TRAY) &&
cdi->options & CDO_AUTO_CLOSE) {
cd_dbg(CD_OPEN, "trying to close the tray\n");
- ret=cdo->tray_move(cdi,0);
+ ret = cdo->tray_move(cdi, 0);
if (ret) {
cd_dbg(CD_OPEN, "bummer. tried to close tray but failed.\n");
/* Ignore the error from the low
@@ -1229,11 +1229,11 @@ static int check_for_audio_disc(struct cdrom_device_info * cdi,
}
/* Ok, the door should be closed now.. Check again */
ret = cdo->drive_status(cdi, CDSL_CURRENT);
- if ((ret == CDS_NO_DISC) || (ret==CDS_TRAY_OPEN)) {
+ if ((ret == CDS_NO_DISC) || (ret == CDS_TRAY_OPEN)) {
cd_dbg(CD_OPEN, "bummer. the tray is still not closed.\n");
return -ENOMEDIUM;
}
- if (ret!=CDS_DISC_OK) {
+ if (ret != CDS_DISC_OK) {
cd_dbg(CD_OPEN, "bummer. disc isn't ready.\n");
return -EIO;
}
@@ -1244,7 +1244,7 @@ static int check_for_audio_disc(struct cdrom_device_info * cdi,
if (tracks.error)
return(tracks.error);

- if (tracks.audio==0)
+ if (tracks.audio == 0)
return -EMEDIUMTYPE;

return 0;
@@ -1589,8 +1589,8 @@ void init_cdrom_command(struct packet_command *cgc, void *buf, int len,

/* DVD handling */

-#define copy_key(dest,src) memcpy((dest), (src), sizeof(dvd_key))
-#define copy_chal(dest,src) memcpy((dest), (src), sizeof(dvd_challenge))
+#define copy_key(dest, src) memcpy((dest), (src), sizeof(dvd_key))
+#define copy_chal(dest, src) memcpy((dest), (src), sizeof(dvd_challenge))

static void setup_report_key(struct packet_command *cgc, unsigned agid, unsigned type)
{
--
1.9.1

2014-11-10 20:23:12

by Fabian Frédérick

[permalink] [raw]
Subject: [PATCH v2 07/10 linux-next] cdrom: export sysctl code

-Move all sysctl operations to cdrom_sysctl
-Remove static/add extern in cdrom.h for some variables
-Prefix those variables with cdrom_ (suggested by Joe Perches)
-Fix some checkpatch warnings
-Update cdrom makefile accordingly.

Signed-off-by: Fabian Frederick <[email protected]>
---
drivers/cdrom/Makefile | 1 +
drivers/cdrom/cdrom.c | 367 +++----------------------------------------
drivers/cdrom/cdrom_sysctl.c | 297 ++++++++++++++++++++++++++++++++++
include/linux/cdrom.h | 33 ++++
4 files changed, 354 insertions(+), 344 deletions(-)
create mode 100644 drivers/cdrom/cdrom_sysctl.c

diff --git a/drivers/cdrom/Makefile b/drivers/cdrom/Makefile
index 8ffde4f..53609b0 100644
--- a/drivers/cdrom/Makefile
+++ b/drivers/cdrom/Makefile
@@ -9,5 +9,6 @@ obj-$(CONFIG_BLK_DEV_IDECD) += cdrom.o
obj-$(CONFIG_BLK_DEV_SR) += cdrom.o
obj-$(CONFIG_PARIDE_PCD) += cdrom.o
obj-$(CONFIG_CDROM_PKTCDVD) += cdrom.o
+obj-$(CONFIG_SYSCTL) += cdrom_sysctl.o

obj-$(CONFIG_GDROM) += gdrom.o cdrom.o
diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
index a1a26d5..9b08f91 100644
--- a/drivers/cdrom/cdrom.c
+++ b/drivers/cdrom/cdrom.c
@@ -242,11 +242,6 @@

-------------------------------------------------------------------------*/

-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
-#define REVISION "Revision: 3.20"
-#define VERSION "Id: cdrom.c 3.20 2003/12/17"
-
/* I use an error-log mask to give fine grain control over the type of
messages dumped to the system logs. The available masks include: */
#define CD_NOTHING 0x0
@@ -274,7 +269,6 @@
#include <linux/mm.h>
#include <linux/slab.h>
#include <linux/cdrom.h>
-#include <linux/sysctl.h>
#include <linux/proc_fs.h>
#include <linux/blkpg.h>
#include <linux/init.h>
@@ -284,23 +278,23 @@
#include <linux/uaccess.h>

/* used to tell the module to turn on full debugging messages */
-static bool debug;
+bool cdrom_debug = false;
/* default compatibility mode */
-static bool autoclose = true;
-static bool autoeject;
-static bool lockdoor = true;
+bool cdrom_autoclose = true;
+bool cdrom_autoeject = false;
+bool cdrom_lockdoor = true;
/* will we ever get to use this... sigh. */
-static bool check_media_type;
+bool cdrom_check_media_type = false;
/* automatically restart mrw format */
-static bool mrw_format_restart = true;
-module_param(debug, bool, 0);
-module_param(autoclose, bool, 0);
-module_param(autoeject, bool, 0);
-module_param(lockdoor, bool, 0);
-module_param(check_media_type, bool, 0);
-module_param(mrw_format_restart, bool, 0);
+bool cdrom_mrw_format_restart = true;
+module_param(cdrom_debug, bool, 0);
+module_param(cdrom_autoclose, bool, 0);
+module_param(cdrom_autoeject, bool, 0);
+module_param(cdrom_lockdoor, bool, 0);
+module_param(cdrom_check_media_type, bool, 0);
+module_param(cdrom_mrw_format_restart, bool, 0);

-static DEFINE_MUTEX(cdrom_mutex);
+DEFINE_MUTEX(cdrom_mutex);

static const char * const mrw_format_status[] = {
"not mrw",
@@ -314,32 +308,24 @@ static const char * const mrw_address_space[] = { "DMA", "GAA" };
#if (ERRLOGMASK != CD_NOTHING)
#define cd_dbg(type, fmt, ...) \
do { \
- if ((ERRLOGMASK & type) || debug) \
+ if ((ERRLOGMASK & type) || cdrom_debug) \
pr_debug(fmt, ##__VA_ARGS__); \
} while (0)
#else
#define cd_dbg(type, fmt, ...) \
do { \
- if (0 && (ERRLOGMASK & type) || debug) \
+ if (0 && (ERRLOGMASK & type) || cdrom_debug) \
pr_debug(fmt, ##__VA_ARGS__); \
} while (0)
#endif

-/* The (cdo->capability & ~cdi->mask & CDC_XXX) construct was used in
- a lot of places. This macro makes the code more clear. */
-#define CDROM_CAN(type) (cdi->ops->capability & ~cdi->mask & (type))
-
/*
* Another popular OS uses 7 seconds as the hard timeout for default
* commands, so it is a good choice for us as well.
*/
#define CDROM_DEF_TIMEOUT (7 * HZ)

-/* Not-exported routines. */
-
-static void cdrom_sysctl_register(void);
-
-static LIST_HEAD(cdrom_list);
+LIST_HEAD(cdrom_list);

static int cdrom_dummy_generic_packet(struct cdrom_device_info *cdi,
struct packet_command *cgc)
@@ -612,13 +598,13 @@ int register_cdrom(struct cdrom_device_info *cdi)
cdo->n_minors = 0;
cdi->options = CDO_USE_FFLAGS;

- if (autoclose && CDROM_CAN(CDC_CLOSE_TRAY))
+ if (cdrom_autoclose && CDROM_CAN(CDC_CLOSE_TRAY))
cdi->options |= (int) CDO_AUTO_CLOSE;
- if (autoeject && CDROM_CAN(CDC_OPEN_TRAY))
+ if (cdrom_autoeject && CDROM_CAN(CDC_OPEN_TRAY))
cdi->options |= (int) CDO_AUTO_EJECT;
- if (lockdoor)
+ if (cdrom_lockdoor)
cdi->options |= (int) CDO_LOCK;
- if (check_media_type)
+ if (cdrom_check_media_type)
cdi->options |= (int) CDO_CHECK_TYPE;

if (CDROM_CAN(CDC_MRW_W))
@@ -809,7 +795,7 @@ static int cdrom_mrw_open_write(struct cdrom_device_info *cdi)
if (!di.mrw_status)
ret = 1;
else if (di.mrw_status == CDM_MRW_BGFORMAT_INACTIVE &&
- mrw_format_restart)
+ cdrom_mrw_format_restart)
ret = cdrom_mrw_bgformat(cdi, 1);

return ret;
@@ -2492,8 +2478,8 @@ static int cdrom_ioctl_debug(struct cdrom_device_info *cdi,

if (!capable(CAP_SYS_ADMIN))
return -EACCES;
- debug = arg ? 1 : 0;
- return debug;
+ cdrom_debug = arg ? 1 : 0;
+ return cdrom_debug;
}

static int cdrom_ioctl_get_capability(struct cdrom_device_info *cdi)
@@ -3406,313 +3392,6 @@ int cdrom_ioctl(struct cdrom_device_info *cdi, struct block_device *bdev,
}
EXPORT_SYMBOL(cdrom_ioctl);

-#ifdef CONFIG_SYSCTL
-
-#define CDROM_STR_SIZE 1000
-
-static struct cdrom_sysctl_settings {
- char info[CDROM_STR_SIZE]; /* general info */
- int autoclose; /* close tray upon mount, etc */
- int autoeject; /* eject on umount */
- int debug; /* turn on debugging messages */
- int lock; /* lock the door on device open */
- int check; /* check media type */
-} cdrom_sysctl_settings;
-
-enum cdrom_print_option {
- CTL_NAME,
- CTL_SPEED,
- CTL_SLOTS,
- CTL_CAPABILITY
-};
-
-static int cdrom_print_info(const char *header, int val, char *info,
- int *pos, enum cdrom_print_option option)
-{
- const int max_size = sizeof(cdrom_sysctl_settings.info);
- struct cdrom_device_info *cdi;
- int ret;
-
- ret = scnprintf(info + *pos, max_size - *pos, header);
- if (!ret)
- return 1;
-
- *pos += ret;
-
- list_for_each_entry(cdi, &cdrom_list, list) {
- switch (option) {
- case CTL_NAME:
- ret = scnprintf(info + *pos, max_size - *pos,
- "\t%s", cdi->name);
- break;
- case CTL_SPEED:
- ret = scnprintf(info + *pos, max_size - *pos,
- "\t%d", cdi->speed);
- break;
- case CTL_SLOTS:
- ret = scnprintf(info + *pos, max_size - *pos,
- "\t%d", cdi->capacity);
- break;
- case CTL_CAPABILITY:
- ret = scnprintf(info + *pos, max_size - *pos,
- "\t%d", CDROM_CAN(val) != 0);
- break;
- default:
- pr_info("invalid option%d\n", option);
- return 1;
- }
- if (!ret)
- return 1;
- *pos += ret;
- }
-
- return 0;
-}
-
-static int cdrom_sysctl_info(struct ctl_table *ctl, int write,
- void __user *buffer, size_t *lenp, loff_t *ppos)
-{
- int pos;
- char *info = cdrom_sysctl_settings.info;
- const int max_size = sizeof(cdrom_sysctl_settings.info);
-
- if (!*lenp || (*ppos && !write)) {
- *lenp = 0;
- return 0;
- }
-
- mutex_lock(&cdrom_mutex);
-
- pos = sprintf(info, "CD-ROM information, " VERSION "\n");
-
- if (cdrom_print_info("\ndrive name:\t", 0, info, &pos, CTL_NAME))
- goto done;
- if (cdrom_print_info("\ndrive speed:\t", 0, info, &pos, CTL_SPEED))
- goto done;
- if (cdrom_print_info("\ndrive # of slots:", 0, info, &pos, CTL_SLOTS))
- goto done;
- if (cdrom_print_info("\nCan close tray:\t",
- CDC_CLOSE_TRAY, info, &pos, CTL_CAPABILITY))
- goto done;
- if (cdrom_print_info("\nCan open tray:\t",
- CDC_OPEN_TRAY, info, &pos, CTL_CAPABILITY))
- goto done;
- if (cdrom_print_info("\nCan lock tray:\t",
- CDC_LOCK, info, &pos, CTL_CAPABILITY))
- goto done;
- if (cdrom_print_info("\nCan change speed:",
- CDC_SELECT_SPEED, info, &pos, CTL_CAPABILITY))
- goto done;
- if (cdrom_print_info("\nCan select disk:",
- CDC_SELECT_DISC, info, &pos, CTL_CAPABILITY))
- goto done;
- if (cdrom_print_info("\nCan read multisession:",
- CDC_MULTI_SESSION, info, &pos, CTL_CAPABILITY))
- goto done;
- if (cdrom_print_info("\nCan read MCN:\t",
- CDC_MCN, info, &pos, CTL_CAPABILITY))
- goto done;
- if (cdrom_print_info("\nReports media changed:",
- CDC_MEDIA_CHANGED, info, &pos, CTL_CAPABILITY))
- goto done;
- if (cdrom_print_info("\nCan play audio:\t",
- CDC_PLAY_AUDIO, info, &pos, CTL_CAPABILITY))
- goto done;
- if (cdrom_print_info("\nCan write CD-R:\t",
- CDC_CD_R, info, &pos, CTL_CAPABILITY))
- goto done;
- if (cdrom_print_info("\nCan write CD-RW:",
- CDC_CD_RW, info, &pos, CTL_CAPABILITY))
- goto done;
- if (cdrom_print_info("\nCan read DVD:\t",
- CDC_DVD, info, &pos, CTL_CAPABILITY))
- goto done;
- if (cdrom_print_info("\nCan write DVD-R:",
- CDC_DVD_R, info, &pos, CTL_CAPABILITY))
- goto done;
- if (cdrom_print_info("\nCan write DVD-RAM:",
- CDC_DVD_RAM, info, &pos, CTL_CAPABILITY))
- goto done;
- if (cdrom_print_info("\nCan read MRW:\t",
- CDC_MRW, info, &pos, CTL_CAPABILITY))
- goto done;
- if (cdrom_print_info("\nCan write MRW:\t",
- CDC_MRW_W, info, &pos, CTL_CAPABILITY))
- goto done;
- if (cdrom_print_info("\nCan write RAM:\t",
- CDC_RAM, info, &pos, CTL_CAPABILITY))
- goto done;
- if (!scnprintf(info + pos, max_size - pos, "\n\n"))
- goto done;
-doit:
- mutex_unlock(&cdrom_mutex);
- return proc_dostring(ctl, write, buffer, lenp, ppos);
-done:
- pr_info("info buffer too small\n");
- goto doit;
-}
-
-/* Unfortunately, per device settings are not implemented through
- procfs/sysctl yet. When they are, this will naturally disappear. For now
- just update all drives. Later this will become the template on which
- new registered drives will be based. */
-static void cdrom_update_settings(void)
-{
- struct cdrom_device_info *cdi;
-
- mutex_lock(&cdrom_mutex);
- list_for_each_entry(cdi, &cdrom_list, list) {
- if (autoclose && CDROM_CAN(CDC_CLOSE_TRAY))
- cdi->options |= CDO_AUTO_CLOSE;
- else if (!autoclose)
- cdi->options &= ~CDO_AUTO_CLOSE;
- if (autoeject && CDROM_CAN(CDC_OPEN_TRAY))
- cdi->options |= CDO_AUTO_EJECT;
- else if (!autoeject)
- cdi->options &= ~CDO_AUTO_EJECT;
- if (lockdoor && CDROM_CAN(CDC_LOCK))
- cdi->options |= CDO_LOCK;
- else if (!lockdoor)
- cdi->options &= ~CDO_LOCK;
- if (check_media_type)
- cdi->options |= CDO_CHECK_TYPE;
- else
- cdi->options &= ~CDO_CHECK_TYPE;
- }
- mutex_unlock(&cdrom_mutex);
-}
-
-static int cdrom_sysctl_handler(struct ctl_table *ctl, int write,
- void __user *buffer, size_t *lenp, loff_t *ppos)
-{
- int ret;
-
- ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
-
- if (write) {
-
- /* we only care for 1 or 0. */
- autoclose = !!cdrom_sysctl_settings.autoclose;
- autoeject = !!cdrom_sysctl_settings.autoeject;
- debug = !!cdrom_sysctl_settings.debug;
- lockdoor = !!cdrom_sysctl_settings.lock;
- check_media_type = !!cdrom_sysctl_settings.check;
-
- /* update the option flags according to the changes. we
- don't have per device options through sysctl yet,
- but we will have and then this will disappear. */
- cdrom_update_settings();
- }
-
- return ret;
-}
-
-/* Place files in /proc/sys/dev/cdrom */
-static struct ctl_table cdrom_table[] = {
- {
- .procname = "info",
- .data = &cdrom_sysctl_settings.info,
- .maxlen = CDROM_STR_SIZE,
- .mode = 0444,
- .proc_handler = cdrom_sysctl_info,
- },
- {
- .procname = "autoclose",
- .data = &cdrom_sysctl_settings.autoclose,
- .maxlen = sizeof(int),
- .mode = 0644,
- .proc_handler = cdrom_sysctl_handler,
- },
- {
- .procname = "autoeject",
- .data = &cdrom_sysctl_settings.autoeject,
- .maxlen = sizeof(int),
- .mode = 0644,
- .proc_handler = cdrom_sysctl_handler,
- },
- {
- .procname = "debug",
- .data = &cdrom_sysctl_settings.debug,
- .maxlen = sizeof(int),
- .mode = 0644,
- .proc_handler = cdrom_sysctl_handler,
- },
- {
- .procname = "lock",
- .data = &cdrom_sysctl_settings.lock,
- .maxlen = sizeof(int),
- .mode = 0644,
- .proc_handler = cdrom_sysctl_handler,
- },
- {
- .procname = "check_media",
- .data = &cdrom_sysctl_settings.check,
- .maxlen = sizeof(int),
- .mode = 0644,
- .proc_handler = cdrom_sysctl_handler
- },
- { }
-};
-
-static struct ctl_table cdrom_cdrom_table[] = {
- {
- .procname = "cdrom",
- .maxlen = 0,
- .mode = 0555,
- .child = cdrom_table,
- },
- { }
-};
-
-/* Make sure that /proc/sys/dev is there */
-static struct ctl_table cdrom_root_table[] = {
- {
- .procname = "dev",
- .maxlen = 0,
- .mode = 0555,
- .child = cdrom_cdrom_table,
- },
- { }
-};
-static struct ctl_table_header *cdrom_sysctl_header;
-
-static void cdrom_sysctl_register(void)
-{
- static bool initialized;
-
- if (initialized)
- return;
-
- cdrom_sysctl_header = register_sysctl_table(cdrom_root_table);
-
- /* set the defaults */
- cdrom_sysctl_settings.autoclose = autoclose;
- cdrom_sysctl_settings.autoeject = autoeject;
- cdrom_sysctl_settings.debug = debug;
- cdrom_sysctl_settings.lock = lockdoor;
- cdrom_sysctl_settings.check = check_media_type;
-
- initialized = true;
-}
-
-static void cdrom_sysctl_unregister(void)
-{
- if (cdrom_sysctl_header)
- unregister_sysctl_table(cdrom_sysctl_header);
-}
-
-#else /* CONFIG_SYSCTL */
-
-static void cdrom_sysctl_register(void)
-{
-}
-
-static void cdrom_sysctl_unregister(void)
-{
-}
-
-#endif /* CONFIG_SYSCTL */
-
static int __init cdrom_init(void)
{
cdrom_sysctl_register();
diff --git a/drivers/cdrom/cdrom_sysctl.c b/drivers/cdrom/cdrom_sysctl.c
new file mode 100644
index 0000000..3035db3
--- /dev/null
+++ b/drivers/cdrom/cdrom_sysctl.c
@@ -0,0 +1,297 @@
+#include <linux/kernel.h>
+#include <linux/mm.h>
+#include <linux/cdrom.h>
+#include <linux/sysctl.h>
+
+#define CDROM_STR_SIZE 1000
+
+static struct cdrom_sysctl_settings {
+ char info[CDROM_STR_SIZE]; /* general info */
+ int autoclose; /* close tray upon mount, etc */
+ int autoeject; /* eject on umount */
+ int debug; /* turn on debugging messages */
+ int lock; /* lock the door on device open */
+ int check; /* check media type */
+} cdrom_sysctl_settings;
+
+enum cdrom_print_option {
+ CTL_NAME,
+ CTL_SPEED,
+ CTL_SLOTS,
+ CTL_CAPABILITY
+};
+
+static int cdrom_print_info(const char *header, int val, char *info,
+ int *pos, enum cdrom_print_option option)
+{
+ const int max_size = sizeof(cdrom_sysctl_settings.info);
+ struct cdrom_device_info *cdi;
+ int ret;
+
+ ret = scnprintf(info + *pos, max_size - *pos, header);
+ if (!ret)
+ return 1;
+
+ *pos += ret;
+
+ list_for_each_entry(cdi, &cdrom_list, list) {
+ switch (option) {
+ case CTL_NAME:
+ ret = scnprintf(info + *pos, max_size - *pos,
+ "\t%s", cdi->name);
+ break;
+ case CTL_SPEED:
+ ret = scnprintf(info + *pos, max_size - *pos,
+ "\t%d", cdi->speed);
+ break;
+ case CTL_SLOTS:
+ ret = scnprintf(info + *pos, max_size - *pos,
+ "\t%d", cdi->capacity);
+ break;
+ case CTL_CAPABILITY:
+ ret = scnprintf(info + *pos, max_size - *pos,
+ "\t%d", CDROM_CAN(val) != 0);
+ break;
+ default:
+ pr_info("invalid option%d\n", option);
+ return 1;
+ }
+ if (!ret)
+ return 1;
+ *pos += ret;
+ }
+
+ return 0;
+}
+
+static int cdrom_sysctl_info(struct ctl_table *ctl, int write,
+ void __user *buffer, size_t *lenp, loff_t *ppos)
+{
+ int pos;
+ char *info = cdrom_sysctl_settings.info;
+ const int max_size = sizeof(cdrom_sysctl_settings.info);
+
+ if (!*lenp || (*ppos && !write)) {
+ *lenp = 0;
+ return 0;
+ }
+
+ mutex_lock(&cdrom_mutex);
+
+ pos = sprintf(info, "CD-ROM information, " VERSION "\n");
+
+ if (cdrom_print_info("\ndrive name:\t", 0, info, &pos, CTL_NAME))
+ goto done;
+ if (cdrom_print_info("\ndrive speed:\t", 0, info, &pos, CTL_SPEED))
+ goto done;
+ if (cdrom_print_info("\ndrive # of slots:", 0, info, &pos, CTL_SLOTS))
+ goto done;
+ if (cdrom_print_info("\nCan close tray:\t",
+ CDC_CLOSE_TRAY, info, &pos, CTL_CAPABILITY))
+ goto done;
+ if (cdrom_print_info("\nCan open tray:\t",
+ CDC_OPEN_TRAY, info, &pos, CTL_CAPABILITY))
+ goto done;
+ if (cdrom_print_info("\nCan lock tray:\t",
+ CDC_LOCK, info, &pos, CTL_CAPABILITY))
+ goto done;
+ if (cdrom_print_info("\nCan change speed:",
+ CDC_SELECT_SPEED, info, &pos, CTL_CAPABILITY))
+ goto done;
+ if (cdrom_print_info("\nCan select disk:",
+ CDC_SELECT_DISC, info, &pos, CTL_CAPABILITY))
+ goto done;
+ if (cdrom_print_info("\nCan read multisession:",
+ CDC_MULTI_SESSION, info, &pos, CTL_CAPABILITY))
+ goto done;
+ if (cdrom_print_info("\nCan read MCN:\t",
+ CDC_MCN, info, &pos, CTL_CAPABILITY))
+ goto done;
+ if (cdrom_print_info("\nReports media changed:",
+ CDC_MEDIA_CHANGED, info, &pos, CTL_CAPABILITY))
+ goto done;
+ if (cdrom_print_info("\nCan play audio:\t",
+ CDC_PLAY_AUDIO, info, &pos, CTL_CAPABILITY))
+ goto done;
+ if (cdrom_print_info("\nCan write CD-R:\t",
+ CDC_CD_R, info, &pos, CTL_CAPABILITY))
+ goto done;
+ if (cdrom_print_info("\nCan write CD-RW:",
+ CDC_CD_RW, info, &pos, CTL_CAPABILITY))
+ goto done;
+ if (cdrom_print_info("\nCan read DVD:\t",
+ CDC_DVD, info, &pos, CTL_CAPABILITY))
+ goto done;
+ if (cdrom_print_info("\nCan write DVD-R:",
+ CDC_DVD_R, info, &pos, CTL_CAPABILITY))
+ goto done;
+ if (cdrom_print_info("\nCan write DVD-RAM:",
+ CDC_DVD_RAM, info, &pos, CTL_CAPABILITY))
+ goto done;
+ if (cdrom_print_info("\nCan read MRW:\t",
+ CDC_MRW, info, &pos, CTL_CAPABILITY))
+ goto done;
+ if (cdrom_print_info("\nCan write MRW:\t",
+ CDC_MRW_W, info, &pos, CTL_CAPABILITY))
+ goto done;
+ if (cdrom_print_info("\nCan write RAM:\t",
+ CDC_RAM, info, &pos, CTL_CAPABILITY))
+ goto done;
+ if (!scnprintf(info + pos, max_size - pos, "\n\n"))
+ goto done;
+doit:
+ mutex_unlock(&cdrom_mutex);
+ return proc_dostring(ctl, write, buffer, lenp, ppos);
+done:
+ pr_info("info buffer too small\n");
+ goto doit;
+}
+
+/* Unfortunately, per device settings are not implemented through
+ procfs/sysctl yet. When they are, this will naturally disappear. For now
+ just update all drives. Later this will become the template on which
+ new registered drives will be based. */
+static void cdrom_update_settings(void)
+{
+ struct cdrom_device_info *cdi;
+
+ mutex_lock(&cdrom_mutex);
+ list_for_each_entry(cdi, &cdrom_list, list) {
+ if (cdrom_autoclose && CDROM_CAN(CDC_CLOSE_TRAY))
+ cdi->options |= CDO_AUTO_CLOSE;
+ else if (!cdrom_autoclose)
+ cdi->options &= ~CDO_AUTO_CLOSE;
+ if (cdrom_autoeject && CDROM_CAN(CDC_OPEN_TRAY))
+ cdi->options |= CDO_AUTO_EJECT;
+ else if (!cdrom_autoeject)
+ cdi->options &= ~CDO_AUTO_EJECT;
+ if (cdrom_lockdoor && CDROM_CAN(CDC_LOCK))
+ cdi->options |= CDO_LOCK;
+ else if (!cdrom_lockdoor)
+ cdi->options &= ~CDO_LOCK;
+ if (cdrom_check_media_type)
+ cdi->options |= CDO_CHECK_TYPE;
+ else
+ cdi->options &= ~CDO_CHECK_TYPE;
+ }
+ mutex_unlock(&cdrom_mutex);
+}
+
+static int cdrom_sysctl_handler(struct ctl_table *ctl, int write,
+ void __user *buffer, size_t *lenp, loff_t *ppos)
+{
+ int ret;
+
+ ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
+
+ if (write) {
+
+ /* we only care for 1 or 0. */
+ cdrom_autoclose = !!cdrom_sysctl_settings.autoclose;
+ cdrom_autoeject = !!cdrom_sysctl_settings.autoeject;
+ cdrom_debug = !!cdrom_sysctl_settings.debug;
+ cdrom_lockdoor = !!cdrom_sysctl_settings.lock;
+ cdrom_check_media_type = !!cdrom_sysctl_settings.check;
+
+ /* update the option flags according to the changes. we
+ don't have per device options through sysctl yet,
+ but we will have and then this will disappear. */
+ cdrom_update_settings();
+ }
+
+ return ret;
+}
+
+/* Place files in /proc/sys/dev/cdrom */
+static struct ctl_table cdrom_table[] = {
+ {
+ .procname = "info",
+ .data = &cdrom_sysctl_settings.info,
+ .maxlen = CDROM_STR_SIZE,
+ .mode = 0444,
+ .proc_handler = cdrom_sysctl_info,
+ },
+ {
+ .procname = "autoclose",
+ .data = &cdrom_sysctl_settings.autoclose,
+ .maxlen = sizeof(int),
+ .mode = 0644,
+ .proc_handler = cdrom_sysctl_handler,
+ },
+ {
+ .procname = "autoeject",
+ .data = &cdrom_sysctl_settings.autoeject,
+ .maxlen = sizeof(int),
+ .mode = 0644,
+ .proc_handler = cdrom_sysctl_handler,
+ },
+ {
+ .procname = "debug",
+ .data = &cdrom_sysctl_settings.debug,
+ .maxlen = sizeof(int),
+ .mode = 0644,
+ .proc_handler = cdrom_sysctl_handler,
+ },
+ {
+ .procname = "lock",
+ .data = &cdrom_sysctl_settings.lock,
+ .maxlen = sizeof(int),
+ .mode = 0644,
+ .proc_handler = cdrom_sysctl_handler,
+ },
+ {
+ .procname = "check_media",
+ .data = &cdrom_sysctl_settings.check,
+ .maxlen = sizeof(int),
+ .mode = 0644,
+ .proc_handler = cdrom_sysctl_handler
+ },
+ { }
+};
+
+static struct ctl_table cdrom_cdrom_table[] = {
+ {
+ .procname = "cdrom",
+ .maxlen = 0,
+ .mode = 0555,
+ .child = cdrom_table,
+ },
+ { }
+};
+
+/* Make sure that /proc/sys/dev is there */
+static struct ctl_table cdrom_root_table[] = {
+ {
+ .procname = "dev",
+ .maxlen = 0,
+ .mode = 0555,
+ .child = cdrom_cdrom_table,
+ },
+ { }
+};
+static struct ctl_table_header *cdrom_sysctl_header;
+
+void cdrom_sysctl_register(void)
+{
+ static bool initialized;
+
+ if (initialized)
+ return;
+
+ cdrom_sysctl_header = register_sysctl_table(cdrom_root_table);
+
+ /* set the defaults */
+ cdrom_sysctl_settings.autoclose = cdrom_autoclose;
+ cdrom_sysctl_settings.autoeject = cdrom_autoeject;
+ cdrom_sysctl_settings.debug = cdrom_debug;
+ cdrom_sysctl_settings.lock = cdrom_lockdoor;
+ cdrom_sysctl_settings.check = cdrom_check_media_type;
+
+ initialized = true;
+}
+
+void cdrom_sysctl_unregister(void)
+{
+ if (cdrom_sysctl_header)
+ unregister_sysctl_table(cdrom_sysctl_header);
+}
diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
index 8609d57..2c9d6fb 100644
--- a/include/linux/cdrom.h
+++ b/include/linux/cdrom.h
@@ -10,10 +10,23 @@
#ifndef _LINUX_CDROM_H
#define _LINUX_CDROM_H

+#ifdef pr_fmt
+#undef pr_fmt
+#endif
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#define REVISION "Revision: 3.20"
+#define VERSION "Id: cdrom.c 3.20 2003/12/17"
+
#include <linux/fs.h> /* not really needed, later.. */
#include <linux/list.h>
#include <uapi/linux/cdrom.h>

+/* The (cdo->capability & ~cdi->mask & CDC_XXX) construct was used in
+ a lot of places. This macro makes the code more clear. */
+#define CDROM_CAN(type) (cdi->ops->capability & ~cdi->mask & (type))
+
struct packet_command
{
unsigned char cmd[CDROM_PACKET_SIZE];
@@ -311,4 +324,24 @@ static inline int msf_to_lba(u8 m, u8 s, u8 f)
{
return (((m * CD_SECS) + s) * CD_FRAMES + f) - CD_MSF_OFFSET;
}
+
+/* cdrom.c */
+extern bool cdrom_debug;
+extern bool cdrom_autoclose;
+extern bool cdrom_autoeject;
+extern bool cdrom_lockdoor;
+extern bool cdrom_check_media_type;
+extern bool cdrom_mrw_format_restart;
+extern struct list_head cdrom_list;
+extern struct mutex cdrom_mutex;
+
+/* cdrom_sysctl.c */
+#ifdef CONFIG_SYSCTL
+extern void cdrom_sysctl_register(void);
+extern void cdrom_sysctl_unregister(void);
+#else
+#define cdrom_sysctl_register do { } while (0)
+#define cdrom_sysctl_unregister do { } while (0)
+#endif /* CONFIG_SYSCTL */
+
#endif /* _LINUX_CDROM_H */
--
1.9.1

2014-11-10 20:23:26

by Fabian Frédérick

[permalink] [raw]
Subject: [PATCH v2 09/10 linux-next] cdrom: remove unnecessary status

cdrom_number_of_slots returns nslots and doesn't need status
variable. Just remove it and test cdrom_read_mech_status().

Signed-off-by: Fabian Frederick <[email protected]>
---
drivers/cdrom/cdrom.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
index d397591..9a6fa8f 100644
--- a/drivers/cdrom/cdrom.c
+++ b/drivers/cdrom/cdrom.c
@@ -1343,7 +1343,6 @@ out_free:
*/
int cdrom_number_of_slots(struct cdrom_device_info *cdi)
{
- int status;
int nslots = 1;
struct cdrom_changer_info *info;

@@ -1355,7 +1354,7 @@ int cdrom_number_of_slots(struct cdrom_device_info *cdi)
if (!info)
return -ENOMEM;

- if ((status = cdrom_read_mech_status(cdi, info)) == 0)
+ if (!cdrom_read_mech_status(cdi, info))
nslots = info->hdr.nslots;

kfree(info);
--
1.9.1

2014-11-10 20:23:41

by Fabian Frédérick

[permalink] [raw]
Subject: [PATCH v2 08/10 linux-next] cdrom: fix init_cdrom_command in dvd_do_auth

Remove memset 0 (init_cdrom_command already does it)
and send sizeof(buf) instead of 0 for buffer size.

Signed-off-by: Fabian Frederick <[email protected]>
---
drivers/cdrom/cdrom.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
index 9b08f91..d397591 100644
--- a/drivers/cdrom/cdrom.c
+++ b/drivers/cdrom/cdrom.c
@@ -1639,8 +1639,7 @@ static int dvd_do_auth(struct cdrom_device_info *cdi, dvd_authinfo *ai)
struct cdrom_device_ops *cdo = cdi->ops;
rpc_state_t rpc_state;

- memset(buf, 0, sizeof(buf));
- init_cdrom_command(&cgc, buf, 0, CGC_DATA_READ);
+ init_cdrom_command(&cgc, buf, sizeof(buf), CGC_DATA_READ);

switch (ai->type) {
/* LU data send */
--
1.9.1

2014-11-10 20:23:55

by Fabian Frédérick

[permalink] [raw]
Subject: [PATCH v2 06/10 linux-next] cdrom: use bool for true/false initialized variable

Signed-off-by: Fabian Frederick <[email protected]>
---
drivers/cdrom/cdrom.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
index a4dd382..a1a26d5 100644
--- a/drivers/cdrom/cdrom.c
+++ b/drivers/cdrom/cdrom.c
@@ -3678,9 +3678,9 @@ static struct ctl_table_header *cdrom_sysctl_header;

static void cdrom_sysctl_register(void)
{
- static int initialized;
+ static bool initialized;

- if (initialized == 1)
+ if (initialized)
return;

cdrom_sysctl_header = register_sysctl_table(cdrom_root_table);
@@ -3692,7 +3692,7 @@ static void cdrom_sysctl_register(void)
cdrom_sysctl_settings.lock = lockdoor;
cdrom_sysctl_settings.check = check_media_type;

- initialized = 1;
+ initialized = true;
}

static void cdrom_sysctl_unregister(void)
--
1.9.1

2014-11-10 20:23:08

by Fabian Frédérick

[permalink] [raw]
Subject: [PATCH v2 04/10 linux-next] cdrom: move EXPORT_SYMBOL after functions

Signed-off-by: Fabian Frederick <[email protected]>
---
drivers/cdrom/cdrom.c | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
index deda0f1..ca47919 100644
--- a/drivers/cdrom/cdrom.c
+++ b/drivers/cdrom/cdrom.c
@@ -638,6 +638,8 @@ int register_cdrom(struct cdrom_device_info *cdi)
mutex_unlock(&cdrom_mutex);
return 0;
}
+EXPORT_SYMBOL(register_cdrom);
+
#undef ENSURE

void unregister_cdrom(struct cdrom_device_info *cdi)
@@ -654,6 +656,7 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
cdi->ops->n_minors--;
cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
}
+EXPORT_SYMBOL(unregister_cdrom);

int cdrom_get_media_event(struct cdrom_device_info *cdi,
struct media_event_desc *med)
@@ -681,6 +684,7 @@ int cdrom_get_media_event(struct cdrom_device_info *cdi,
memcpy(med, &buffer[sizeof(*eh)], sizeof(*med));
return 0;
}
+EXPORT_SYMBOL(cdrom_get_media_event);

static int cdrom_get_random_writable(struct cdrom_device_info *cdi,
struct rwrt_feature_desc *rfd)
@@ -1192,6 +1196,7 @@ err:
cdi->use_count--;
return ret;
}
+EXPORT_SYMBOL(cdrom_open);

/* This code is similar to that in open_for_data. The routine is called
whenever an audio play operation is requested.
@@ -1287,6 +1292,7 @@ void cdrom_release(struct cdrom_device_info *cdi, fmode_t mode)
cdo->tray_move(cdi, 1);
}
}
+EXPORT_SYMBOL(cdrom_release);

static int cdrom_read_mech_status(struct cdrom_device_info *cdi,
struct cdrom_changer_info *buf)
@@ -1369,6 +1375,7 @@ int cdrom_number_of_slots(struct cdrom_device_info *cdi)
kfree(info);
return nslots;
}
+EXPORT_SYMBOL(cdrom_number_of_slots);


/* If SLOT < 0, unload the current slot. Otherwise, try to load SLOT. */
@@ -1538,6 +1545,7 @@ int cdrom_media_changed(struct cdrom_device_info *cdi)
return 0;
return media_changed(cdi, 0);
}
+EXPORT_SYMBOL(cdrom_media_changed);

/* Requests to the low-level drivers will /always/ be done in the
following format convention:
@@ -1586,6 +1594,7 @@ void init_cdrom_command(struct packet_command *cgc, void *buf, int len,
cgc->data_direction = type;
cgc->timeout = CDROM_DEF_TIMEOUT;
}
+EXPORT_SYMBOL(init_cdrom_command);

/* DVD handling */

@@ -2004,6 +2013,7 @@ int cdrom_mode_sense(struct cdrom_device_info *cdi,
cgc->data_direction = CGC_DATA_READ;
return cdo->generic_packet(cdi, cgc);
}
+EXPORT_SYMBOL(cdrom_mode_sense);

int cdrom_mode_select(struct cdrom_device_info *cdi,
struct packet_command *cgc)
@@ -2019,6 +2029,7 @@ int cdrom_mode_select(struct cdrom_device_info *cdi,
cgc->data_direction = CGC_DATA_WRITE;
return cdo->generic_packet(cdi, cgc);
}
+EXPORT_SYMBOL(cdrom_mode_select);

static int cdrom_read_subchannel(struct cdrom_device_info *cdi,
struct cdrom_subchnl *subchnl, int mcn)
@@ -2871,6 +2882,7 @@ use_toc:
*last_written = toc.cdte_addr.lba;
return 0;
}
+EXPORT_SYMBOL(cdrom_get_last_written);

/* return the next writable block. also for udf file system. */
static int cdrom_get_next_writable(struct cdrom_device_info *cdi,
@@ -3392,19 +3404,7 @@ int cdrom_ioctl(struct cdrom_device_info *cdi, struct block_device *bdev,

return -ENOSYS;
}
-
-EXPORT_SYMBOL(cdrom_get_last_written);
-EXPORT_SYMBOL(register_cdrom);
-EXPORT_SYMBOL(unregister_cdrom);
-EXPORT_SYMBOL(cdrom_open);
-EXPORT_SYMBOL(cdrom_release);
EXPORT_SYMBOL(cdrom_ioctl);
-EXPORT_SYMBOL(cdrom_media_changed);
-EXPORT_SYMBOL(cdrom_number_of_slots);
-EXPORT_SYMBOL(cdrom_mode_select);
-EXPORT_SYMBOL(cdrom_mode_sense);
-EXPORT_SYMBOL(init_cdrom_command);
-EXPORT_SYMBOL(cdrom_get_media_event);

#ifdef CONFIG_SYSCTL

--
1.9.1

2014-11-10 20:24:29

by Fabian Frédérick

[permalink] [raw]
Subject: [PATCH v2 10/10 linux-next] cdrom: uniformize lba command initialization

logical block address field was initialized in different
functions directly in package cmd or bio cmd.

Note that cdrom_dummy_generic_packet didn't use & 0xff

Signed-off-by: Fabian Frederick <[email protected]>
---
drivers/cdrom/cdrom.c | 33 +++++++++++++--------------------
1 file changed, 13 insertions(+), 20 deletions(-)

diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
index 9a6fa8f..3922038 100644
--- a/drivers/cdrom/cdrom.c
+++ b/drivers/cdrom/cdrom.c
@@ -327,6 +327,14 @@ do { \

LIST_HEAD(cdrom_list);

+static void int_to_cmd_lba(int value, unsigned char *cmd)
+{
+ cmd[2] = (value >> 24) & 0xff;
+ cmd[3] = (value >> 16) & 0xff;
+ cmd[4] = (value >> 8) & 0xff;
+ cmd[5] = value & 0xff;
+}
+
static int cdrom_dummy_generic_packet(struct cdrom_device_info *cdi,
struct packet_command *cgc)
{
@@ -1681,10 +1689,7 @@ static int dvd_do_auth(struct cdrom_device_info *cdi, dvd_authinfo *ai)
cd_dbg(CD_DVD, "entering DVD_LU_SEND_TITLE_KEY\n");
cgc.quiet = 1;
setup_report_key(&cgc, ai->lstk.agid, 4);
- cgc.cmd[5] = ai->lstk.lba;
- cgc.cmd[4] = ai->lstk.lba >> 8;
- cgc.cmd[3] = ai->lstk.lba >> 16;
- cgc.cmd[2] = ai->lstk.lba >> 24;
+ int_to_cmd_lba(ai->lstk.lba, cgc.cmd);

if ((ret = cdo->generic_packet(cdi, &cgc)))
return ret;
@@ -2060,10 +2065,7 @@ static int cdrom_read_cd(struct cdrom_device_info *cdi,

memset(&cgc->cmd, 0, sizeof(cgc->cmd));
cgc->cmd[0] = GPCMD_READ_10;
- cgc->cmd[2] = (lba >> 24) & 0xff;
- cgc->cmd[3] = (lba >> 16) & 0xff;
- cgc->cmd[4] = (lba >> 8) & 0xff;
- cgc->cmd[5] = lba & 0xff;
+ int_to_cmd_lba(lba, cgc->cmd);
cgc->cmd[6] = (nblocks >> 16) & 0xff;
cgc->cmd[7] = (nblocks >> 8) & 0xff;
cgc->cmd[8] = nblocks & 0xff;
@@ -2083,10 +2085,7 @@ static int cdrom_read_block(struct cdrom_device_info *cdi,
/* expected sector size - cdda,mode1,etc. */
cgc->cmd[1] = format << 2;
/* starting address */
- cgc->cmd[2] = (lba >> 24) & 0xff;
- cgc->cmd[3] = (lba >> 16) & 0xff;
- cgc->cmd[4] = (lba >> 8) & 0xff;
- cgc->cmd[5] = lba & 0xff;
+ int_to_cmd_lba(lba, cgc->cmd);
/* number of blocks */
cgc->cmd[6] = (nblocks >> 16) & 0xff;
cgc->cmd[7] = (nblocks >> 8) & 0xff;
@@ -2188,10 +2187,7 @@ static int cdrom_read_cdda_bpc(struct cdrom_device_info *cdi, __u8 __user *ubuf,

rq->cmd[0] = GPCMD_READ_CD;
rq->cmd[1] = 1 << 2;
- rq->cmd[2] = (lba >> 24) & 0xff;
- rq->cmd[3] = (lba >> 16) & 0xff;
- rq->cmd[4] = (lba >> 8) & 0xff;
- rq->cmd[5] = lba & 0xff;
+ int_to_cmd_lba(lba, rq->cmd);
rq->cmd[6] = (nr >> 16) & 0xff;
rq->cmd[7] = (nr >> 8) & 0xff;
rq->cmd[8] = nr & 0xff;
@@ -3059,10 +3055,7 @@ static noinline int mmc_ioctl_cdrom_play_blk(struct cdrom_device_info *cdi,
if (copy_from_user(&blk, (struct cdrom_blk __user *)arg, sizeof(blk)))
return -EFAULT;
cgc->cmd[0] = GPCMD_PLAY_AUDIO_10;
- cgc->cmd[2] = (blk.from >> 24) & 0xff;
- cgc->cmd[3] = (blk.from >> 16) & 0xff;
- cgc->cmd[4] = (blk.from >> 8) & 0xff;
- cgc->cmd[5] = blk.from & 0xff;
+ int_to_cmd_lba(blk.from, cgc->cmd);
cgc->cmd[7] = (blk.len >> 8) & 0xff;
cgc->cmd[8] = blk.len & 0xff;
cgc->data_direction = CGC_DATA_NONE;
--
1.9.1

2014-11-10 20:24:47

by Fabian Frédérick

[permalink] [raw]
Subject: [PATCH v2 05/10 linux-next] cdrom: remove bool comparison/assignment to 0/1

Fix the following coccinelle warnings:

drivers/cdrom/cdrom.c:615:5-14: WARNING: Comparison of bool to 0/1
drivers/cdrom/cdrom.c:617:5-14: WARNING: Comparison of bool to 0/1
drivers/cdrom/cdrom.c:619:5-13: WARNING: Comparison of bool to 0/1
drivers/cdrom/cdrom.c:621:5-21: WARNING: Comparison of bool to 0/1
drivers/cdrom/cdrom.c:317:28-33: WARNING: Comparison of bool to 0/1
drivers/cdrom/cdrom.c:323:33-38: WARNING: Comparison of bool to 0/1
drivers/cdrom/cdrom.c:289:12-21: WARNING: Assignment of bool to 0/1
drivers/cdrom/cdrom.c:291:12-20: WARNING: Assignment of bool to 0/1
drivers/cdrom/cdrom.c:295:12-30: WARNING: Assignment of bool to 0/1

Signed-off-by: Fabian Frederick <[email protected]>
---
drivers/cdrom/cdrom.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
index ca47919..a4dd382 100644
--- a/drivers/cdrom/cdrom.c
+++ b/drivers/cdrom/cdrom.c
@@ -286,13 +286,13 @@
/* used to tell the module to turn on full debugging messages */
static bool debug;
/* default compatibility mode */
-static bool autoclose = 1;
+static bool autoclose = true;
static bool autoeject;
-static bool lockdoor = 1;
+static bool lockdoor = true;
/* will we ever get to use this... sigh. */
static bool check_media_type;
/* automatically restart mrw format */
-static bool mrw_format_restart = 1;
+static bool mrw_format_restart = true;
module_param(debug, bool, 0);
module_param(autoclose, bool, 0);
module_param(autoeject, bool, 0);
@@ -314,13 +314,13 @@ static const char * const mrw_address_space[] = { "DMA", "GAA" };
#if (ERRLOGMASK != CD_NOTHING)
#define cd_dbg(type, fmt, ...) \
do { \
- if ((ERRLOGMASK & type) || debug == 1) \
+ if ((ERRLOGMASK & type) || debug) \
pr_debug(fmt, ##__VA_ARGS__); \
} while (0)
#else
#define cd_dbg(type, fmt, ...) \
do { \
- if (0 && (ERRLOGMASK & type) || debug == 1) \
+ if (0 && (ERRLOGMASK & type) || debug) \
pr_debug(fmt, ##__VA_ARGS__); \
} while (0)
#endif
@@ -612,13 +612,13 @@ int register_cdrom(struct cdrom_device_info *cdi)
cdo->n_minors = 0;
cdi->options = CDO_USE_FFLAGS;

- if (autoclose == 1 && CDROM_CAN(CDC_CLOSE_TRAY))
+ if (autoclose && CDROM_CAN(CDC_CLOSE_TRAY))
cdi->options |= (int) CDO_AUTO_CLOSE;
- if (autoeject == 1 && CDROM_CAN(CDC_OPEN_TRAY))
+ if (autoeject && CDROM_CAN(CDC_OPEN_TRAY))
cdi->options |= (int) CDO_AUTO_EJECT;
- if (lockdoor == 1)
+ if (lockdoor)
cdi->options |= (int) CDO_LOCK;
- if (check_media_type == 1)
+ if (check_media_type)
cdi->options |= (int) CDO_CHECK_TYPE;

if (CDROM_CAN(CDC_MRW_W))
--
1.9.1

2014-11-10 20:54:25

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH v2 00/10 linux-next] cdrom: sysctl export + clean-up

On Mon, 2014-11-10 at 21:21 +0100, Fabian Frederick wrote:
> This patchset moves sysctl functions to a new file cdrom_sysctl.c
> and tries to solve small code / coding style issues.

Hey Fabian.

You're doing a lot of these.

Maybe you should setup a git tree somewhere
(maybe repo.or.cz or request a kernel.org account)
and let people pull your branches from there.

2014-11-10 22:20:34

by Jens Axboe

[permalink] [raw]
Subject: Re: [PATCH v2 00/10 linux-next] cdrom: sysctl export + clean-up

On 2014-11-10 13:21, Fabian Frederick wrote:
> This patchset moves sysctl functions to a new file cdrom_sysctl.c
> and tries to solve small code / coding style issues.
>
> V2:
> -Use cdrom_ prefix for global variables
> (suggested by Joe Perches)
> -Add 2 patches

Looks like a good cleanup, applied.

--
Jens Axboe

2014-11-10 22:21:44

by Jens Axboe

[permalink] [raw]
Subject: Re: [PATCH v2 00/10 linux-next] cdrom: sysctl export + clean-up

On 2014-11-10 13:54, Joe Perches wrote:
> On Mon, 2014-11-10 at 21:21 +0100, Fabian Frederick wrote:
>> This patchset moves sysctl functions to a new file cdrom_sysctl.c
>> and tries to solve small code / coding style issues.
>
> Hey Fabian.
>
> You're doing a lot of these.
>
> Maybe you should setup a git tree somewhere
> (maybe repo.or.cz or request a kernel.org account)
> and let people pull your branches from there.

I prefer just seeing the patches, makes it easier to review in the
mailer. And applying them from email is easy enough.

--
Jens Axboe

2014-11-10 22:24:33

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH v2 00/10 linux-next] cdrom: sysctl export + clean-up

On Mon, 2014-11-10 at 15:21 -0700, Jens Axboe wrote:
> On 2014-11-10 13:54, Joe Perches wrote:
> > On Mon, 2014-11-10 at 21:21 +0100, Fabian Frederick wrote:
> >> This patchset moves sysctl functions to a new file cdrom_sysctl.c
> >> and tries to solve small code / coding style issues.
> >
> > Hey Fabian.
> >
> > You're doing a lot of these.
> >
> > Maybe you should setup a git tree somewhere
> > (maybe repo.or.cz or request a kernel.org account)
> > and let people pull your branches from there.
>
> I prefer just seeing the patches, makes it easier to review in the
> mailer. And applying them from email is easy enough.

I prefer seeing the patches too and I didn't suggest
_not_ sending them, just adding the ability to do
a git pull.