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
This commit is contained in:
jdolecek 2020-04-07 15:59:57 +00:00
parent 1c0b49f5ee
commit 125dad3d64
3 changed files with 24 additions and 16 deletions

View File

@ -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 *,

View File

@ -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.c,v 1.45 2020/04/07 15:40:14 jdolecek E
#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 *path, const char *type,
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 *path, const char *type,
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;
}

View File

@ -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_transaction *t,
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,