linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] driver core: Make probe_type of driver accessible via sysfs
@ 2021-07-08 12:20 Wenchao Hao
  2021-07-08 12:28 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 4+ messages in thread
From: Wenchao Hao @ 2021-07-08 12:20 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Rafael J . Wysocki, linux-kernel
  Cc: linfeilong, Wu Bo, Zhiqiang Liu, Wenchao Hao

Like drivers_autoprobe of bus, make probe_type of driver
accessible via sysfs, so we can get and set a driver's probe_type
happily.

Signed-off-by: Wenchao Hao <haowenchao@huawei.com>
---
 drivers/base/bus.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 1f6b4bd61056..e006562cb638 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -583,6 +583,25 @@ static ssize_t uevent_store(struct device_driver *drv, const char *buf,
 }
 static DRIVER_ATTR_WO(uevent);
 
+static ssize_t probe_type_show(struct device_driver *drv, char *buf)
+{
+	return sysfs_emit(buf, "%d\n", drv->probe_type);
+}
+
+static ssize_t probe_type_store(struct device_driver *drv, const char *buf,
+		size_t count)
+{
+	if (buf[0] == '0')
+		drv->probe_type = 0;
+	else if (buf[0] == '1')
+		drv->probe_type = 1;
+	else if (buf[0] == '2')
+		drv->probe_type = 2;
+
+	return count;
+}
+static DRIVER_ATTR_RW(probe_type);
+
 /**
  * bus_add_driver - Add a driver to the bus.
  * @drv: driver.
@@ -626,6 +645,12 @@ int bus_add_driver(struct device_driver *drv)
 		printk(KERN_ERR "%s: uevent attr (%s) failed\n",
 			__func__, drv->name);
 	}
+	error = driver_create_file(drv, &driver_attr_probe_type);
+	if (error) {
+		printk(KERN_ERR "%s: probe_type attr (%s) failed\n",
+				__func__, drv->name);
+	}
+
 	error = driver_add_groups(drv, bus->drv_groups);
 	if (error) {
 		/* How the hell do we get out of this pickle? Give up */
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] driver core: Make probe_type of driver accessible via sysfs
  2021-07-08 12:20 [PATCH] driver core: Make probe_type of driver accessible via sysfs Wenchao Hao
@ 2021-07-08 12:28 ` Greg Kroah-Hartman
  2021-07-08 12:49   ` Wenchao Hao
  0 siblings, 1 reply; 4+ messages in thread
From: Greg Kroah-Hartman @ 2021-07-08 12:28 UTC (permalink / raw)
  To: Wenchao Hao
  Cc: Rafael J . Wysocki, linux-kernel, linfeilong, Wu Bo, Zhiqiang Liu

On Thu, Jul 08, 2021 at 08:20:10PM +0800, Wenchao Hao wrote:
> Like drivers_autoprobe of bus, make probe_type of driver
> accessible via sysfs, so we can get and set a driver's probe_type
> happily.

Why is this needed?  Who will use it?  And where is the
Documentation/ABI/ file update for this new sysfs file which is required
for all sysfs files?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] driver core: Make probe_type of driver accessible via sysfs
  2021-07-08 12:28 ` Greg Kroah-Hartman
@ 2021-07-08 12:49   ` Wenchao Hao
  2021-07-08 15:53     ` Greg Kroah-Hartman
  0 siblings, 1 reply; 4+ messages in thread
From: Wenchao Hao @ 2021-07-08 12:49 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Rafael J . Wysocki, linux-kernel, linfeilong, Wu Bo, Zhiqiang Liu

In some scenarios, you need to know whether the probe() callback in struct
driver which triggered by device_add() or driver_register() is called
synchronous or not, and modify this mode according to user requirements.

While kernel now does not open an interface for users to query or
modify, so I add this interface.

I ignored updates to ABI document due to no previous experience with ABI 
change,
and I will bring updates to the ABI in next submission.

On 2021/7/8 20:28, Greg Kroah-Hartman wrote:
> On Thu, Jul 08, 2021 at 08:20:10PM +0800, Wenchao Hao wrote:
>> Like drivers_autoprobe of bus, make probe_type of driver
>> accessible via sysfs, so we can get and set a driver's probe_type
>> happily.
> Why is this needed?  Who will use it?  And where is the
> Documentation/ABI/ file update for this new sysfs file which is required
> for all sysfs files?
>
> thanks,
>
> greg k-h
> .

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] driver core: Make probe_type of driver accessible via sysfs
  2021-07-08 12:49   ` Wenchao Hao
@ 2021-07-08 15:53     ` Greg Kroah-Hartman
  0 siblings, 0 replies; 4+ messages in thread
From: Greg Kroah-Hartman @ 2021-07-08 15:53 UTC (permalink / raw)
  To: Wenchao Hao
  Cc: Rafael J . Wysocki, linux-kernel, linfeilong, Wu Bo, Zhiqiang Liu


A: http://en.wikipedia.org/wiki/Top_post
Q: Were do I find info about this thing called top-posting?
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

A: No.
Q: Should I include quotations after my reply?

http://daringfireball.net/2007/07/on_top

On Thu, Jul 08, 2021 at 08:49:31PM +0800, Wenchao Hao wrote:
> In some scenarios, you need to know whether the probe() callback in struct
> driver which triggered by device_add() or driver_register() is called
> synchronous or not, and modify this mode according to user requirements.

Who needs to know this?  What can you modify that will change anything?
What will you do to change it that will solve a problem that just fixing
the driver would not solve instead?

And what are these magic numbers that probe_type is?  If they are
exported to userspace, shouldn't they be a string instead?

> While kernel now does not open an interface for users to query or
> modify, so I add this interface.

You need to really document this in the changelog text, and in the abi
documentation, otherwise we have no idea what this for.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-07-08 15:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-08 12:20 [PATCH] driver core: Make probe_type of driver accessible via sysfs Wenchao Hao
2021-07-08 12:28 ` Greg Kroah-Hartman
2021-07-08 12:49   ` Wenchao Hao
2021-07-08 15:53     ` Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).