ia64/xen-unstable

changeset 8425:4d729134a0a4

remove duplicate code to allocate a string ala printf (using kasprintf)

Signed-off-by: Vincent Hanquez <vincent@xensource.com>
author vhanquez@kneesa.uk.xensource.com
date Wed Dec 21 11:14:37 2005 +0000 (2005-12-21)
parents c259492dfb43
children f2a08a5a807a
files linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_client.c linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_client.c	Wed Dec 21 14:29:23 2005 +0100
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_client.c	Wed Dec 21 11:14:37 2005 +0000
     1.3 @@ -63,6 +63,7 @@ int xenbus_watch_path(struct xenbus_devi
     1.4  }
     1.5  EXPORT_SYMBOL(xenbus_watch_path);
     1.6  
     1.7 +extern char *kasprintf(const char *fmt, ...);
     1.8  
     1.9  int xenbus_watch_path2(struct xenbus_device *dev, const char *path,
    1.10  		       const char *path2, struct xenbus_watch *watch, 
    1.11 @@ -70,16 +71,11 @@ int xenbus_watch_path2(struct xenbus_dev
    1.12  					const char **, unsigned int))
    1.13  {
    1.14  	int err;
    1.15 -	char *state =
    1.16 -		kmalloc(strlen(path) + 1 + strlen(path2) + 1, GFP_KERNEL);
    1.17 +	char *state = kasprintf("%s/%s", path, path2);
    1.18  	if (!state) {
    1.19  		xenbus_dev_fatal(dev, -ENOMEM, "allocating path for watch");
    1.20  		return -ENOMEM;
    1.21  	}
    1.22 -	strcpy(state, path);
    1.23 -	strcat(state, "/");
    1.24 -	strcat(state, path2);
    1.25 -
    1.26  	err = xenbus_watch_path(dev, state, watch, callback);
    1.27  
    1.28  	if (err) {
    1.29 @@ -126,16 +122,7 @@ EXPORT_SYMBOL(xenbus_switch_state);
    1.30   */
    1.31  static char *error_path(struct xenbus_device *dev)
    1.32  {
    1.33 -	char *path_buffer = kmalloc(strlen("error/") + strlen(dev->nodename) +
    1.34 -				    1, GFP_KERNEL);
    1.35 -	if (path_buffer == NULL) {
    1.36 -		return NULL;
    1.37 -	}
    1.38 -
    1.39 -	strcpy(path_buffer, "error/");
    1.40 -	strcpy(path_buffer + strlen("error/"), dev->nodename);
    1.41 -
    1.42 -	return path_buffer;
    1.43 +	return kasprintf("error/%s", dev->nodename);
    1.44  }
    1.45  
    1.46  
     2.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c	Wed Dec 21 14:29:23 2005 +0100
     2.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c	Wed Dec 21 11:14:37 2005 +0000
     2.3 @@ -505,7 +505,7 @@ static void xenbus_dev_release(struct de
     2.4  }
     2.5  
     2.6  /* Simplified asprintf. */
     2.7 -static char *kasprintf(const char *fmt, ...)
     2.8 +char *kasprintf(const char *fmt, ...)
     2.9  {
    2.10  	va_list ap;
    2.11  	unsigned int len;
     3.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c	Wed Dec 21 14:29:23 2005 +0100
     3.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c	Wed Dec 21 11:14:37 2005 +0000
     3.3 @@ -276,18 +276,11 @@ static char *join(const char *dir, const
     3.4  {
     3.5  	char *buffer;
     3.6  
     3.7 -	buffer = kmalloc(strlen(dir) + strlen("/") + strlen(name) + 1,
     3.8 -			 GFP_KERNEL);
     3.9 -	if (buffer == NULL)
    3.10 -		return ERR_PTR(-ENOMEM);
    3.11 -
    3.12 -	strcpy(buffer, dir);
    3.13 -	if (!streq(name, "")) {
    3.14 -		strcat(buffer, "/");
    3.15 -		strcat(buffer, name);
    3.16 -	}
    3.17 -
    3.18 -	return buffer;
    3.19 +	if (strlen(name) == 0)
    3.20 +		buffer = kasprintf("%s", dir);
    3.21 +	else
    3.22 +		buffer = kasprintf("%s/%s", dir, name);
    3.23 +	return (!buffer) ? ERR_PTR(-ENOMEM) : buffer;
    3.24  }
    3.25  
    3.26  static char **split(char *strings, unsigned int len, unsigned int *num)