]> Git Repo - linux.git/blobdiff - drivers/parport/procfs.c
blk-core: use pr_warn_ratelimited() in bio_check_ro()
[linux.git] / drivers / parport / procfs.c
index 4e5b972c3e2633527287e1ee663224654f8d55f9..bd388560ed59267f785fd90794dc8c78ddb51bc9 100644 (file)
 #define PARPORT_MAX_TIMESLICE_VALUE ((unsigned long) HZ)
 #define PARPORT_MIN_SPINTIME_VALUE 1
 #define PARPORT_MAX_SPINTIME_VALUE 1000
-/*
- * PARPORT_BASE_* is the size of the known parts of the sysctl path
- * in dev/partport/%s/devices/%s. "dev/parport/"(12), "/devices/"(9
- * and null char(1).
- */
-#define PARPORT_BASE_PATH_SIZE 13
-#define PARPORT_BASE_DEVICES_PATH_SIZE 22
 
 static int do_active_device(struct ctl_table *table, int write,
                      void *result, size_t *lenp, loff_t *ppos)
@@ -259,8 +252,12 @@ PARPORT_MAX_SPINTIME_VALUE;
 struct parport_sysctl_table {
        struct ctl_table_header *port_header;
        struct ctl_table_header *devices_header;
-       struct ctl_table vars[12];
-       struct ctl_table device_dir[2];
+#ifdef CONFIG_PARPORT_1284
+       struct ctl_table vars[10];
+#else
+       struct ctl_table vars[5];
+#endif /* IEEE 1284 support */
+       struct ctl_table device_dir[1];
 };
 
 static const struct parport_sysctl_table parport_sysctl_template = {
@@ -341,7 +338,6 @@ static const struct parport_sysctl_table parport_sysctl_template = {
                        .proc_handler   = do_autoprobe
                },
 #endif /* IEEE 1284 support */
-               {}
        },
        {
                {
@@ -351,19 +347,14 @@ static const struct parport_sysctl_table parport_sysctl_template = {
                        .mode           = 0444,
                        .proc_handler   = do_active_device
                },
-               {}
        },
 };
 
 struct parport_device_sysctl_table
 {
        struct ctl_table_header *sysctl_header;
-       struct ctl_table vars[2];
-       struct ctl_table device_dir[2];
-       struct ctl_table devices_root_dir[2];
-       struct ctl_table port_dir[2];
-       struct ctl_table parport_dir[2];
-       struct ctl_table dev_dir[2];
+       struct ctl_table vars[1];
+       struct ctl_table device_dir[1];
 };
 
 static const struct parport_device_sysctl_table
@@ -379,7 +370,6 @@ parport_device_sysctl_template = {
                        .extra1         = (void*) &parport_min_timeslice_value,
                        .extra2         = (void*) &parport_max_timeslice_value
                },
-               {}
        },
        {
                {
@@ -388,17 +378,13 @@ parport_device_sysctl_template = {
                        .maxlen         = 0,
                        .mode           = 0555,
                },
-               {}
        }
 };
 
 struct parport_default_sysctl_table
 {
        struct ctl_table_header *sysctl_header;
-       struct ctl_table vars[3];
-       struct ctl_table default_dir[2];
-       struct ctl_table parport_dir[2];
-       struct ctl_table dev_dir[2];
+       struct ctl_table vars[2];
 };
 
 static struct parport_default_sysctl_table
@@ -423,7 +409,6 @@ parport_default_sysctl_table = {
                        .extra1         = (void*) &parport_min_spintime_value,
                        .extra2         = (void*) &parport_max_spintime_value
                },
-               {}
        }
 };
 
