mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-29 10:01:25 +00:00
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>
This commit is contained in:
parent
bdc4960a0b
commit
bf62456eb9
6 changed files with 77 additions and 109 deletions
|
@ -47,14 +47,13 @@ static int amba_match(struct device *dev, struct device_driver *drv)
|
||||||
static int amba_uevent(struct device *dev, char **envp, int nr_env, char *buf, int bufsz)
|
static int amba_uevent(struct device *dev, char **envp, int nr_env, char *buf, int bufsz)
|
||||||
{
|
{
|
||||||
struct amba_device *pcdev = to_amba_device(dev);
|
struct amba_device *pcdev = to_amba_device(dev);
|
||||||
|
int retval = 0, i = 0, len = 0;
|
||||||
|
|
||||||
if (nr_env < 2)
|
retval = add_uevent_var(envp, nr_env, &i,
|
||||||
return -ENOMEM;
|
buf, bufsz, &len,
|
||||||
|
"AMBA_ID=%08x", pcdev->periphid);
|
||||||
snprintf(buf, bufsz, "AMBA_ID=%08x", pcdev->periphid);
|
envp[i] = NULL;
|
||||||
*envp++ = buf;
|
return retval;
|
||||||
*envp++ = NULL;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#define amba_uevent NULL
|
#define amba_uevent NULL
|
||||||
|
|
|
@ -1163,6 +1163,7 @@ static int nodemgr_uevent(struct class_device *cdev, char **envp, int num_envp,
|
||||||
struct unit_directory *ud;
|
struct unit_directory *ud;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int length = 0;
|
int length = 0;
|
||||||
|
int retval = 0;
|
||||||
/* ieee1394:venNmoNspNverN */
|
/* ieee1394:venNmoNspNverN */
|
||||||
char buf[8 + 1 + 3 + 8 + 2 + 8 + 2 + 8 + 3 + 8 + 1];
|
char buf[8 + 1 + 3 + 8 + 2 + 8 + 2 + 8 + 3 + 8 + 1];
|
||||||
|
|
||||||
|
@ -1176,14 +1177,11 @@ static int nodemgr_uevent(struct class_device *cdev, char **envp, int num_envp,
|
||||||
|
|
||||||
#define PUT_ENVP(fmt,val) \
|
#define PUT_ENVP(fmt,val) \
|
||||||
do { \
|
do { \
|
||||||
int printed; \
|
retval = add_uevent_var(envp, num_envp, &i, \
|
||||||
envp[i++] = buffer; \
|
buffer, buffer_size, &length, \
|
||||||
printed = snprintf(buffer, buffer_size - length, \
|
|
||||||
fmt, val); \
|
fmt, val); \
|
||||||
if ((buffer_size - (length+printed) <= 0) || (i >= num_envp)) \
|
if (retval) \
|
||||||
return -ENOMEM; \
|
return retval; \
|
||||||
length += printed+1; \
|
|
||||||
buffer += printed+1; \
|
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
PUT_ENVP("VENDOR_ID=%06x", ud->vendor_id);
|
PUT_ENVP("VENDOR_ID=%06x", ud->vendor_id);
|
||||||
|
|
|
@ -86,31 +86,26 @@ mmc_bus_uevent(struct device *dev, char **envp, int num_envp, char *buf,
|
||||||
{
|
{
|
||||||
struct mmc_card *card = dev_to_mmc_card(dev);
|
struct mmc_card *card = dev_to_mmc_card(dev);
|
||||||
char ccc[13];
|
char ccc[13];
|
||||||
int i = 0;
|
int retval = 0, i = 0, length = 0;
|
||||||
|
|
||||||
#define add_env(fmt,val) \
|
#define add_env(fmt,val) do { \
|
||||||
({ \
|
retval = add_uevent_var(envp, num_envp, &i, \
|
||||||
int len, ret = -ENOMEM; \
|
buf, buf_size, &length, \
|
||||||
if (i < num_envp) { \
|
fmt, val); \
|
||||||
envp[i++] = buf; \
|
if (retval) \
|
||||||
len = snprintf(buf, buf_size, fmt, val) + 1; \
|
return retval; \
|
||||||
buf_size -= len; \
|
} while (0);
|
||||||
buf += len; \
|
|
||||||
if (buf_size >= 0) \
|
|
||||||
ret = 0; \
|
|
||||||
} \
|
|
||||||
ret; \
|
|
||||||
})
|
|
||||||
|
|
||||||
for (i = 0; i < 12; i++)
|
for (i = 0; i < 12; i++)
|
||||||
ccc[i] = card->csd.cmdclass & (1 << i) ? '1' : '0';
|
ccc[i] = card->csd.cmdclass & (1 << i) ? '1' : '0';
|
||||||
ccc[12] = '\0';
|
ccc[12] = '\0';
|
||||||
|
|
||||||
i = 0;
|
|
||||||
add_env("MMC_CCC=%s", ccc);
|
add_env("MMC_CCC=%s", ccc);
|
||||||
add_env("MMC_MANFID=%06x", card->cid.manfid);
|
add_env("MMC_MANFID=%06x", card->cid.manfid);
|
||||||
add_env("MMC_NAME=%s", mmc_card_name(card));
|
add_env("MMC_NAME=%s", mmc_card_name(card));
|
||||||
add_env("MMC_OEMID=%04x", card->cid.oemid);
|
add_env("MMC_OEMID=%04x", card->cid.oemid);
|
||||||
|
#undef add_env
|
||||||
|
envp[i] = NULL;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -423,27 +423,25 @@ static int ap_uevent (struct device *dev, char **envp, int num_envp,
|
||||||
char *buffer, int buffer_size)
|
char *buffer, int buffer_size)
|
||||||
{
|
{
|
||||||
struct ap_device *ap_dev = to_ap_dev(dev);
|
struct ap_device *ap_dev = to_ap_dev(dev);
|
||||||
int length;
|
int retval = 0, length = 0, i = 0;
|
||||||
|
|
||||||
if (!ap_dev)
|
if (!ap_dev)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
/* Set up DEV_TYPE environment variable. */
|
/* Set up DEV_TYPE environment variable. */
|
||||||
envp[0] = buffer;
|
retval = add_uevent_var(envp, num_envp, &i,
|
||||||
length = scnprintf(buffer, buffer_size, "DEV_TYPE=%04X",
|
buffer, buffer_size, &length,
|
||||||
ap_dev->device_type);
|
"DEV_TYPE=%04X", ap_dev->device_type);
|
||||||
if (buffer_size - length <= 0)
|
if (retval)
|
||||||
return -ENOMEM;
|
return retval;
|
||||||
buffer += length;
|
|
||||||
buffer_size -= length;
|
|
||||||
/* Add MODALIAS= */
|
/* Add MODALIAS= */
|
||||||
envp[1] = buffer;
|
retval = add_uevent_var(envp, num_envp, &i,
|
||||||
length = scnprintf(buffer, buffer_size, "MODALIAS=ap:t%02X",
|
buffer, buffer_size, &length,
|
||||||
ap_dev->device_type);
|
"MODALIAS=ap:t%02X", ap_dev->device_type);
|
||||||
if (buffer_size - length <= 0)
|
|
||||||
return -ENOMEM;
|
envp[i] = NULL;
|
||||||
envp[2] = NULL;
|
return retval;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct bus_type ap_bus_type = {
|
static struct bus_type ap_bus_type = {
|
||||||
|
|
|
@ -412,31 +412,25 @@ static int netdev_uevent(struct device *d, char **envp,
|
||||||
int num_envp, char *buf, int size)
|
int num_envp, char *buf, int size)
|
||||||
{
|
{
|
||||||
struct net_device *dev = to_net_dev(d);
|
struct net_device *dev = to_net_dev(d);
|
||||||
int i = 0;
|
int retval, len = 0, i = 0;
|
||||||
int n;
|
|
||||||
|
|
||||||
/* pass interface to uevent. */
|
/* pass interface to uevent. */
|
||||||
envp[i++] = buf;
|
retval = add_uevent_var(envp, num_envp, &i,
|
||||||
n = snprintf(buf, size, "INTERFACE=%s", dev->name) + 1;
|
buf, size, &len,
|
||||||
buf += n;
|
"INTERFACE=%s", dev->name);
|
||||||
size -= n;
|
if (retval)
|
||||||
|
goto exit;
|
||||||
if ((size <= 0) || (i >= num_envp))
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
/* pass ifindex to uevent.
|
/* pass ifindex to uevent.
|
||||||
* ifindex is useful as it won't change (interface name may change)
|
* ifindex is useful as it won't change (interface name may change)
|
||||||
* and is what RtNetlink uses natively. */
|
* and is what RtNetlink uses natively. */
|
||||||
envp[i++] = buf;
|
retval = add_uevent_var(envp, num_envp, &i,
|
||||||
n = snprintf(buf, size, "IFINDEX=%d", dev->ifindex) + 1;
|
buf, size, &len,
|
||||||
buf += n;
|
"IFINDEX=%d", dev->ifindex);
|
||||||
size -= n;
|
|
||||||
|
|
||||||
if ((size <= 0) || (i >= num_envp))
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
|
exit:
|
||||||
envp[i] = NULL;
|
envp[i] = NULL;
|
||||||
return 0;
|
return retval;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -61,9 +61,9 @@ static int soundbus_uevent(struct device *dev, char **envp, int num_envp,
|
||||||
{
|
{
|
||||||
struct soundbus_dev * soundbus_dev;
|
struct soundbus_dev * soundbus_dev;
|
||||||
struct of_device * of;
|
struct of_device * of;
|
||||||
char *scratch, *compat, *compat2;
|
char *compat;
|
||||||
int i = 0;
|
int retval = 0, i = 0, length = 0;
|
||||||
int length, cplen, cplen2, seen = 0;
|
int cplen, seen = 0;
|
||||||
|
|
||||||
if (!dev)
|
if (!dev)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
@ -75,63 +75,47 @@ static int soundbus_uevent(struct device *dev, char **envp, int num_envp,
|
||||||
of = &soundbus_dev->ofdev;
|
of = &soundbus_dev->ofdev;
|
||||||
|
|
||||||
/* stuff we want to pass to /sbin/hotplug */
|
/* stuff we want to pass to /sbin/hotplug */
|
||||||
envp[i++] = scratch = buffer;
|
retval = add_uevent_var(envp, num_envp, &i,
|
||||||
length = scnprintf (scratch, buffer_size, "OF_NAME=%s", of->node->name);
|
buffer, buffer_size, &length,
|
||||||
++length;
|
"OF_NAME=%s", of->node->name);
|
||||||
buffer_size -= length;
|
if (retval)
|
||||||
if ((buffer_size <= 0) || (i >= num_envp))
|
return retval;
|
||||||
return -ENOMEM;
|
|
||||||
scratch += length;
|
|
||||||
|
|
||||||
envp[i++] = scratch;
|
retval = add_uevent_var(envp, num_envp, &i,
|
||||||
length = scnprintf (scratch, buffer_size, "OF_TYPE=%s", of->node->type);
|
buffer, buffer_size, &length,
|
||||||
++length;
|
"OF_TYPE=%s", of->node->type);
|
||||||
buffer_size -= length;
|
if (retval)
|
||||||
if ((buffer_size <= 0) || (i >= num_envp))
|
return retval;
|
||||||
return -ENOMEM;
|
|
||||||
scratch += length;
|
|
||||||
|
|
||||||
/* Since the compatible field can contain pretty much anything
|
/* Since the compatible field can contain pretty much anything
|
||||||
* it's not really legal to split it out with commas. We split it
|
* it's not really legal to split it out with commas. We split it
|
||||||
* up using a number of environment variables instead. */
|
* up using a number of environment variables instead. */
|
||||||
|
|
||||||
compat = (char *) get_property(of->node, "compatible", &cplen);
|
compat = (char *) get_property(of->node, "compatible", &cplen);
|
||||||
compat2 = compat;
|
|
||||||
cplen2= cplen;
|
|
||||||
while (compat && cplen > 0) {
|
while (compat && cplen > 0) {
|
||||||
envp[i++] = scratch;
|
int tmp = length;
|
||||||
length = scnprintf (scratch, buffer_size,
|
retval = add_uevent_var(envp, num_envp, &i,
|
||||||
|
buffer, buffer_size, &length,
|
||||||
"OF_COMPATIBLE_%d=%s", seen, compat);
|
"OF_COMPATIBLE_%d=%s", seen, compat);
|
||||||
++length;
|
if (retval)
|
||||||
buffer_size -= length;
|
return retval;
|
||||||
if ((buffer_size <= 0) || (i >= num_envp))
|
compat += length - tmp;
|
||||||
return -ENOMEM;
|
cplen -= length - tmp;
|
||||||
scratch += length;
|
seen += 1;
|
||||||
length = strlen (compat) + 1;
|
|
||||||
compat += length;
|
|
||||||
cplen -= length;
|
|
||||||
seen++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
envp[i++] = scratch;
|
retval = add_uevent_var(envp, num_envp, &i,
|
||||||
length = scnprintf (scratch, buffer_size, "OF_COMPATIBLE_N=%d", seen);
|
buffer, buffer_size, &length,
|
||||||
++length;
|
"OF_COMPATIBLE_N=%d", seen);
|
||||||
buffer_size -= length;
|
if (retval)
|
||||||
if ((buffer_size <= 0) || (i >= num_envp))
|
return retval;
|
||||||
return -ENOMEM;
|
retval = add_uevent_var(envp, num_envp, &i,
|
||||||
scratch += length;
|
buffer, buffer_size, &length,
|
||||||
|
"MODALIAS=%s", soundbus_dev->modalias);
|
||||||
envp[i++] = scratch;
|
|
||||||
length = scnprintf (scratch, buffer_size, "MODALIAS=%s",
|
|
||||||
soundbus_dev->modalias);
|
|
||||||
|
|
||||||
buffer_size -= length;
|
|
||||||
if ((buffer_size <= 0) || (i >= num_envp))
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
envp[i] = NULL;
|
envp[i] = NULL;
|
||||||
|
|
||||||
return 0;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int soundbus_device_remove(struct device *dev)
|
static int soundbus_device_remove(struct device *dev)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue