aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorEric Rannaud <eric.rannaud@gmail.com>2007-03-31 01:23:12 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2007-04-27 13:57:29 -0400
commitbf62456eb91f3d2ef0736081583d09b0b3c8b7ea (patch)
tree851c2559ae11835e19763b7c7c54393f0ae0d5f6 /drivers
parentbdc4960a0b4831a24276b65f1f7afdfc57f2f5cf (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>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/amba/bus.c13
-rw-r--r--drivers/ieee1394/nodemgr.c14
-rw-r--r--drivers/mmc/mmc_sysfs.c27
-rw-r--r--drivers/s390/crypto/ap_bus.c28
4 files changed, 36 insertions, 46 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)
47static int amba_uevent(struct device *dev, char **envp, int nr_env, char *buf, int bufsz) 47static 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) \
1178do { \ 1179do { \
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
449static struct bus_type ap_bus_type = { 447static struct bus_type ap_bus_type = {