From a5cd98b796b6891edc324415034a7f89531c754f Mon Sep 17 00:00:00 2001 From: Ricardo Ribalda Delgado Date: Wed, 14 Aug 2013 14:23:48 -0700 Subject: leds-pca9633: Unique naming of the LEDs If there is more than one pca963x chips on the system and there are some LEDs without platform_data names, the driver wont be able to provide unique naming to them. This will cause led_class_dev_register to fail, unregistering all the LEDs of the chip. This patch adds the i2c address to the name of the unnamed LEDs, making them unique. [ 555.346827] ------------[ cut here ]------------ [ 555.346844] WARNING: at /build/linux-voe0Su/linux-3.9.8/fs/sysfs/dir.c:536 sysfs_add_one+0x8b/0x9d() [ 555.346847] Hardware name: QT5022 [ 555.346850] sysfs: cannot create duplicate filename '/class/leds/pca9633:6' [ 555.346853] Modules linked in: qt5038_platform(O+) leds_pca9633(O) hid_generic ledtrig_default_on rfcomm bnep bluetooth binfmt_misc nfsd auth_rpcgss nfs_acl nfs lockd dns_resolver fscache sunrpc nls_utf8 nls_cp437 vfat fat loop fuse joydev hid_multitouch usbhid hid acpi_cpufreq mperf kvm_amd kvm evdev pn533 nfc arc4 microcode pcspkr efivars k10temp ath9k ath9k_common ath9k_hw ath fglrx(PO) mac80211 cfg80211 video rfkill processor thermal_sys sp5100_tco button i2c_piix4 ext4 crc16 jbd2 mbcache sg sd_mod crc_t10dif ahci libahci igb i2c_algo_bit i2c_core dca ptp pps_core ehci_pci ohci_hcd ehci_hcd libata usbcore usb_common scsi_mod [last unloaded: leds_pca963x] [ 555.346940] Pid: 4766, comm: insmod Tainted: P W O 3.9-1-amd64 #1 Debian 3.9.8-1 [ 555.346943] Call Trace: [ 555.346956] [] ? warn_slowpath_common+0x76/0x8c [ 555.346962] [] ? warn_slowpath_fmt+0x47/0x49 [ 555.346968] [] ? sysfs_pathname+0x3b/0x41 [ 555.346973] [] ? sysfs_add_one+0x8b/0x9d [ 555.346978] [] ? sysfs_do_create_link_sd+0xe8/0x174 [ 555.346985] [] ? device_add+0x243/0x5ab [ 555.346991] [] ? complete_all+0x31/0x40 [ 555.346998] [] ? init_timer_key+0xc/0x56 [ 555.347004] [] ? device_create_vargs+0x82/0xb6 [ 555.347009] [] ? device_create+0x2f/0x31 [ 555.347014] [] ? should_resched+0x5/0x23 [ 555.347021] [] ? led_classdev_register+0x24/0x103 [ 555.347028] [] ? pca9633_probe+0x173/0x239 [leds_pca9633] [ 555.347035] [] ? __driver_attach+0x73/0x73 [ 555.347049] [] ? i2c_device_probe+0x63/0x88 [i2c_core] [ 555.347057] [] ? driver_probe_device+0x92/0x1b0 [ 555.347064] [] ? bus_for_each_drv+0x43/0x7d [ 555.347070] [] ? device_attach+0x68/0x83 [ 555.347078] [] ? bus_probe_device+0x25/0x8d [ 555.347083] [] ? device_add+0x3ea/0x5ab [ 555.347088] [] ? complete_all+0x31/0x40 [ 555.347094] [] ? init_timer_key+0xc/0x56 [ 555.347104] [] ? i2c_new_device+0x10d/0x179 [i2c_core] [ 555.347112] [] ? qt5038_init+0x36/0x1000 [qt5038_platform] [ 555.347119] [] ? 0xffffffffa008efff [ 555.347125] [] ? do_one_initcall+0x74/0x128 [ 555.347131] [] ? 0xffffffffa008efff [ 555.347137] [] ? load_module+0x1af7/0x1dfc [ 555.347144] [] ? free_notes_attrs+0x3c/0x3c [ 555.347150] [] ? sys_init_module+0x9e/0xab [ 555.347157] [] ? system_call_fastpath+0x16/0x1b [ 555.347161] ---[ end trace ad00b85794e0de4d ]--- [ 555.347448] leds-pca9633: probe of 0-006b failed with error -17 Signed-off-by: Ricardo Ribalda Delgado Signed-off-by: Bryan Wu diff --git a/drivers/leds/leds-pca9633.c b/drivers/leds/leds-pca9633.c index e59ca0a..7dd48f8 100644 --- a/drivers/leds/leds-pca9633.c +++ b/drivers/leds/leds-pca9633.c @@ -362,10 +362,12 @@ static int pca9633_probe(struct i2c_client *client, if (pdata->leds.leds[i].default_trigger) pca9633[i].led_cdev.default_trigger = pdata->leds.leds[i].default_trigger; - } else { - snprintf(pca9633[i].name, sizeof(pca9633[i].name), - "pca9633:%d", i); } + if (!pdata || i >= pdata->leds.num_leds || + !pdata->leds.leds[i].name) + snprintf(pca9633[i].name, sizeof(pca9633[i].name), + "pca9633:%d:%.2x:%d", client->adapter->nr, + client->addr, i); pca9633[i].led_cdev.name = pca9633[i].name; pca9633[i].led_cdev.brightness_set = pca9633_led_set; -- cgit v0.10.2