diff options
author | Eric Rannaud <eric.rannaud@gmail.com> | 2007-03-31 01:23:12 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2007-04-27 13:57:29 -0400 |
commit | bf62456eb91f3d2ef0736081583d09b0b3c8b7ea (patch) | |
tree | 851c2559ae11835e19763b7c7c54393f0ae0d5f6 | |
parent | bdc4960a0b4831a24276b65f1f7afdfc57f2f5cf (diff) |
uevent: use add_uevent_var() instead of open coding it
Make use of add_uevent_var() instead of (often incorrectly) open coding it.
Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Eric Rannaud <eric.rannaud@gmail.com>
Cc: Kay Sievers <kay.sievers@vrfy.org>
Cc: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r-- | drivers/amba/bus.c | 13 | ||||
-rw-r--r-- | drivers/ieee1394/nodemgr.c | 14 | ||||
-rw-r--r-- | drivers/mmc/mmc_sysfs.c | 27 | ||||
-rw-r--r-- | drivers/s390/crypto/ap_bus.c | 28 | ||||
-rw-r--r-- | net/core/net-sysfs.c | 28 | ||||
-rw-r--r-- | sound/aoa/soundbus/core.c | 80 |
6 files changed, 79 insertions, 111 deletions
diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c index fd5475071acc..268e301775fc 100644 --- a/drivers/amba/bus.c +++ b/drivers/amba/bus.c | |||
@@ -47,14 +47,13 @@ static int amba_match(struct device *dev, struct device_driver *drv) | |||
47 | static int amba_uevent(struct device *dev, char **envp, int nr_env, char *buf, int bufsz) | 47 | static int amba_uevent(struct device *dev, char **envp, int nr_env, char *buf, int bufsz) |
48 | { | 48 | { |
49 | struct amba_device *pcdev = to_amba_device(dev); | 49 | struct amba_device *pcdev = to_amba_device(dev); |
50 | int retval = 0, i = 0, len = 0; | ||
50 | 51 | ||
51 | if (nr_env < 2) | 52 | retval = add_uevent_var(envp, nr_env, &i, |
52 | return -ENOMEM; | 53 | buf, bufsz, &len, |
53 | 54 | "AMBA_ID=%08x", pcdev->periphid); | |
54 | snprintf(buf, bufsz, "AMBA_ID=%08x", pcdev->periphid); | 55 | envp[i] = NULL; |
55 | *envp++ = buf; | 56 | return retval; |
56 | *envp++ = NULL; | ||
57 | return 0; | ||
58 | } | 57 | } |
59 | #else | 58 | #else |
60 | #define amba_uevent NULL | 59 | #define amba_uevent NULL |
diff --git a/drivers/ieee1394/nodemgr.c b/drivers/ieee1394/nodemgr.c index c5ace190bfe6..1644e6fd2c89 100644 --- a/drivers/ieee1394/nodemgr.c +++ b/drivers/ieee1394/nodemgr.c | |||
@@ -1163,6 +1163,7 @@ static int nodemgr_uevent(struct class_device *cdev, char **envp, int num_envp, | |||
1163 | struct unit_directory *ud; | 1163 | struct unit_directory *ud; |
1164 | int i = 0; | 1164 | int i = 0; |
1165 | int length = 0; | 1165 | int length = 0; |
1166 | int retval = 0; | ||
1166 | /* ieee1394:venNmoNspNverN */ | 1167 | /* ieee1394:venNmoNspNverN */ |
1167 | char buf[8 + 1 + 3 + 8 + 2 + 8 + 2 + 8 + 3 + 8 + 1]; | 1168 | char buf[8 + 1 + 3 + 8 + 2 + 8 + 2 + 8 + 3 + 8 + 1]; |
1168 | 1169 | ||
@@ -1176,14 +1177,11 @@ static int nodemgr_uevent(struct class_device *cdev, char **envp, int num_envp, | |||
1176 | 1177 | ||
1177 | #define PUT_ENVP(fmt,val) \ | 1178 | #define PUT_ENVP(fmt,val) \ |
1178 | do { \ | 1179 | do { \ |
1179 | int printed; \ | 1180 | retval = add_uevent_var(envp, num_envp, &i, \ |
1180 | envp[i++] = buffer; \ | 1181 | buffer, buffer_size, &length, \ |
1181 | printed = snprintf(buffer, buffer_size - length, \ | 1182 | fmt, val); \ |
1182 | fmt, val); \ | 1183 | if (retval) \ |
1183 | if ((buffer_size - (length+printed) <= 0) || (i >= num_envp)) \ | 1184 | return retval; \ |
1184 | return -ENOMEM; \ | ||
1185 | length += printed+1; \ | ||
1186 | buffer += printed+1; \ | ||
1187 | } while (0) | 1185 | } while (0) |
1188 | 1186 | ||
1189 | PUT_ENVP("VENDOR_ID=%06x", ud->vendor_id); | 1187 | PUT_ENVP("VENDOR_ID=%06x", ud->vendor_id); |
diff --git a/drivers/mmc/mmc_sysfs.c b/drivers/mmc/mmc_sysfs.c index d32698b02d7f..e0e82d849d5f 100644 --- a/drivers/mmc/mmc_sysfs.c +++ b/drivers/mmc/mmc_sysfs.c | |||
@@ -86,31 +86,26 @@ mmc_bus_uevent(struct device *dev, char **envp, int num_envp, char *buf, | |||
86 | { | 86 | { |
87 | struct mmc_card *card = dev_to_mmc_card(dev); | 87 | struct mmc_card *card = dev_to_mmc_card(dev); |
88 | char ccc[13]; | 88 | char ccc[13]; |
89 | int i = 0; | 89 | int retval = 0, i = 0, length = 0; |
90 | 90 | ||
91 | #define add_env(fmt,val) \ | 91 | #define add_env(fmt,val) do { \ |
92 | ({ \ | 92 | retval = add_uevent_var(envp, num_envp, &i, \ |
93 | int len, ret = -ENOMEM; \ | 93 | buf, buf_size, &length, \ |
94 | if (i < num_envp) { \ | 94 | fmt, val); \ |
95 | envp[i++] = buf; \ | 95 | if (retval) \ |
96 | len = snprintf(buf, buf_size, fmt, val) + 1; \ | 96 | return retval; \ |
97 | buf_size -= len; \ | 97 | } while (0); |
98 | buf += len; \ | ||
99 | if (buf_size >= 0) \ | ||
100 | ret = 0; \ | ||
101 | } \ | ||
102 | ret; \ | ||
103 | }) | ||
104 | 98 | ||
105 | for (i = 0; i < 12; i++) | 99 | for (i = 0; i < 12; i++) |
106 | ccc[i] = card->csd.cmdclass & (1 << i) ? '1' : '0'; | 100 | ccc[i] = card->csd.cmdclass & (1 << i) ? '1' : '0'; |
107 | ccc[12] = '\0'; | 101 | ccc[12] = '\0'; |
108 | 102 | ||
109 | i = 0; | ||
110 | add_env("MMC_CCC=%s", ccc); | 103 | add_env("MMC_CCC=%s", ccc); |
111 | add_env("MMC_MANFID=%06x", card->cid.manfid); | 104 | add_env("MMC_MANFID=%06x", card->cid.manfid); |
112 | add_env("MMC_NAME=%s", mmc_card_name(card)); | 105 | add_env("MMC_NAME=%s", mmc_card_name(card)); |
113 | add_env("MMC_OEMID=%04x", card->cid.oemid); | 106 | add_env("MMC_OEMID=%04x", card->cid.oemid); |
107 | #undef add_env | ||
108 | envp[i] = NULL; | ||
114 | 109 | ||
115 | return 0; | 110 | return 0; |
116 | } | 111 | } |
diff --git a/drivers/s390/crypto/ap_bus.c b/drivers/s390/crypto/ap_bus.c index bf37cdf43fae..5aac0ec36368 100644 --- a/drivers/s390/crypto/ap_bus.c +++ b/drivers/s390/crypto/ap_bus.c | |||
@@ -423,27 +423,25 @@ static int ap_uevent (struct device *dev, char **envp, int num_envp, | |||
423 | char *buffer, int buffer_size) | 423 | char *buffer, int buffer_size) |
424 | { | 424 | { |
425 | struct ap_device *ap_dev = to_ap_dev(dev); | 425 | struct ap_device *ap_dev = to_ap_dev(dev); |
426 | int length; | 426 | int retval = 0, length = 0, i = 0; |
427 | 427 | ||
428 | if (!ap_dev) | 428 | if (!ap_dev) |
429 | return -ENODEV; | 429 | return -ENODEV; |
430 | 430 | ||
431 | /* Set up DEV_TYPE environment variable. */ | 431 | /* Set up DEV_TYPE environment variable. */ |
432 | envp[0] = buffer; | 432 | retval = add_uevent_var(envp, num_envp, &i, |
433 | length = scnprintf(buffer, buffer_size, "DEV_TYPE=%04X", | 433 | buffer, buffer_size, &length, |
434 | ap_dev->device_type); | 434 | "DEV_TYPE=%04X", ap_dev->device_type); |
435 | if (buffer_size - length <= 0) | 435 | if (retval) |
436 | return -ENOMEM; | 436 | return retval; |
437 | buffer += length; | 437 | |
438 | buffer_size -= length; | ||
439 | /* Add MODALIAS= */ | 438 | /* Add MODALIAS= */ |
440 | envp[1] = buffer; | 439 | retval = add_uevent_var(envp, num_envp, &i, |
441 | length = scnprintf(buffer, buffer_size, "MODALIAS=ap:t%02X", | 440 | buffer, buffer_size, &length, |
442 | ap_dev->device_type); | 441 | "MODALIAS=ap:t%02X", ap_dev->device_type); |
443 | if (buffer_size - length <= 0) | 442 | |
444 | return -ENOMEM; | 443 | envp[i] = NULL; |
445 | envp[2] = NULL; | 444 | return retval; |
446 | return 0; | ||
447 | } | 445 | } |
448 | 446 | ||
449 | static struct bus_type ap_bus_type = { | 447 | static struct bus_type ap_bus_type = { |
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index e441ec7988c1..b21307b15b82 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c | |||
@@ -412,31 +412,25 @@ static int netdev_uevent(struct device *d, char **envp, | |||
412 | int num_envp, char *buf, int size) | 412 | int num_envp, char *buf, int size) |
413 | { | 413 | { |
414 | struct net_device *dev = to_net_dev(d); | 414 | struct net_device *dev = to_net_dev(d); |
415 | int i = 0; | 415 | int retval, len = 0, i = 0; |
416 | int n; | ||
417 | 416 | ||
418 | /* pass interface to uevent. */ | 417 | /* pass interface to uevent. */ |
419 | envp[i++] = buf; | 418 | retval = add_uevent_var(envp, num_envp, &i, |
420 | n = snprintf(buf, size, "INTERFACE=%s", dev->name) + 1; | 419 | buf, size, &len, |
421 | buf += n; | 420 | "INTERFACE=%s", dev->name); |
422 | size -= n; | 421 | if (retval) |
423 | 422 | goto exit; | |
424 | if ((size <= 0) || (i >= num_envp)) | ||
425 | return -ENOMEM; | ||
426 | 423 | ||
427 | /* pass ifindex to uevent. | 424 | /* pass ifindex to uevent. |
428 | * ifindex is useful as it won't change (interface name may change) | 425 | * ifindex is useful as it won't change (interface name may change) |
429 | * and is what RtNetlink uses natively. */ | 426 | * and is what RtNetlink uses natively. */ |
430 | envp[i++] = buf; | 427 | retval = add_uevent_var(envp, num_envp, &i, |
431 | n = snprintf(buf, size, "IFINDEX=%d", dev->ifindex) + 1; | 428 | buf, size, &len, |
432 | buf += n; | 429 | "IFINDEX=%d", dev->ifindex); |
433 | size -= n; | ||
434 | |||
435 | if ((size <= 0) || (i >= num_envp)) | ||
436 | return -ENOMEM; | ||
437 | 430 | ||
431 | exit: | ||
438 | envp[i] = NULL; | 432 | envp[i] = NULL; |
439 | return 0; | 433 | return retval; |
440 | } | 434 | } |
441 | #endif | 435 | #endif |
442 | 436 | ||
diff --git a/sound/aoa/soundbus/core.c b/sound/aoa/soundbus/core.c index 47b3e3768df0..418a98a10c73 100644 --- a/sound/aoa/soundbus/core.c +++ b/sound/aoa/soundbus/core.c | |||
@@ -61,9 +61,9 @@ static int soundbus_uevent(struct device *dev, char **envp, int num_envp, | |||
61 | { | 61 | { |
62 | struct soundbus_dev * soundbus_dev; | 62 | struct soundbus_dev * soundbus_dev; |
63 | struct of_device * of; | 63 | struct of_device * of; |
64 | char *scratch, *compat, *compat2; | 64 | char *compat; |
65 | int i = 0; | 65 | int retval = 0, i = 0, length = 0; |
66 | int length, cplen, cplen2, seen = 0; | 66 | int cplen, seen = 0; |
67 | 67 | ||
68 | if (!dev) | 68 | if (!dev) |
69 | return -ENODEV; | 69 | return -ENODEV; |
@@ -75,63 +75,47 @@ static int soundbus_uevent(struct device *dev, char **envp, int num_envp, | |||
75 | of = &soundbus_dev->ofdev; | 75 | of = &soundbus_dev->ofdev; |
76 | 76 | ||
77 | /* stuff we want to pass to /sbin/hotplug */ | 77 | /* stuff we want to pass to /sbin/hotplug */ |
78 | envp[i++] = scratch = buffer; | 78 | retval = add_uevent_var(envp, num_envp, &i, |
79 | length = scnprintf (scratch, buffer_size, "OF_NAME=%s", of->node->name); | 79 | buffer, buffer_size, &length, |
80 | ++length; | 80 | "OF_NAME=%s", of->node->name); |
81 | buffer_size -= length; | 81 | if (retval) |
82 | if ((buffer_size <= 0) || (i >= num_envp)) | 82 | return retval; |
83 | return -ENOMEM; | 83 | |
84 | scratch += length; | 84 | retval = add_uevent_var(envp, num_envp, &i, |
85 | 85 | buffer, buffer_size, &length, | |
86 | envp[i++] = scratch; | 86 | "OF_TYPE=%s", of->node->type); |
87 | length = scnprintf (scratch, buffer_size, "OF_TYPE=%s", of->node->type); | 87 | if (retval) |
88 | ++length; | 88 | return retval; |
89 | buffer_size -= length; | ||
90 | if ((buffer_size <= 0) || (i >= num_envp)) | ||
91 | return -ENOMEM; | ||
92 | scratch += length; | ||
93 | 89 | ||
94 | /* Since the compatible field can contain pretty much anything | 90 | /* Since the compatible field can contain pretty much anything |
95 | * it's not really legal to split it out with commas. We split it | 91 | * it's not really legal to split it out with commas. We split it |
96 | * up using a number of environment variables instead. */ | 92 | * up using a number of environment variables instead. */ |
97 | 93 | ||
98 | compat = (char *) get_property(of->node, "compatible", &cplen); | 94 | compat = (char *) get_property(of->node, "compatible", &cplen); |
99 | compat2 = compat; | ||
100 | cplen2= cplen; | ||
101 | while (compat && cplen > 0) { | 95 | while (compat && cplen > 0) { |
102 | envp[i++] = scratch; | 96 | int tmp = length; |
103 | length = scnprintf (scratch, buffer_size, | 97 | retval = add_uevent_var(envp, num_envp, &i, |
104 | "OF_COMPATIBLE_%d=%s", seen, compat); | 98 | buffer, buffer_size, &length, |
105 | ++length; | 99 | "OF_COMPATIBLE_%d=%s", seen, compat); |
106 | buffer_size -= length; | 100 | if (retval) |
107 | if ((buffer_size <= 0) || (i >= num_envp)) | 101 | return retval; |
108 | return -ENOMEM; | 102 | compat += length - tmp; |
109 | scratch += length; | 103 | cplen -= length - tmp; |
110 | length = strlen (compat) + 1; | 104 | seen += 1; |
111 | compat += length; | ||
112 | cplen -= length; | ||
113 | seen++; | ||
114 | } | 105 | } |
115 | 106 | ||
116 | envp[i++] = scratch; | 107 | retval = add_uevent_var(envp, num_envp, &i, |
117 | length = scnprintf (scratch, buffer_size, "OF_COMPATIBLE_N=%d", seen); | 108 | buffer, buffer_size, &length, |
118 | ++length; | 109 | "OF_COMPATIBLE_N=%d", seen); |
119 | buffer_size -= length; | 110 | if (retval) |
120 | if ((buffer_size <= 0) || (i >= num_envp)) | 111 | return retval; |
121 | return -ENOMEM; | 112 | retval = add_uevent_var(envp, num_envp, &i, |
122 | scratch += length; | 113 | buffer, buffer_size, &length, |
123 | 114 | "MODALIAS=%s", soundbus_dev->modalias); | |
124 | envp[i++] = scratch; | ||
125 | length = scnprintf (scratch, buffer_size, "MODALIAS=%s", | ||
126 | soundbus_dev->modalias); | ||
127 | |||
128 | buffer_size -= length; | ||
129 | if ((buffer_size <= 0) || (i >= num_envp)) | ||
130 | return -ENOMEM; | ||
131 | 115 | ||
132 | envp[i] = NULL; | 116 | envp[i] = NULL; |
133 | 117 | ||
134 | return 0; | 118 | return retval; |
135 | } | 119 | } |
136 | 120 | ||
137 | static int soundbus_device_remove(struct device *dev) | 121 | static int soundbus_device_remove(struct device *dev) |