@@ -431,8 +416,7 @@ int parport_proc_register(struct parport *port)
 {
        struct parport_sysctl_table *t;
        char *tmp_dir_path;
-       size_t tmp_path_len, port_name_len;
-       int bytes_written, i, err = 0;
+       int i, err = 0;
 
        t = kmemdup(&parport_sysctl_template, sizeof(*t), GFP_KERNEL);
        if (t == NULL)
@@ -443,38 +427,28 @@ int parport_proc_register(struct parport *port)
        t->vars[0].data = &port->spintime;
        for (i = 0; i < 5; i++) {
                t->vars[i].extra1 = port;
+#ifdef CONFIG_PARPORT_1284
                t->vars[5 + i].extra2 = &port->probe_info[i];
+#endif /* IEEE 1284 support */
        }
 
-       port_name_len = strnlen(port->name, PARPORT_NAME_MAX_LEN);
-       /*
-        * Allocate a buffer for two paths: dev/parport/PORT and dev/parport/PORT/devices.
-        * We calculate for the second as that will give us enough for the first.
-        */
-       tmp_path_len = PARPORT_BASE_DEVICES_PATH_SIZE + port_name_len;
-       tmp_dir_path = kzalloc(tmp_path_len, GFP_KERNEL);
+       tmp_dir_path = kasprintf(GFP_KERNEL, "dev/parport/%s/devices", port->name);
        if (!tmp_dir_path) {
                err = -ENOMEM;
                goto exit_free_t;
        }
 
-       bytes_written = snprintf(tmp_dir_path, tmp_path_len,
-                                "dev/parport/%s/devices", port->name);
-       if (tmp_path_len <= bytes_written) {
-               err = -ENOENT;
-               goto exit_free_tmp_dir_path;
-       }
        t->devices_header = register_sysctl(tmp_dir_path, t->device_dir);
        if (t->devices_header == NULL) {
                err = -ENOENT;
                goto  exit_free_tmp_dir_path;
        }
 
-       tmp_path_len = PARPORT_BASE_PATH_SIZE + port_name_len;
-       bytes_written = snprintf(tmp_dir_path, tmp_path_len,
-                                "dev/parport/%s", port->name);
-       if (tmp_path_len <= bytes_written) {
-               err = -ENOENT;
+       kfree(tmp_dir_path);
+
+       tmp_dir_path = kasprintf(GFP_KERNEL, "dev/parport/%s", port->name);
+       if (!tmp_dir_path) {
+               err = -ENOMEM;
                goto unregister_devices_h;
        }
 
@@ -514,34 +488,22 @@ int parport_proc_unregister(struct parport *port)
 
 int parport_device_proc_register(struct pardevice *device)
 {
-       int bytes_written, err = 0;
        struct parport_device_sysctl_table *t;
        struct parport * port = device->port;
-       size_t port_name_len, device_name_len, tmp_dir_path_len;
        char *tmp_dir_path;
+       int err = 0;
        
        t = kmemdup(&parport_device_sysctl_template, sizeof(*t), GFP_KERNEL);
        if (t == NULL)
                return -ENOMEM;
 
-       port_name_len = strnlen(port->name, PARPORT_NAME_MAX_LEN);
-       device_name_len = strnlen(device->name, PATH_MAX);
-
        /* Allocate a buffer for two paths: dev/parport/PORT/devices/DEVICE. */
-       tmp_dir_path_len = PARPORT_BASE_DEVICES_PATH_SIZE + port_name_len + device_name_len;
-       tmp_dir_path = kzalloc(tmp_dir_path_len, GFP_KERNEL);
+       tmp_dir_path = kasprintf(GFP_KERNEL, "dev/parport/%s/devices/%s", port->name, device->name);
        if (!tmp_dir_path) {
                err = -ENOMEM;
                goto exit_free_t;
        }
 
-       bytes_written = snprintf(tmp_dir_path, tmp_dir_path_len, "dev/parport/%s/devices/%s",
-                                port->name, device->name);
-       if (tmp_dir_path_len <= bytes_written) {
-               err = -ENOENT;
-               goto exit_free_path;
-       }
-
        t->vars[0].data = &device->timeslice;
 
        t->sysctl_header = register_sysctl(tmp_dir_path, t->vars);
@@ -554,9 +516,6 @@ int parport_device_proc_register(struct pardevice *device)
        kfree(tmp_dir_path);
        return 0;
 
-exit_free_path:
-       kfree(tmp_dir_path);
-
 exit_free_t:
        kfree(t);
 
This page took 0.037378 seconds and 4 git commands to generate.