Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi: zfcp: Clean up sysfs code for SFP diagnostics

The error path from zfcp_adapter_enqueue() no longer attempts to remove the
diagnostics attributes if they haven't been created yet.

So remove the manual 'sysfs_established' guard for this case, and use
device_add_groups() to add all adapter-related sysfs attributes in one go.

Link: https://lore.kernel.org/r/37a97537f675d643006271f37723c346189b6eec.1618417667.git.bblock@linux.ibm.com
Reviewed-by: Benjamin Block <bblock@linux.ibm.com>
Reviewed-by: Steffen Maier <maier@linux.ibm.com>
Signed-off-by: Julian Wiedmann <jwi@linux.ibm.com>
Signed-off-by: Benjamin Block <bblock@linux.ibm.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Julian Wiedmann and committed by
Martin K. Petersen
20540a56 ab1fa880

+14 -63
+4 -10
drivers/s390/scsi/zfcp_aux.c
··· 413 413 414 414 dev_set_drvdata(&ccw_device->dev, adapter); 415 415 416 - if (sysfs_create_group(&ccw_device->dev.kobj, 417 - &zfcp_sysfs_adapter_attrs)) 418 - goto failed; 419 - 420 - if (zfcp_diag_sysfs_setup(adapter)) 421 - goto err_diag_sysfs; 416 + if (device_add_groups(&ccw_device->dev, zfcp_sysfs_adapter_attr_groups)) 417 + goto err_sysfs; 422 418 423 419 /* report size limit per scatter-gather segment */ 424 420 adapter->ccw_device->dev.dma_parms = &adapter->dma_parms; ··· 423 427 424 428 return adapter; 425 429 426 - err_diag_sysfs: 427 - sysfs_remove_group(&ccw_device->dev.kobj, &zfcp_sysfs_adapter_attrs); 430 + err_sysfs: 428 431 failed: 429 432 /* TODO: make this more fine-granular */ 430 433 cancel_delayed_work_sync(&adapter->scan_work); ··· 455 460 456 461 zfcp_fc_wka_ports_force_offline(adapter->gs); 457 462 zfcp_scsi_adapter_unregister(adapter); 458 - zfcp_diag_sysfs_destroy(adapter); 459 - sysfs_remove_group(&cdev->dev.kobj, &zfcp_sysfs_adapter_attrs); 463 + device_remove_groups(&cdev->dev, zfcp_sysfs_adapter_attr_groups); 460 464 461 465 zfcp_erp_thread_kill(adapter); 462 466 zfcp_dbf_adapter_unregister(adapter);
-42
drivers/s390/scsi/zfcp_diag.c
··· 10 10 #include <linux/spinlock.h> 11 11 #include <linux/jiffies.h> 12 12 #include <linux/string.h> 13 - #include <linux/kernfs.h> 14 - #include <linux/sysfs.h> 15 13 #include <linux/errno.h> 16 14 #include <linux/slab.h> 17 15 ··· 76 78 kfree(adapter->diagnostics); 77 79 adapter->diagnostics = NULL; 78 80 } 79 - 80 - /** 81 - * zfcp_diag_sysfs_setup() - Setup the sysfs-group for adapter-diagnostics. 82 - * @adapter: target adapter to which the group should be added. 83 - * 84 - * Return: 0 on success; Something else otherwise (see sysfs_create_group()). 85 - */ 86 - int zfcp_diag_sysfs_setup(struct zfcp_adapter *const adapter) 87 - { 88 - int rc = sysfs_create_group(&adapter->ccw_device->dev.kobj, 89 - &zfcp_sysfs_diag_attr_group); 90 - if (rc == 0) 91 - adapter->diagnostics->sysfs_established = 1; 92 - 93 - return rc; 94 - } 95 - 96 - /** 97 - * zfcp_diag_sysfs_destroy() - Remove the sysfs-group for adapter-diagnostics. 98 - * @adapter: target adapter from which the group should be removed. 99 - */ 100 - void zfcp_diag_sysfs_destroy(struct zfcp_adapter *const adapter) 101 - { 102 - if (adapter->diagnostics == NULL || 103 - !adapter->diagnostics->sysfs_established) 104 - return; 105 - 106 - /* 107 - * We need this state-handling so we can prevent warnings being printed 108 - * on the kernel-console in case we have to abort a halfway done 109 - * zfcp_adapter_enqueue(), in which the sysfs-group was not yet 110 - * established. sysfs_remove_group() does this checking as well, but 111 - * still prints a warning in case we try to remove a group that has not 112 - * been established before 113 - */ 114 - adapter->diagnostics->sysfs_established = 0; 115 - sysfs_remove_group(&adapter->ccw_device->dev.kobj, 116 - &zfcp_sysfs_diag_attr_group); 117 - } 118 - 119 81 120 82 /** 121 83 * zfcp_diag_update_xdata() - Update a diagnostics buffer.
-7
drivers/s390/scsi/zfcp_diag.h
··· 40 40 /** 41 41 * struct zfcp_diag_adapter - central storage for all diagnostics concerning an 42 42 * adapter. 43 - * @sysfs_established: flag showing that the associated sysfs-group was created 44 - * during run of zfcp_adapter_enqueue(). 45 43 * @max_age: maximum age of data in diagnostic buffers before they need to be 46 44 * refreshed (in ms). 47 45 * @port_data: data retrieved using exchange port data. ··· 50 52 * @config_data.data: cached QTCB Bottom of command exchange config data. 51 53 */ 52 54 struct zfcp_diag_adapter { 53 - u64 sysfs_established :1; 54 - 55 55 unsigned long max_age; 56 56 57 57 struct zfcp_diag_adapter_port_data { ··· 64 68 65 69 int zfcp_diag_adapter_setup(struct zfcp_adapter *const adapter); 66 70 void zfcp_diag_adapter_free(struct zfcp_adapter *const adapter); 67 - 68 - int zfcp_diag_sysfs_setup(struct zfcp_adapter *const adapter); 69 - void zfcp_diag_sysfs_destroy(struct zfcp_adapter *const adapter); 70 71 71 72 void zfcp_diag_update_xdata(struct zfcp_diag_header *const hdr, 72 73 const void *const data, const bool incomplete);
+2 -2
drivers/s390/scsi/zfcp_ext.h
··· 11 11 #define ZFCP_EXT_H 12 12 13 13 #include <linux/types.h> 14 + #include <linux/sysfs.h> 14 15 #include <scsi/fc/fc_els.h> 15 16 #include "zfcp_def.h" 16 17 #include "zfcp_fc.h" ··· 180 179 const struct fsf_qtcb_bottom_port *const bottom); 181 180 182 181 /* zfcp_sysfs.c */ 182 + extern const struct attribute_group *zfcp_sysfs_adapter_attr_groups[]; 183 183 extern const struct attribute_group *zfcp_unit_attr_groups[]; 184 - extern struct attribute_group zfcp_sysfs_adapter_attrs; 185 184 extern const struct attribute_group *zfcp_port_attr_groups[]; 186 185 extern struct mutex zfcp_sysfs_port_units_mutex; 187 186 extern struct device_attribute *zfcp_sysfs_sdev_attrs[]; 188 187 extern struct device_attribute *zfcp_sysfs_shost_attrs[]; 189 - extern const struct attribute_group zfcp_sysfs_diag_attr_group; 190 188 bool zfcp_sysfs_port_is_removing(const struct zfcp_port *const port); 191 189 192 190 /* zfcp_unit.c */
+8 -2
drivers/s390/scsi/zfcp_sysfs.c
··· 435 435 NULL 436 436 }; 437 437 438 - struct attribute_group zfcp_sysfs_adapter_attrs = { 438 + static const struct attribute_group zfcp_sysfs_adapter_attr_group = { 439 439 .attrs = zfcp_adapter_attrs, 440 440 }; 441 441 ··· 906 906 NULL, 907 907 }; 908 908 909 - const struct attribute_group zfcp_sysfs_diag_attr_group = { 909 + static const struct attribute_group zfcp_sysfs_diag_attr_group = { 910 910 .name = "diagnostics", 911 911 .attrs = zfcp_sysfs_diag_attrs, 912 + }; 913 + 914 + const struct attribute_group *zfcp_sysfs_adapter_attr_groups[] = { 915 + &zfcp_sysfs_adapter_attr_group, 916 + &zfcp_sysfs_diag_attr_group, 917 + NULL, 912 918 };