[i2c] Empty i2c device name sysfs attribute
David Brownell
david-b at pacbell.net
Fri Jun 22 21:08:49 CEST 2007
On Thursday 21 June 2007, Jean Delvare wrote:
> Hi David, hi all,
>
> I just hit a minor problem with a new-style i2c driver. When
> instantiating a new device, the type member of struct i2c_board_info is
> said to be optional. If it's not set, i2c_client.name isn't set either.
> However, the device's "name" sysfs attribute is always created. So we
> end up with an empty sysfs file. Confusing; I think we want to change
> that.
There are other empty sysfs files. It's the simplest solution when
no value is currently specified.
> I see 3 possibilities:
> * Create the "name" sysfs file conditionally. This means extra code.
> * Make the type member of struct i2c_board_info mandatory.
> * Use the driver name for i2c_client.name if no type is provided.
>
> This last possibility has my preference, here's a patch. Thoughts
> anyone?
Another solution would be to use a constant string, maybe
something like "(unspecified)". If the empty file bothers
you, I'd rather go that route than overload the driver name.
- Dave
> * * * * *
>
> Use the i2c driver name for the new-style i2c device's "name" sysfs
> file if no type string was provided at device creation. Otherwise we
> create an empty sysfs file, which is confusing.
>
> Signed-off-by: Jean Delvare <khali at linux-fr.org>
> ---
> drivers/i2c/i2c-core.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> --- linux-2.6.22-rc5.orig/drivers/i2c/i2c-core.c 2007-06-21 09:56:01.000000000 +0200
> +++ linux-2.6.22-rc5/drivers/i2c/i2c-core.c 2007-06-21 21:00:26.000000000 +0200
> @@ -236,7 +236,10 @@ i2c_new_device(struct i2c_adapter *adap,
>
> strlcpy(client->driver_name, info->driver_name,
> sizeof(client->driver_name));
> - strlcpy(client->name, info->type, sizeof(client->name));
> + if (info->type[0])
> + strlcpy(client->name, info->type, sizeof(client->name));
> + else
> + strlcpy(client->name, info->driver_name, sizeof(client->name));
>
> /* a new style driver may be bound to this device when we
> * return from this function, or any later moment (e.g. maybe
>
>
> --
> Jean Delvare
>
More information about the i2c
mailing list