1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-11-24 07:40:52 +00:00

gpioc: Fix handling of priv data during open

Fix the ordering of priv data creation with setting priv data. This
handles failure better and resolves a panic when repeatedly running
tools/tools/gpioevents.

Explicitly initialise more fields in priv data while we are here.

Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D46568
This commit is contained in:
Tom Jones 2024-09-26 10:13:41 +01:00
parent 78e1b031d2
commit 99adbd1b3f

View File

@ -677,19 +677,18 @@ static int
gpioc_open(struct cdev *dev, int oflags, int devtype, struct thread *td)
{
struct gpioc_cdevpriv *priv;
int err;
int err = 0;
priv = malloc(sizeof(*priv), M_GPIOC, M_WAITOK | M_ZERO);
priv->sc = dev->si_drv1;
priv->report_option = GPIO_EVENT_REPORT_DETAIL;
err = devfs_set_cdevpriv(priv, gpioc_cdevpriv_dtor);
if (err != 0) {
gpioc_cdevpriv_dtor(priv);
return (err);
}
mtx_init(&priv->mtx, "gpioc priv", NULL, MTX_DEF);
knlist_init_mtx(&priv->selinfo.si_note, &priv->mtx);
priv->async = false;
priv->report_option = GPIO_EVENT_REPORT_DETAIL;
priv->sigio = NULL;
/*
* Allocate a circular buffer for events. The scheme we use for summary
* reporting assumes there will always be a pair of events available to
@ -701,7 +700,13 @@ gpioc_open(struct cdev *dev, int oflags, int devtype, struct thread *td)
priv->events = malloc(priv->numevents * sizeof(struct gpio_event_detail),
M_GPIOC, M_WAITOK | M_ZERO);
return (0);
priv->evidx_head = priv->evidx_tail = 0;
SLIST_INIT(&priv->pins);
err = devfs_set_cdevpriv(priv, gpioc_cdevpriv_dtor);
if (err != 0)
gpioc_cdevpriv_dtor(priv);
return (err);
}
static int