Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/xen add a small wrapper xenbus_directory_free() to ...



details:   https://anonhg.NetBSD.org/src/rev/c113c7a7d5ff
branches:  trunk
changeset: 970946:c113c7a7d5ff
user:      jdolecek <jdolecek%NetBSD.org@localhost>
date:      Tue Apr 07 15:59:57 2020 +0000

description:
add a small wrapper xenbus_directory_free() to free result of
xenbus_directory(), so that caller doesn't need to be aware how the memory
was allocated

diffstat:

 sys/arch/xen/include/xenbus.h      |   3 ++-
 sys/arch/xen/xenbus/xenbus_probe.c |  27 ++++++++++++++-------------
 sys/arch/xen/xenbus/xenbus_xs.c    |  10 ++++++++--
 3 files changed, 24 insertions(+), 16 deletions(-)

diffs (140 lines):

diff -r d5731bd2cd71 -r c113c7a7d5ff sys/arch/xen/include/xenbus.h
--- a/sys/arch/xen/include/xenbus.h     Tue Apr 07 15:43:42 2020 +0000
+++ b/sys/arch/xen/include/xenbus.h     Tue Apr 07 15:59:57 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: xenbus.h,v 1.20 2020/04/07 15:40:14 jdolecek Exp $ */
+/* $NetBSD: xenbus.h,v 1.21 2020/04/07 15:59:57 jdolecek Exp $ */
 /******************************************************************************
  * xenbus.h
  *
@@ -120,6 +120,7 @@
 int xenbus_directory(struct xenbus_transaction *t,
                        const char *dir, const char *node, unsigned int *num,
                        char ***);
+void xenbus_directory_free(unsigned int, char **);
 int xenbus_read(struct xenbus_transaction *,
                  const char *, const char *, char *, size_t);
 int xenbus_read_ul(struct xenbus_transaction *,
diff -r d5731bd2cd71 -r c113c7a7d5ff sys/arch/xen/xenbus/xenbus_probe.c
--- a/sys/arch/xen/xenbus/xenbus_probe.c        Tue Apr 07 15:43:42 2020 +0000
+++ b/sys/arch/xen/xenbus/xenbus_probe.c        Tue Apr 07 15:59:57 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: xenbus_probe.c,v 1.45 2020/04/07 15:40:14 jdolecek Exp $ */
+/* $NetBSD: xenbus_probe.c,v 1.46 2020/04/07 15:59:57 jdolecek Exp $ */
 /******************************************************************************
  * Talks to Xen Store to figure out what devices we have.
  *
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xenbus_probe.c,v 1.45 2020/04/07 15:40:14 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xenbus_probe.c,v 1.46 2020/04/07 15:59:57 jdolecek Exp $");
 
 #if 0
 #define DPRINTK(fmt, args...) \
@@ -41,7 +41,6 @@
 #include <sys/types.h>
 #include <sys/null.h>
 #include <sys/errno.h>
-#include <sys/malloc.h>
 #include <sys/kmem.h>
 #include <sys/systm.h>
 #include <sys/param.h>
@@ -316,16 +315,17 @@
        size_t lookup_sz = 0;
        unsigned long state;
        char **dir;
-       unsigned int dir_n = 0;
+       unsigned int orig_dir_n = 0, dir_n;
        struct xenbus_device *xbusd;
        struct xenbusdev_attach_args xa;
        char *ep;
 
        DPRINTK("probe %s type %s", path, type);
-       err = xenbus_directory(NULL, path, "", &dir_n, &dir);
+       err = xenbus_directory(NULL, path, "", &orig_dir_n, &dir);
        DPRINTK("directory err %d dir_n %d", err, dir_n);
        if (err)
                return err;
+       dir_n = orig_dir_n;
 
        /* Only sort frontend devices i.e. create == NULL*/
        if (dir_n > 1 && create == NULL) {
@@ -456,7 +456,7 @@
                    xbusd, xbusd_entries);
                watch_otherend(xbusd);
        }
-       free(dir, M_DEVBUF);
+       xenbus_directory_free(orig_dir_n, dir);
        if (lookup)
                kmem_free(lookup, lookup_sz);
        
@@ -511,7 +511,7 @@
                if (err)
                        break;
        }
-       free(dir, M_DEVBUF);
+       xenbus_directory_free(dir_n, dir);
        return err;
 }
 
@@ -542,10 +542,9 @@
                    &dirid_n, &dirid);
                DPRINTK("directory backend/%s err %d dirid_n %d",
                    dirt[type], err, dirid_n);
-               if (err) {
-                       free(dirt, M_DEVBUF); /* to be checked */
-                       return err;
-               }
+               if (err)
+                       goto out;
+
                for (id = 0; id < dirid_n; id++) {
                        snprintf(path, sizeof(path), "backend/%s/%s",
                            dirt[type], dirid[id]);
@@ -554,9 +553,11 @@
                        if (err)
                                break;
                }
-               free(dirid, M_DEVBUF);
+               xenbus_directory_free(dirid_n, dirid);
        }
-       free(dirt, M_DEVBUF);
+
+out:
+       xenbus_directory_free(dirt_n, dirt);
        return err;
 }
 
diff -r d5731bd2cd71 -r c113c7a7d5ff sys/arch/xen/xenbus/xenbus_xs.c
--- a/sys/arch/xen/xenbus/xenbus_xs.c   Tue Apr 07 15:43:42 2020 +0000
+++ b/sys/arch/xen/xenbus/xenbus_xs.c   Tue Apr 07 15:59:57 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: xenbus_xs.c,v 1.24 2020/04/07 11:47:06 jdolecek Exp $ */
+/* $NetBSD: xenbus_xs.c,v 1.25 2020/04/07 15:59:57 jdolecek Exp $ */
 /******************************************************************************
  * xenbus_xs.c
  *
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xenbus_xs.c,v 1.24 2020/04/07 11:47:06 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xenbus_xs.c,v 1.25 2020/04/07 15:59:57 jdolecek Exp $");
 
 #if 0
 #define DPRINTK(fmt, args...) \
@@ -338,6 +338,12 @@
        return 0;
 }
 
+void
+xenbus_directory_free(unsigned int num, char **dir)
+{
+       free(dir, M_DEVBUF);
+}
+
 /* Check if a path exists. Return 1 if it does. */
 int
 xenbus_exists(struct xenbus_transaction *t,



Home | Main Index | Thread Index | Old Index