Skip to contentSkip to conversation

cdrom: sysctl export + clean-up

PATCH In review Fabian Frederick 3 participants 15 messages Nov 10, 2014 Uniform cdrom driver

lore
Share & tools
lore
#0 lore raw

v2 cover 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
Signature · 1 line
1.9.1
#1 lore raw

PATCH v2 1/10 cdrom: include linux/uaccess.h instead of asm/uaccess.h

---
 drivers/cdrom/cdrom.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/cdrom/cdrom.c +1 -2
index 5d28a45..c7fa0e2 100644
@@ -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;
Signature · 1 line
1.9.1
#2 lore raw

PATCH v2 2/10 cdrom: use static const char * const where possible

In reply to Fabian Frederick

Both mrw_format_status and mrw_address_space strings are only read in pr_info.

---
 drivers/cdrom/cdrom.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/cdrom/cdrom.c +2 -2
index c7fa0e2..c311e0d 100644
@@ -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, ...)				\
Signature · 1 line
1.9.1
#3 lore raw

PATCH v2 3/10 cdrom: fix spaces required errors

In reply to Fabian Frederick
---
 drivers/cdrom/cdrom.c | 38 +++++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 19 deletions(-)
drivers/cdrom/cdrom.c +19 -19
index c311e0d..deda0f1 100644
@@ -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)
 {
Signature · 1 line
1.9.1
#4 lore raw

PATCH v2 4/10 cdrom: move EXPORT_SYMBOL after functions

In reply to Fabian Frederick
---
 drivers/cdrom/cdrom.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
drivers/cdrom/cdrom.c +12 -12
index deda0f1..ca47919 100644
@@ -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
 
Signature · 1 line
1.9.1
#5 lore raw

PATCH v2 5/10 cdrom: remove bool comparison/assignment to 0/1

In reply to Fabian Frederick

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

---
 drivers/cdrom/cdrom.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/cdrom/cdrom.c +9 -9
index ca47919..a4dd382 100644
@@ -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))
Signature · 1 line
1.9.1
#6 lore raw

PATCH v2 6/10 cdrom: use bool for true/false initialized variable

In reply to Fabian Frederick
---
 drivers/cdrom/cdrom.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/cdrom/cdrom.c +3 -3
index a4dd382..a1a26d5 100644
@@ -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)
Signature · 1 line
1.9.1
#7 lore raw

PATCH v2 7/10 cdrom: export sysctl code

In reply to Fabian Frederick

-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.

---
 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
drivers/cdrom/Makefile +1 -0
index 8ffde4f..53609b0 100644
@@ -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
drivers/cdrom/cdrom.c +23 -344

437 lines not on this page · raw message

drivers/cdrom/cdrom_sysctl.c new file +297 -0

297 lines not on this page · raw message

include/linux/cdrom.h +33 -0
index 8609d57..2c9d6fb 100644
@@ -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 */
Signature · 1 line
1.9.1
#8 lore raw

PATCH v2 8/10 cdrom: fix init_cdrom_command in dvd_do_auth

In reply to Fabian Frederick

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

---
 drivers/cdrom/cdrom.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/cdrom/cdrom.c +1 -2
index 9b08f91..d397591 100644
@@ -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 */
Signature · 1 line
1.9.1
#9 lore raw

PATCH v2 9/10 cdrom: remove unnecessary status

In reply to Fabian Frederick

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

---
 drivers/cdrom/cdrom.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/cdrom/cdrom.c +1 -2
index d397591..9a6fa8f 100644
@@ -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);
Signature · 1 line
1.9.1
#10 lore raw

PATCH v2 10/10 cdrom: uniformize lba command initialization

In reply to Fabian Frederick

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

---
 drivers/cdrom/cdrom.c | 33 +++++++++++++--------------------
 1 file changed, 13 insertions(+), 20 deletions(-)
drivers/cdrom/cdrom.c +13 -20
index 9a6fa8f..3922038 100644
@@ -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;
Signature · 1 line
1.9.1
#11 lore raw
In reply to Fabian Frederick
Quoted 2 lines · Fabian Frederick

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.

#12 lore raw
Quoted 11 lines · Joe Perches
Quoted 2 lines · Fabian Frederick

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.

Signature · 1 line
Jens Axboe
#13 lore raw
Quoted 7 lines · Jens Axboe
Quoted 6 lines · Joe Perches
Quoted 2 lines · Fabian Frederick

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

Hey Fabian.

Quoted 8 lines
Quoted 5 lines

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.

#14 lore raw
In reply to Fabian Frederick
Quoted 7 lines · Fabian Frederick

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.

Signature · 1 line
Jens Axboe