aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2018-04-11 05:26:22 -0400
committerChristoph Hellwig <hch@lst.de>2018-05-16 01:24:30 -0400
commitb8b1483d79550343a687cd4a2c7ff9c82889586f (patch)
tree90b92ddd659978127706a748b378985945c727af
parentf7680bec0456403b4d3d7720e00b95586a7bc26b (diff)
sg: simplify procfs code
Use remove_proc_subtree to remove the whole subtree on cleanup, and unwind the registration loop into individual calls. Switch to use proc_create_seq where applicable. Also don't bother handling proc_create* failures - the driver works perfectly fine without the proc files, and the cleanup will handle missing files gracefully. Signed-off-by: Christoph Hellwig <hch@lst.de>
-rw-r--r--drivers/scsi/sg.c124
1 files changed, 12 insertions, 112 deletions
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index c198b96368dd..8ff687158704 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -66,7 +66,6 @@ static int sg_version_num = 30536; /* 2 digits for each component */
66static char *sg_version_date = "20140603"; 66static char *sg_version_date = "20140603";
67 67
68static int sg_proc_init(void); 68static int sg_proc_init(void);
69static void sg_proc_cleanup(void);
70#endif 69#endif
71 70
72#define SG_ALLOW_DIO_DEF 0 71#define SG_ALLOW_DIO_DEF 0
@@ -1661,7 +1660,7 @@ static void __exit
1661exit_sg(void) 1660exit_sg(void)
1662{ 1661{
1663#ifdef CONFIG_SCSI_PROC_FS 1662#ifdef CONFIG_SCSI_PROC_FS
1664 sg_proc_cleanup(); 1663 remove_proc_subtree("scsi/sg", NULL);
1665#endif /* CONFIG_SCSI_PROC_FS */ 1664#endif /* CONFIG_SCSI_PROC_FS */
1666 scsi_unregister_interface(&sg_interface); 1665 scsi_unregister_interface(&sg_interface);
1667 class_destroy(sg_sysfs_class); 1666 class_destroy(sg_sysfs_class);
@@ -2274,11 +2273,6 @@ sg_get_dev(int dev)
2274} 2273}
2275 2274
2276#ifdef CONFIG_SCSI_PROC_FS 2275#ifdef CONFIG_SCSI_PROC_FS
2277
2278static struct proc_dir_entry *sg_proc_sgp = NULL;
2279
2280static char sg_proc_sg_dirname[] = "scsi/sg";
2281
2282static int sg_proc_seq_show_int(struct seq_file *s, void *v); 2276static int sg_proc_seq_show_int(struct seq_file *s, void *v);
2283 2277
2284static int sg_proc_single_open_adio(struct inode *inode, struct file *file); 2278static int sg_proc_single_open_adio(struct inode *inode, struct file *file);
@@ -2306,37 +2300,11 @@ static const struct file_operations dressz_fops = {
2306}; 2300};
2307 2301
2308static int sg_proc_seq_show_version(struct seq_file *s, void *v); 2302static int sg_proc_seq_show_version(struct seq_file *s, void *v);
2309static int sg_proc_single_open_version(struct inode *inode, struct file *file);
2310static const struct file_operations version_fops = {
2311 .owner = THIS_MODULE,
2312 .open = sg_proc_single_open_version,
2313 .read = seq_read,
2314 .llseek = seq_lseek,
2315 .release = single_release,
2316};
2317
2318static int sg_proc_seq_show_devhdr(struct seq_file *s, void *v); 2303static int sg_proc_seq_show_devhdr(struct seq_file *s, void *v);
2319static int sg_proc_single_open_devhdr(struct inode *inode, struct file *file);
2320static const struct file_operations devhdr_fops = {
2321 .owner = THIS_MODULE,
2322 .open = sg_proc_single_open_devhdr,
2323 .read = seq_read,
2324 .llseek = seq_lseek,
2325 .release = single_release,
2326};
2327
2328static int sg_proc_seq_show_dev(struct seq_file *s, void *v); 2304static int sg_proc_seq_show_dev(struct seq_file *s, void *v);
2329static int sg_proc_open_dev(struct inode *inode, struct file *file);
2330static void * dev_seq_start(struct seq_file *s, loff_t *pos); 2305static void * dev_seq_start(struct seq_file *s, loff_t *pos);
2331static void * dev_seq_next(struct seq_file *s, void *v, loff_t *pos); 2306static void * dev_seq_next(struct seq_file *s, void *v, loff_t *pos);
2332static void dev_seq_stop(struct seq_file *s, void *v); 2307static void dev_seq_stop(struct seq_file *s, void *v);
2333static const struct file_operations dev_fops = {
2334 .owner = THIS_MODULE,
2335 .open = sg_proc_open_dev,
2336 .read = seq_read,
2337 .llseek = seq_lseek,
2338 .release = seq_release,
2339};
2340static const struct seq_operations dev_seq_ops = { 2308static const struct seq_operations dev_seq_ops = {
2341 .start = dev_seq_start, 2309 .start = dev_seq_start,
2342 .next = dev_seq_next, 2310 .next = dev_seq_next,
@@ -2345,14 +2313,6 @@ static const struct seq_operations dev_seq_ops = {
2345}; 2313};
2346 2314
2347static int sg_proc_seq_show_devstrs(struct seq_file *s, void *v); 2315static int sg_proc_seq_show_devstrs(struct seq_file *s, void *v);
2348static int sg_proc_open_devstrs(struct inode *inode, struct file *file);
2349static const struct file_operations devstrs_fops = {
2350 .owner = THIS_MODULE,
2351 .open = sg_proc_open_devstrs,
2352 .read = seq_read,
2353 .llseek = seq_lseek,
2354 .release = seq_release,
2355};
2356static const struct seq_operations devstrs_seq_ops = { 2316static const struct seq_operations devstrs_seq_ops = {
2357 .start = dev_seq_start, 2317 .start = dev_seq_start,
2358 .next = dev_seq_next, 2318 .next = dev_seq_next,
@@ -2361,14 +2321,6 @@ static const struct seq_operations devstrs_seq_ops = {
2361}; 2321};
2362 2322
2363static int sg_proc_seq_show_debug(struct seq_file *s, void *v); 2323static int sg_proc_seq_show_debug(struct seq_file *s, void *v);
2364static int sg_proc_open_debug(struct inode *inode, struct file *file);
2365static const struct file_operations debug_fops = {
2366 .owner = THIS_MODULE,
2367 .open = sg_proc_open_debug,
2368 .read = seq_read,
2369 .llseek = seq_lseek,
2370 .release = seq_release,
2371};
2372static const struct seq_operations debug_seq_ops = { 2324static const struct seq_operations debug_seq_ops = {
2373 .start = dev_seq_start, 2325 .start = dev_seq_start,
2374 .next = dev_seq_next, 2326 .next = dev_seq_next,
@@ -2376,50 +2328,23 @@ static const struct seq_operations debug_seq_ops = {
2376 .show = sg_proc_seq_show_debug, 2328 .show = sg_proc_seq_show_debug,
2377}; 2329};
2378 2330
2379
2380struct sg_proc_leaf {
2381 const char * name;
2382 const struct file_operations * fops;
2383};
2384
2385static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
2386 {"allow_dio", &adio_fops},
2387 {"debug", &debug_fops},
2388 {"def_reserved_size", &dressz_fops},
2389 {"device_hdr", &devhdr_fops},
2390 {"devices", &dev_fops},
2391 {"device_strs", &devstrs_fops},
2392 {"version", &version_fops}
2393};
2394
2395static int 2331static int
2396sg_proc_init(void) 2332sg_proc_init(void)
2397{ 2333{
2398 int num_leaves = ARRAY_SIZE(sg_proc_leaf_arr); 2334 struct proc_dir_entry *p;
2399 int k;
2400 2335
2401 sg_proc_sgp = proc_mkdir(sg_proc_sg_dirname, NULL); 2336 p = proc_mkdir("scsi/sg", NULL);
2402 if (!sg_proc_sgp) 2337 if (!p)
2403 return 1; 2338 return 1;
2404 for (k = 0; k < num_leaves; ++k) {
2405 const struct sg_proc_leaf *leaf = &sg_proc_leaf_arr[k];
2406 umode_t mask = leaf->fops->write ? S_IRUGO | S_IWUSR : S_IRUGO;
2407 proc_create(leaf->name, mask, sg_proc_sgp, leaf->fops);
2408 }
2409 return 0;
2410}
2411 2339
2412static void 2340 proc_create("allow_dio", S_IRUGO | S_IWUSR, p, &adio_fops);
2413sg_proc_cleanup(void) 2341 proc_create_seq("debug", S_IRUGO, p, &debug_seq_ops);
2414{ 2342 proc_create("def_reserved_size", S_IRUGO | S_IWUSR, p, &dressz_fops);
2415 int k; 2343 proc_create_single("device_hdr", S_IRUGO, p, sg_proc_seq_show_devhdr);
2416 int num_leaves = ARRAY_SIZE(sg_proc_leaf_arr); 2344 proc_create_seq("devices", S_IRUGO, p, &dev_seq_ops);
2417 2345 proc_create_seq("device_strs", S_IRUGO, p, &devstrs_seq_ops);
2418 if (!sg_proc_sgp) 2346 proc_create_single("version", S_IRUGO, p, sg_proc_seq_show_version);
2419 return; 2347 return 0;
2420 for (k = 0; k < num_leaves; ++k)
2421 remove_proc_entry(sg_proc_leaf_arr[k].name, sg_proc_sgp);
2422 remove_proc_entry(sg_proc_sg_dirname, NULL);
2423} 2348}
2424 2349
2425 2350
@@ -2482,22 +2407,12 @@ static int sg_proc_seq_show_version(struct seq_file *s, void *v)
2482 return 0; 2407 return 0;
2483} 2408}
2484 2409
2485static int sg_proc_single_open_version(struct inode *inode, struct file *file)
2486{
2487 return single_open(file, sg_proc_seq_show_version, NULL);
2488}
2489
2490static int sg_proc_seq_show_devhdr(struct seq_file *s, void *v) 2410static int sg_proc_seq_show_devhdr(struct seq_file *s, void *v)
2491{ 2411{
2492 seq_puts(s, "host\tchan\tid\tlun\ttype\topens\tqdepth\tbusy\tonline\n"); 2412 seq_puts(s, "host\tchan\tid\tlun\ttype\topens\tqdepth\tbusy\tonline\n");
2493 return 0; 2413 return 0;
2494} 2414}
2495 2415
2496static int sg_proc_single_open_devhdr(struct inode *inode, struct file *file)
2497{
2498 return single_open(file, sg_proc_seq_show_devhdr, NULL);
2499}
2500
2501struct sg_proc_deviter { 2416struct sg_proc_deviter {
2502 loff_t index; 2417 loff_t index;
2503 size_t max; 2418 size_t max;
@@ -2531,11 +2446,6 @@ static void dev_seq_stop(struct seq_file *s, void *v)
2531 kfree(s->private); 2446 kfree(s->private);
2532} 2447}
2533 2448
2534static int sg_proc_open_dev(struct inode *inode, struct file *file)
2535{
2536 return seq_open(file, &dev_seq_ops);
2537}
2538
2539static int sg_proc_seq_show_dev(struct seq_file *s, void *v) 2449static int sg_proc_seq_show_dev(struct seq_file *s, void *v)
2540{ 2450{
2541 struct sg_proc_deviter * it = (struct sg_proc_deviter *) v; 2451 struct sg_proc_deviter * it = (struct sg_proc_deviter *) v;
@@ -2562,11 +2472,6 @@ static int sg_proc_seq_show_dev(struct seq_file *s, void *v)
2562 return 0; 2472 return 0;
2563} 2473}
2564 2474
2565static int sg_proc_open_devstrs(struct inode *inode, struct file *file)
2566{
2567 return seq_open(file, &devstrs_seq_ops);
2568}
2569
2570static int sg_proc_seq_show_devstrs(struct seq_file *s, void *v) 2475static int sg_proc_seq_show_devstrs(struct seq_file *s, void *v)
2571{ 2476{
2572 struct sg_proc_deviter * it = (struct sg_proc_deviter *) v; 2477 struct sg_proc_deviter * it = (struct sg_proc_deviter *) v;
@@ -2650,11 +2555,6 @@ static void sg_proc_debug_helper(struct seq_file *s, Sg_device * sdp)
2650 } 2555 }
2651} 2556}
2652 2557
2653static int sg_proc_open_debug(struct inode *inode, struct file *file)
2654{
2655 return seq_open(file, &debug_seq_ops);
2656}
2657
2658static int sg_proc_seq_show_debug(struct seq_file *s, void *v) 2558static int sg_proc_seq_show_debug(struct seq_file *s, void *v)
2659{ 2559{
2660 struct sg_proc_deviter * it = (struct sg_proc_deviter *) v; 2560 struct sg_proc_deviter * it = (struct sg_proc_deviter *) v;