Skip to contentSkip to conversation

create modalias file in sysfs for bus vio

PATCH In review Olaf Hering 2 participants 4 messages Jan 22, 2008 – Feb 4, 2008 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 create modalias file in sysfs for bus vio

Create /sys/bus/vio/devices/*/modalias file to allow autoloading of modules. modalias files are already present for many other bus types.

---
 arch/powerpc/kernel/vio.c |   15 +++++++++++++++
 1 file changed, 15 insertions(+)
arch/powerpc/kernel/vio.c +15 -0
@@ -296,9 +296,24 @@ static ssize_t devspec_show(struct devic
 	return sprintf(buf, "%s\n", of_node ? of_node->full_name : "none");
 }
 
+static ssize_t modalias_show (struct device *dev, struct device_attribute *attr,
+			      char *buf)
+{
+	struct device_node *of_node = dev->archdata.of_node;
+	const char *compat;
+	int i = 0;
+
+	if (of_node) {
+		compat = of_get_property(of_node, "compatible", &i);
+		i = sprintf (buf, "vio:T%sS%s\n", of_node->type, compat ? compat : "");
+	}
+	return i;
+}
+
 static struct device_attribute vio_dev_attrs[] = {
 	__ATTR_RO(name),
 	__ATTR_RO(devspec),
+	__ATTR_RO(modalias),
 	__ATTR_NULL
 };
 
#1 lore raw

Hi Olaf,

Thanks for this. Just a couple of nits ...

Quoted 2 lines · On Tue, 22 Jan 2008 09:33:28 +0100 Olaf Hering <[email protected]> wrote:

+static ssize_t modalias_show (struct device *dev, struct device_attribute *attr,

                               ^

No space here, please.

arch/powerpc/kernel/vio.c static ssize_t devspec_show(struct devic · line 308

Quoted 9 lines
arch/powerpc/kernel/vio.c +9 -0
+			      char *buf)
+{
+	struct device_node *of_node = dev->archdata.of_node;
+	const char *compat;
+	int i = 0;
+
+	if (of_node) {
+		compat = of_get_property(of_node, "compatible", &i);
+		i = sprintf (buf, "vio:T%sS%s\n", of_node->type, compat ? compat : "");
                           ^

Or here.

It would be nice if we could factor out the "vio:T%sS%s" string as it is also used in vio_hotplug().

Signature · 3 lines
Cheers,
Stephen Rothwell                    [email protected]
http://www.canb.auug.org.au/~sfr/
#2 lore raw
Quoted 2 lines · Stephen Rothwell

It would be nice if we could factor out the "vio:T%sS%s" string as it is also used in vio_hotplug().

What exactly do you have in mind?
Creating a tempstring seems to make things more complicated.

#3 lore raw

Hi Olaf,

[Sorry, been on vacation]

Quoted 8 lines · On Fri, 25 Jan 2008 18:09:14 +0100 Olaf Hering <[email protected]> wrote:
Quoted 2 lines · Stephen Rothwell

It would be nice if we could factor out the "vio:T%sS%s" string as it is also used in vio_hotplug().

What exactly do you have in mind?
Creating a tempstring seems to make things more complicated.

Yeah, but it would be nice if the format only had to be known/changed in one place. Don't worry about it for now. Or maybe create a "static const char []" or #define with the string.

Signature · 3 lines
Cheers,
Stephen Rothwell                    [email protected]
http://www.canb.auug.org.au/~sfr/