Re: [PATCH/RFC] platform: Add support for automatic device IDs

From: Greg Kroah-Hartman
Date: Fri Jul 27 2012 - 14:21:53 EST


On Fri, Jul 27, 2012 at 01:46:25PM +0200, Jean Delvare wrote:
> Right now we have support for explicit platform device IDs, as well as
> ID-less platform devices when a given device type can only have one
> instance. However there are cases where multiple instances of a device
> type can exist, and their IDs aren't (and can't be) known in advance
> and do not matter. In that case we need automatic device IDs to avoid
> device name collisions.
>
> I am using magic ID value -4 for this (I left -2 and -3 free in case
> we ever need a couple of other magic values.) The automatically
> allocated device IDs are global (to avoid an additional per-driver
> cost) and are stored internally as negative numbers, starting with -4.
> This is required so that the IDs can be freed later. Externally the
> positive value is used.
>
> Signed-off-by: Jean Delvare <khali@xxxxxxxxxxxx>
> Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
> ---
> If anyone has a problem with the -4 or using negative device IDs
> internally, it would be possible to avoid that by adding a boolean
> attribute to every platform device to record whether the ID needs to
> be freed. This would cost some memory.

A boolean is "free" don't worry about that. Don't overload the device
id with "magic" values like this, I don't like that at all. I'd prefer
to see another field added if this is really going to be needed.

thanks,

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/