[S390] cio: Use add_uevent_var.

Convert ccw_uevent to use add_uevent_var and adapt snprint_alias.

Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
This commit is contained in:
Cornelia Huck 2007-04-27 16:01:32 +02:00 committed by Martin Schwidefsky
parent e5854a5839
commit cfbe9bb2fb

View File

@ -56,13 +56,12 @@ ccw_bus_match (struct device * dev, struct device_driver * drv)
/* Store modalias string delimited by prefix/suffix string into buffer with /* Store modalias string delimited by prefix/suffix string into buffer with
* specified size. Return length of resulting string (excluding trailing '\0') * specified size. Return length of resulting string (excluding trailing '\0')
* even if string doesn't fit buffer (snprintf semantics). */ * even if string doesn't fit buffer (snprintf semantics). */
static int snprint_alias(char *buf, size_t size, const char *prefix, static int snprint_alias(char *buf, size_t size,
struct ccw_device_id *id, const char *suffix) struct ccw_device_id *id, const char *suffix)
{ {
int len; int len;
len = snprintf(buf, size, "%sccw:t%04Xm%02X", prefix, id->cu_type, len = snprintf(buf, size, "ccw:t%04Xm%02X", id->cu_type, id->cu_model);
id->cu_model);
if (len > size) if (len > size)
return len; return len;
buf += len; buf += len;
@ -85,53 +84,40 @@ static int ccw_uevent(struct device *dev, char **envp, int num_envp,
struct ccw_device *cdev = to_ccwdev(dev); struct ccw_device *cdev = to_ccwdev(dev);
struct ccw_device_id *id = &(cdev->id); struct ccw_device_id *id = &(cdev->id);
int i = 0; int i = 0;
int len; int len = 0;
int ret;
char modalias_buf[30];
/* CU_TYPE= */ /* CU_TYPE= */
len = snprintf(buffer, buffer_size, "CU_TYPE=%04X", id->cu_type) + 1; ret = add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &len,
if (len > buffer_size || i >= num_envp) "CU_TYPE=%04X", id->cu_type);
return -ENOMEM; if (ret)
envp[i++] = buffer; return ret;
buffer += len;
buffer_size -= len;
/* CU_MODEL= */ /* CU_MODEL= */
len = snprintf(buffer, buffer_size, "CU_MODEL=%02X", id->cu_model) + 1; ret = add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &len,
if (len > buffer_size || i >= num_envp) "CU_MODEL=%02X", id->cu_model);
return -ENOMEM; if (ret)
envp[i++] = buffer; return ret;
buffer += len;
buffer_size -= len;
/* The next two can be zero, that's ok for us */ /* The next two can be zero, that's ok for us */
/* DEV_TYPE= */ /* DEV_TYPE= */
len = snprintf(buffer, buffer_size, "DEV_TYPE=%04X", id->dev_type) + 1; ret = add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &len,
if (len > buffer_size || i >= num_envp) "DEV_TYPE=%04X", id->dev_type);
return -ENOMEM; if (ret)
envp[i++] = buffer; return ret;
buffer += len;
buffer_size -= len;
/* DEV_MODEL= */ /* DEV_MODEL= */
len = snprintf(buffer, buffer_size, "DEV_MODEL=%02X", ret = add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &len,
(unsigned char) id->dev_model) + 1; "DEV_MODEL=%02X", id->dev_model);
if (len > buffer_size || i >= num_envp) if (ret)
return -ENOMEM; return ret;
envp[i++] = buffer;
buffer += len;
buffer_size -= len;
/* MODALIAS= */ /* MODALIAS= */
len = snprint_alias(buffer, buffer_size, "MODALIAS=", id, "") + 1; snprint_alias(modalias_buf, sizeof(modalias_buf), id, "");
if (len > buffer_size || i >= num_envp) ret = add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &len,
return -ENOMEM; "MODALIAS=%s", modalias_buf);
envp[i++] = buffer; return ret;
buffer += len;
buffer_size -= len;
envp[i] = NULL;
return 0;
} }
struct bus_type ccw_bus_type; struct bus_type ccw_bus_type;
@ -280,7 +266,7 @@ modalias_show (struct device *dev, struct device_attribute *attr, char *buf)
struct ccw_device_id *id = &(cdev->id); struct ccw_device_id *id = &(cdev->id);
int len; int len;
len = snprint_alias(buf, PAGE_SIZE, "", id, "\n") + 1; len = snprint_alias(buf, PAGE_SIZE, id, "\n") + 1;
return len > PAGE_SIZE ? PAGE_SIZE : len; return len > PAGE_SIZE ? PAGE_SIZE : len;
} }