[PATCH] auxdisplay: ht16k33: Use unique prefixed i2c client device name

From: Robin van der Gracht
Date: Wed Aug 16 2017 - 06:46:03 EST


Static naming causes problems when multiple devices are registered.

Reported-by: Michael Kaplan <M.KAPLAN@xxxxxxxx>
Signed-off-by: Robin van der Gracht <robin@xxxxxxxxxxx>
---

Michael Kaplan <M.KAPLAN@xxxxxxxx> reported the issue with his multiple
ht16k33 controller setup.

[ 472.124385] sysfs: cannot create duplicate filename '/class/backlight/ht16k33-bl'

So we've got to get rid of the static device names for backlight and keypad.

I figured incoperating the i2c device name would make it generic enough.

The default device name if on i2c adapter 0 with addres 0x70 is '0-0070' which
might be fine for an input or framebuffer device, but IMO it looks odd for a
backlight device (/sys/class/backlight/0-0070/).

So I choose to prefix the default i2c device name (assigned in i2c-core.c) with
the driver name which will result in 'ht16k33-0-0070'.

drivers/auxdisplay/ht16k33.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/auxdisplay/ht16k33.c b/drivers/auxdisplay/ht16k33.c
index 99ce9731fc9c..674a6c0cec2a 100644
--- a/drivers/auxdisplay/ht16k33.c
+++ b/drivers/auxdisplay/ht16k33.c
@@ -339,7 +339,7 @@ static int ht16k33_keypad_probe(struct i2c_client *client,

input_set_drvdata(keypad->dev, keypad);

- keypad->dev->name = DRIVER_NAME"-keypad";
+ keypad->dev->name = dev_name(&client->dev);
keypad->dev->id.bustype = BUS_I2C;
keypad->dev->open = ht16k33_keypad_start;
keypad->dev->close = ht16k33_keypad_stop;
@@ -421,6 +421,7 @@ static int ht16k33_probe(struct i2c_client *client,

priv->client = client;
i2c_set_clientdata(client, priv);
+ dev_set_name(&client->dev, DRIVER_NAME"-%s", dev_name(&client->dev));
fbdev = &priv->fbdev;

err = ht16k33_initialize(priv);
@@ -476,7 +477,8 @@ static int ht16k33_probe(struct i2c_client *client,
bl_props.type = BACKLIGHT_RAW;
bl_props.max_brightness = MAX_BRIGHTNESS;

- bl = devm_backlight_device_register(&client->dev, DRIVER_NAME"-bl",
+ bl = devm_backlight_device_register(&client->dev,
+ dev_name(&client->dev),
&client->dev, priv,
&ht16k33_bl_ops, &bl_props);
if (IS_ERR(bl)) {
--
2.11.0