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

Configure Feed

Select the types of activity you want to include in your feed.

Input: ims-pcu - use driver core to instantiate device attributes

Instead of manually creating driver-specific device attributes
set struct usb_driver->dev_groups pointer to have the driver core
do it.

Link: https://lore.kernel.org/r/20240610041813.722445-1-dmitry.torokhov@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

+28 -25
+28 -25
drivers/input/misc/ims-pcu.c
··· 1465 1465 NULL 1466 1466 }; 1467 1467 1468 + static umode_t ims_pcu_ofn_is_attr_visible(struct kobject *kobj, 1469 + struct attribute *attr, int n) 1470 + { 1471 + struct device *dev = kobj_to_dev(kobj); 1472 + struct usb_interface *intf = to_usb_interface(dev); 1473 + struct ims_pcu *pcu = usb_get_intfdata(intf); 1474 + umode_t mode = attr->mode; 1475 + 1476 + /* 1477 + * PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor. 1478 + */ 1479 + if (pcu->bootloader_mode || pcu->device_id == IMS_PCU_PCU_B_DEVICE_ID) 1480 + mode = 0; 1481 + 1482 + return mode; 1483 + } 1484 + 1468 1485 static const struct attribute_group ims_pcu_ofn_attr_group = { 1469 - .name = "ofn", 1470 - .attrs = ims_pcu_ofn_attrs, 1486 + .name = "ofn", 1487 + .is_visible = ims_pcu_ofn_is_attr_visible, 1488 + .attrs = ims_pcu_ofn_attrs, 1471 1489 }; 1472 1490 1473 1491 static void ims_pcu_irq(struct urb *urb) ··· 1907 1889 /* Device appears to be operable, complete initialization */ 1908 1890 pcu->device_no = atomic_inc_return(&device_no); 1909 1891 1910 - /* 1911 - * PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor 1912 - */ 1913 - if (pcu->device_id != IMS_PCU_PCU_B_DEVICE_ID) { 1914 - error = sysfs_create_group(&pcu->dev->kobj, 1915 - &ims_pcu_ofn_attr_group); 1916 - if (error) 1917 - return error; 1918 - } 1919 - 1920 1892 error = ims_pcu_setup_backlight(pcu); 1921 1893 if (error) 1922 1894 return error; ··· 1943 1935 ims_pcu_destroy_gamepad(pcu); 1944 1936 ims_pcu_destroy_buttons(pcu); 1945 1937 ims_pcu_destroy_backlight(pcu); 1946 - 1947 - if (pcu->device_id != IMS_PCU_PCU_B_DEVICE_ID) 1948 - sysfs_remove_group(&pcu->dev->kobj, 1949 - &ims_pcu_ofn_attr_group); 1950 1938 } 1951 1939 } 1952 1940 ··· 2034 2030 if (error) 2035 2031 goto err_stop_io; 2036 2032 2037 - error = sysfs_create_group(&intf->dev.kobj, &ims_pcu_attr_group); 2038 - if (error) 2039 - goto err_stop_io; 2040 - 2041 2033 error = pcu->bootloader_mode ? 2042 2034 ims_pcu_init_bootloader_mode(pcu) : 2043 2035 ims_pcu_init_application_mode(pcu); 2044 2036 if (error) 2045 - goto err_remove_sysfs; 2037 + goto err_stop_io; 2046 2038 2047 2039 return 0; 2048 2040 2049 - err_remove_sysfs: 2050 - sysfs_remove_group(&intf->dev.kobj, &ims_pcu_attr_group); 2051 2041 err_stop_io: 2052 2042 ims_pcu_stop_io(pcu); 2053 2043 err_free_buffers: ··· 2066 2068 */ 2067 2069 if (alt->desc.bInterfaceClass != USB_CLASS_COMM) 2068 2070 return; 2069 - 2070 - sysfs_remove_group(&intf->dev.kobj, &ims_pcu_attr_group); 2071 2071 2072 2072 ims_pcu_stop_io(pcu); 2073 2073 ··· 2125 2129 { } 2126 2130 }; 2127 2131 2132 + static const struct attribute_group *ims_pcu_sysfs_groups[] = { 2133 + &ims_pcu_attr_group, 2134 + &ims_pcu_ofn_attr_group, 2135 + NULL 2136 + }; 2137 + 2128 2138 static struct usb_driver ims_pcu_driver = { 2129 2139 .name = "ims_pcu", 2130 2140 .id_table = ims_pcu_id_table, 2141 + .dev_groups = ims_pcu_sysfs_groups, 2131 2142 .probe = ims_pcu_probe, 2132 2143 .disconnect = ims_pcu_disconnect, 2133 2144 #ifdef CONFIG_PM