Commit 7fd097d4 authored by Akinobu Mita's avatar Akinobu Mita Committed by Jens Axboe

cdrom: use list_head for cdrom_device_info list

Use list_head for cdrom_device_info list instead of opencoded
singly list handling.
Signed-off-by: default avatarAkinobu Mita <akinobu.mita@gmail.com>
Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
parent 032d8d90
...@@ -362,7 +362,7 @@ static int cdrom_get_disc_info(struct cdrom_device_info *cdi, disc_information * ...@@ -362,7 +362,7 @@ static int cdrom_get_disc_info(struct cdrom_device_info *cdi, disc_information *
static void cdrom_sysctl_register(void); static void cdrom_sysctl_register(void);
static struct cdrom_device_info *topCdromPtr; static LIST_HEAD(cdrom_list);
static int cdrom_dummy_generic_packet(struct cdrom_device_info *cdi, static int cdrom_dummy_generic_packet(struct cdrom_device_info *cdi,
struct packet_command *cgc) struct packet_command *cgc)
...@@ -436,35 +436,18 @@ int register_cdrom(struct cdrom_device_info *cdi) ...@@ -436,35 +436,18 @@ int register_cdrom(struct cdrom_device_info *cdi)
cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name); cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
mutex_lock(&cdrom_mutex); mutex_lock(&cdrom_mutex);
cdi->next = topCdromPtr; list_add(&cdi->list, &cdrom_list);
topCdromPtr = cdi;
mutex_unlock(&cdrom_mutex); mutex_unlock(&cdrom_mutex);
return 0; return 0;
} }
#undef ENSURE #undef ENSURE
int unregister_cdrom(struct cdrom_device_info *unreg) int unregister_cdrom(struct cdrom_device_info *cdi)
{ {
struct cdrom_device_info *cdi, *prev;
cdinfo(CD_OPEN, "entering unregister_cdrom\n"); cdinfo(CD_OPEN, "entering unregister_cdrom\n");
prev = NULL;
mutex_lock(&cdrom_mutex); mutex_lock(&cdrom_mutex);
cdi = topCdromPtr; list_del(&cdi->list);
while (cdi && cdi != unreg) {
prev = cdi;
cdi = cdi->next;
}
if (cdi == NULL) {
mutex_unlock(&cdrom_mutex);
return -2;
}
if (prev)
prev->next = cdi->next;
else
topCdromPtr = cdi->next;
mutex_unlock(&cdrom_mutex); mutex_unlock(&cdrom_mutex);
if (cdi->exit) if (cdi->exit)
...@@ -3306,7 +3289,7 @@ static int cdrom_print_info(const char *header, int val, char *info, ...@@ -3306,7 +3289,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
*pos += ret; *pos += ret;
for (cdi = topCdromPtr; cdi; cdi = cdi->next) { list_for_each_entry(cdi, &cdrom_list, list) {
switch (option) { switch (option) {
case CTL_NAME: case CTL_NAME:
ret = scnprintf(info + *pos, max_size - *pos, ret = scnprintf(info + *pos, max_size - *pos,
...@@ -3428,7 +3411,7 @@ static void cdrom_update_settings(void) ...@@ -3428,7 +3411,7 @@ static void cdrom_update_settings(void)
struct cdrom_device_info *cdi; struct cdrom_device_info *cdi;
mutex_lock(&cdrom_mutex); mutex_lock(&cdrom_mutex);
for (cdi = topCdromPtr; cdi != NULL; cdi = cdi->next) { list_for_each_entry(cdi, &cdrom_list, list) {
if (autoclose && CDROM_CAN(CDC_CLOSE_TRAY)) if (autoclose && CDROM_CAN(CDC_CLOSE_TRAY))
cdi->options |= CDO_AUTO_CLOSE; cdi->options |= CDO_AUTO_CLOSE;
else if (!autoclose) else if (!autoclose)
......
...@@ -910,6 +910,7 @@ struct mode_page_header { ...@@ -910,6 +910,7 @@ struct mode_page_header {
#ifdef __KERNEL__ #ifdef __KERNEL__
#include <linux/fs.h> /* not really needed, later.. */ #include <linux/fs.h> /* not really needed, later.. */
#include <linux/device.h> #include <linux/device.h>
#include <linux/list.h>
struct packet_command struct packet_command
{ {
...@@ -934,7 +935,7 @@ struct packet_command ...@@ -934,7 +935,7 @@ struct packet_command
/* Uniform cdrom data structures for cdrom.c */ /* Uniform cdrom data structures for cdrom.c */
struct cdrom_device_info { struct cdrom_device_info {
struct cdrom_device_ops *ops; /* link to device_ops */ struct cdrom_device_ops *ops; /* link to device_ops */
struct cdrom_device_info *next; /* next device_info for this major */ struct list_head list; /* linked list of all device_info */
struct gendisk *disk; /* matching block layer disk */ struct gendisk *disk; /* matching block layer disk */
void *handle; /* driver-dependent data */ void *handle; /* driver-dependent data */
/* specifications */ /* specifications */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment