Module Name: src Committed By: jdolecek Date: Tue Apr 7 15:59:58 UTC 2020
Modified Files: src/sys/arch/xen/include: xenbus.h src/sys/arch/xen/xenbus: xenbus_probe.c xenbus_xs.c Log Message: 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 To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 src/sys/arch/xen/include/xenbus.h cvs rdiff -u -r1.45 -r1.46 src/sys/arch/xen/xenbus/xenbus_probe.c cvs rdiff -u -r1.24 -r1.25 src/sys/arch/xen/xenbus/xenbus_xs.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/xen/include/xenbus.h diff -u src/sys/arch/xen/include/xenbus.h:1.20 src/sys/arch/xen/include/xenbus.h:1.21 --- src/sys/arch/xen/include/xenbus.h:1.20 Tue Apr 7 15:40:14 2020 +++ src/sys/arch/xen/include/xenbus.h Tue Apr 7 15:59:57 2020 @@ -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 @@ struct xenbus_transaction; 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 *, Index: src/sys/arch/xen/xenbus/xenbus_probe.c diff -u src/sys/arch/xen/xenbus/xenbus_probe.c:1.45 src/sys/arch/xen/xenbus/xenbus_probe.c:1.46 --- src/sys/arch/xen/xenbus/xenbus_probe.c:1.45 Tue Apr 7 15:40:14 2020 +++ src/sys/arch/xen/xenbus/xenbus_probe.c Tue Apr 7 15:59:57 2020 @@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: xenbus_probe #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 @@ xenbus_probe_device_type(const char *pat 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 @@ xenbus_probe_device_type(const char *pat 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 @@ xenbus_probe_frontends(void) if (err) break; } - free(dir, M_DEVBUF); + xenbus_directory_free(dir_n, dir); return err; } @@ -542,10 +542,9 @@ xenbus_probe_backends(void) &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 @@ xenbus_probe_backends(void) 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; } Index: src/sys/arch/xen/xenbus/xenbus_xs.c diff -u src/sys/arch/xen/xenbus/xenbus_xs.c:1.24 src/sys/arch/xen/xenbus/xenbus_xs.c:1.25 --- src/sys/arch/xen/xenbus/xenbus_xs.c:1.24 Tue Apr 7 11:47:06 2020 +++ src/sys/arch/xen/xenbus/xenbus_xs.c Tue Apr 7 15:59:57 2020 @@ -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 @@ xenbus_directory(struct xenbus_transacti 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,