Re: [PATCH] base: soc: Export soc_device_to_device API

From: Greg KH
Date: Thu Sep 19 2019 - 17:32:08 EST


On Thu, Sep 19, 2019 at 02:13:44PM -0700, Murali Nalajala wrote:
> If the soc drivers want to add custom sysfs entries it needs to
> access "dev" field in "struct soc_device". This can be achieved
> by "soc_device_to_device" API. Soc drivers which are built as a
> module they need above API to be exported. Otherwise one can
> observe compilation issues.
>
> Signed-off-by: Murali Nalajala <mnalajal@xxxxxxxxxxxxxx>
> ---
> drivers/base/soc.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/base/soc.c b/drivers/base/soc.c
> index 7c0c5ca..4ad52f6 100644
> --- a/drivers/base/soc.c
> +++ b/drivers/base/soc.c
> @@ -41,6 +41,7 @@ struct device *soc_device_to_device(struct soc_device *soc_dev)
> {
> return &soc_dev->dev;
> }
> +EXPORT_SYMBOL_GPL(soc_device_to_device);
>
> static umode_t soc_attribute_mode(struct kobject *kobj,
> struct attribute *attr,

What in-kernel driver needs this?

Is linux-next breaking without this?

We don't export things unless we have a user of the export.

Also, adding "custom" sysfs attributes is almost always not the correct
thing to do at all. The driver should be doing it, by setting up the
attribute group properly so that the driver core can do it automatically
for it.

No driver should be doing individual add/remove of sysfs files. If it
does so, it is almost guaranteed to be doing it incorrectly and racing
userspace.

And yes, there's loads of in-kernel examples of doing this wrong, I've
been working on fixing that up, look at the patches now in Linus's tree
for platform and USB drivers that do this as examples of how to do it
right.

thanks,

greg k-h