Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 27 Aug 2025 21:57:09 GMT
From:      Ahmad Khalifa <vexeduxr@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 59e74fdfafcf - main - gpioc: cleanup if pin allocation fails
Message-ID:  <202508272157.57RLv9RZ026456@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by vexeduxr:

URL: https://cgit.FreeBSD.org/src/commit/?id=59e74fdfafcff3310c316dcec3bccfd04f8722b4

commit 59e74fdfafcff3310c316dcec3bccfd04f8722b4
Author:     Ahmad Khalifa <vexeduxr@FreeBSD.org>
AuthorDate: 2025-08-27 21:25:10 +0000
Commit:     Ahmad Khalifa <vexeduxr@FreeBSD.org>
CommitDate: 2025-08-27 21:38:32 +0000

    gpioc: cleanup if pin allocation fails
    
    gpioc normally depends on gpioc_cdevpriv_dtor to call
    gpioc_release_pin_intr when it's done with a pin. However, if
    gpioc_allocate_pin_intr fails, the pin is never added to the linked list
    which the destructor loops over to free the pins. Make it so
    gpioc_allocate_pin_intr cleans up after itself if it fails.
    
    Reported by:    Evgenii Ivanov <devivanov@proton.me>
    Approved by:    imp (mentor, implicit)
    Differential Revision:  https://reviews.freebsd.org/D51998
---
 sys/dev/gpio/gpioc.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/sys/dev/gpio/gpioc.c b/sys/dev/gpio/gpioc.c
index 87fed38ebe3e..77aaf2cb5447 100644
--- a/sys/dev/gpio/gpioc.c
+++ b/sys/dev/gpio/gpioc.c
@@ -208,8 +208,11 @@ gpioc_allocate_pin_intr(struct gpioc_pin_intr *intr_conf, uint32_t flags)
 	err = bus_setup_intr(intr_conf->pin->dev, intr_conf->intr_res,
 	    INTR_TYPE_MISC | INTR_MPSAFE, NULL, gpioc_interrupt_handler,
 	    intr_conf, &intr_conf->intr_cookie);
-	if (err != 0)
+	if (err != 0) {
+		bus_release_resource(sc->sc_dev, intr_conf->intr_res);
+		intr_conf->intr_res = NULL;
 		goto error_exit;
+	}
 
 	intr_conf->pin->flags = flags;
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202508272157.57RLv9RZ026456>