# HG changeset patch
# User vhanquez@xxxxxxxxxxxxxxxxxxxxxxx
# Node ID 4d729134a0a4e522defab916ff6d068e5e57eb38
# Parent c259492dfb43d83fdb74bb4f4fd8be6ccfa926ee
remove duplicate code to allocate a string ala printf (using kasprintf)
Signed-off-by: Vincent Hanquez <vincent@xxxxxxxxxxxxx>
diff -r c259492dfb43 -r 4d729134a0a4
linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_client.c
--- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_client.c Wed Dec 21
13:29:23 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_client.c Wed Dec 21
11:14:37 2005
@@ -63,6 +63,7 @@
}
EXPORT_SYMBOL(xenbus_watch_path);
+extern char *kasprintf(const char *fmt, ...);
int xenbus_watch_path2(struct xenbus_device *dev, const char *path,
const char *path2, struct xenbus_watch *watch,
@@ -70,16 +71,11 @@
const char **, unsigned int))
{
int err;
- char *state =
- kmalloc(strlen(path) + 1 + strlen(path2) + 1, GFP_KERNEL);
+ char *state = kasprintf("%s/%s", path, path2);
if (!state) {
xenbus_dev_fatal(dev, -ENOMEM, "allocating path for watch");
return -ENOMEM;
}
- strcpy(state, path);
- strcat(state, "/");
- strcat(state, path2);
-
err = xenbus_watch_path(dev, state, watch, callback);
if (err) {
@@ -126,16 +122,7 @@
*/
static char *error_path(struct xenbus_device *dev)
{
- char *path_buffer = kmalloc(strlen("error/") + strlen(dev->nodename) +
- 1, GFP_KERNEL);
- if (path_buffer == NULL) {
- return NULL;
- }
-
- strcpy(path_buffer, "error/");
- strcpy(path_buffer + strlen("error/"), dev->nodename);
-
- return path_buffer;
+ return kasprintf("error/%s", dev->nodename);
}
diff -r c259492dfb43 -r 4d729134a0a4
linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c
--- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c Wed Dec 21
13:29:23 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c Wed Dec 21
11:14:37 2005
@@ -505,7 +505,7 @@
}
/* Simplified asprintf. */
-static char *kasprintf(const char *fmt, ...)
+char *kasprintf(const char *fmt, ...)
{
va_list ap;
unsigned int len;
diff -r c259492dfb43 -r 4d729134a0a4
linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c
--- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c Wed Dec 21
13:29:23 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c Wed Dec 21
11:14:37 2005
@@ -276,18 +276,11 @@
{
char *buffer;
- buffer = kmalloc(strlen(dir) + strlen("/") + strlen(name) + 1,
- GFP_KERNEL);
- if (buffer == NULL)
- return ERR_PTR(-ENOMEM);
-
- strcpy(buffer, dir);
- if (!streq(name, "")) {
- strcat(buffer, "/");
- strcat(buffer, name);
- }
-
- return buffer;
+ if (strlen(name) == 0)
+ buffer = kasprintf("%s", dir);
+ else
+ buffer = kasprintf("%s/%s", dir, name);
+ return (!buffer) ? ERR_PTR(-ENOMEM) : buffer;
}
static char **split(char *strings, unsigned int len, unsigned int *num)
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|