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

s390/pci: use macro for attribute creation

Introduce the zpci_attr macro to create read only sysfs attributes
to avoid duplicate code.

Reviewed-by: Gerald Schaefer <gerald.schaefer@de.ibm.com>
Signed-off-by: Sebastian Ott <sebott@linux.vnet.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>

authored by

Sebastian Ott and committed by
Martin Schwidefsky
b346953d ca25f564

+15 -36
+15 -36
arch/s390/pci/pci_sysfs.c
··· 12 12 #include <linux/stat.h> 13 13 #include <linux/pci.h> 14 14 15 - static ssize_t show_fid(struct device *dev, struct device_attribute *attr, 16 - char *buf) 17 - { 18 - struct zpci_dev *zdev = get_zdev(to_pci_dev(dev)); 15 + #define zpci_attr(name, fmt, member) \ 16 + static ssize_t name##_show(struct device *dev, \ 17 + struct device_attribute *attr, char *buf) \ 18 + { \ 19 + struct zpci_dev *zdev = get_zdev(to_pci_dev(dev)); \ 20 + \ 21 + return sprintf(buf, fmt, zdev->member); \ 22 + } \ 23 + static DEVICE_ATTR_RO(name) 19 24 20 - return sprintf(buf, "0x%08x\n", zdev->fid); 21 - } 22 - static DEVICE_ATTR(function_id, S_IRUGO, show_fid, NULL); 25 + zpci_attr(function_id, "0x%08x\n", fid); 26 + zpci_attr(function_handle, "0x%08x\n", fh); 27 + zpci_attr(pchid, "0x%04x\n", pchid); 28 + zpci_attr(pfgid, "0x%02x\n", pfgid); 23 29 24 - static ssize_t show_fh(struct device *dev, struct device_attribute *attr, 25 - char *buf) 26 - { 27 - struct zpci_dev *zdev = get_zdev(to_pci_dev(dev)); 28 - 29 - return sprintf(buf, "0x%08x\n", zdev->fh); 30 - } 31 - static DEVICE_ATTR(function_handle, S_IRUGO, show_fh, NULL); 32 - 33 - static ssize_t show_pchid(struct device *dev, struct device_attribute *attr, 34 - char *buf) 35 - { 36 - struct zpci_dev *zdev = get_zdev(to_pci_dev(dev)); 37 - 38 - return sprintf(buf, "0x%04x\n", zdev->pchid); 39 - } 40 - static DEVICE_ATTR(pchid, S_IRUGO, show_pchid, NULL); 41 - 42 - static ssize_t show_pfgid(struct device *dev, struct device_attribute *attr, 43 - char *buf) 44 - { 45 - struct zpci_dev *zdev = get_zdev(to_pci_dev(dev)); 46 - 47 - return sprintf(buf, "0x%02x\n", zdev->pfgid); 48 - } 49 - static DEVICE_ATTR(pfgid, S_IRUGO, show_pfgid, NULL); 50 - 51 - static ssize_t store_recover(struct device *dev, struct device_attribute *attr, 30 + static ssize_t recover_store(struct device *dev, struct device_attribute *attr, 52 31 const char *buf, size_t count) 53 32 { 54 33 struct pci_dev *pdev = to_pci_dev(dev); ··· 49 70 pci_rescan_bus(zdev->bus); 50 71 return count; 51 72 } 52 - static DEVICE_ATTR(recover, S_IWUSR, NULL, store_recover); 73 + static DEVICE_ATTR_WO(recover); 53 74 54 75 static struct device_attribute *zpci_dev_attrs[] = { 55 76 &dev_attr_function_id,