WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] remove duplicate code to allocate a string ala printf (u

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] remove duplicate code to allocate a string ala printf (using kasprintf)
From: Xen patchbot -unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Wed, 21 Dec 2005 18:56:06 +0000
Delivery-date: Wed, 21 Dec 2005 18:59:06 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# 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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] remove duplicate code to allocate a string ala printf (using kasprintf), Xen patchbot -unstable <=