From nobody Mon Feb 23 16:06:43 2026 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4fKQhh5vHFz6TgQk; Mon, 23 Feb 2026 16:06:44 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [IPv6:2610:1c1:1:606c::24b:4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R13" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4fKQhh3zjJz3lZW; Mon, 23 Feb 2026 16:06:44 +0000 (UTC) (envelope-from jhb@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1771862804; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TyRd5L2o4tj3jxwfr8/jrFA8RbrNkW/1AGN20VbZ/rM=; b=OshlzxYR6lRNSustA+vPIXbb6gcQAUGvIl+dpMlpzq1zO34jNaJV4v4mMW3FNOabyHY/wl 3W8/7Ru7c22LeipfCsvHpzlvAq1hdrN6MIXPwe9lcZU3i58u//Hm7mlMa6x0JYV7LY6uff DzCLpbOYVTlXy9mweGOP21P3YoBgPKsdIAp3zllxZMgGvYVf96ODYbCUcwoTN2Y8TiLdTz ITTWe2ebJYxbMqIJiJWYOoBYBNEH3+UEsIJKmFQeN/QsfaFuXSQUMaghSgimueRCsiZhTx 0qaSTecKATfvQAtif9Ov0quTfRrhMWHtj+cKZb0Nl3jvKEx88EuYdAHZXr5Tpg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1771862804; a=rsa-sha256; cv=none; b=h0NelkRcIll1G3JVWo9G2z6tpC66Py3V/GoXte3ctu0dZ9cmOgs+zC9CR+1Ti5P3ZYfgLP 4jyTb8krjBSzM14J9891Vjt0AM2fXIEDU2jILkBgyyKWVBncKgWIsx6SYoTinqcUIngygx XWm7NSYMZEe0i0DgKR6cu2Pn9NUnSfczDCGSbixlYQIsn756kJhBPHvDQX4pYAVKiEH/T8 x5dAwEknBjfgsiRwC0Q4nOajqUUYylQr2/aCzbq9h4wTHnB5MmgHWj3NKsplcMcMXaiIs8 OUh91Ga87bawARO+61cS7tvmX1Xq3yqmnd+sEgbRNHmA1oZuJhAIgqAKVbCXew== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1771862804; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TyRd5L2o4tj3jxwfr8/jrFA8RbrNkW/1AGN20VbZ/rM=; b=WCTFF/+TbXYC0seIIWI6CB/a4HmL89Ds5cjPOwE9WEttdyq7SiYJcwQycwnKAftY4i4BBh ozuTjq62U5ZnH80Tv22iFtqo0haX8d32BqXFGVNOsMyVM+j28JC93rvpyLbYmC2Q5Wulh4 vjgdP0MYW8FPMSj4yvQiKX5AXvYXZ0FYwKllOWEH5la2V/pOUHYeJWfRuQzyX38QiuShkc oUj1qnnBeOog0KCVKOb634LZOMgyTIlrnOUSLmA6zZYHJmsAkQX5V/iFnzvT8kwDK7HM4Q 86JvhwgaDi6IuwYi+99YScksm/UxeVN3N4TCYct9nr2uF+IYk41aU1doFayDSw== Received: from [IPV6:2601:5c0:4202:5670:dd0e:5a2:6441:fcd5] (unknown [IPv6:2601:5c0:4202:5670:dd0e:5a2:6441:fcd5]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: jhb) by smtp.freebsd.org (Postfix) with ESMTPSA id 4fKQhh1tdqz3kG; Mon, 23 Feb 2026 16:06:44 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Message-ID: <3c07e539-5024-4462-a085-34fc958aeae6@FreeBSD.org> Date: Mon, 23 Feb 2026 11:06:43 -0500 List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: git: eda36ae09dd1 - main - asmc: resource cleanup simplifications Content-Language: en-US To: Enji Cooper , src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org References: <699a632b.4690e.2fab15e8@gitrepo.freebsd.org> From: John Baldwin In-Reply-To: <699a632b.4690e.2fab15e8@gitrepo.freebsd.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2/21/26 21:00, Enji Cooper wrote: > The branch main has been updated by ngie: > > URL: https://cgit.FreeBSD.org/src/commit/?id=eda36ae09dd1fab78bd377739fc5d6c65c61f5d7 > > commit eda36ae09dd1fab78bd377739fc5d6c65c61f5d7 > Author: Enji Cooper > AuthorDate: 2026-01-30 06:55:08 +0000 > Commit: Enji Cooper > CommitDate: 2026-02-22 01:59:06 +0000 > > asmc: resource cleanup simplifications > > This change makes `asmc_detach(..)` reentrant by setting freed resources > to known invalid values when done, and makes `asmc_attach(..)` call > `asmc_detach(..)` instead of attempting to the semi-equivalent way of > cleaning up the driver resources allocated in `asmc_detach(..)`. > > MFC after: 1 week > Differential Revision: https://reviews.freebsd.org/D55413 > --- > sys/dev/asmc/asmc.c | 33 +++++++++++++++++++-------------- > 1 file changed, 19 insertions(+), 14 deletions(-) > > diff --git a/sys/dev/asmc/asmc.c b/sys/dev/asmc/asmc.c > index bff214c084c5..084b57331dd9 100644 > --- a/sys/dev/asmc/asmc.c > +++ b/sys/dev/asmc/asmc.c > @@ -795,25 +795,21 @@ asmc_attach(device_t dev) > if (sc->sc_irq == NULL) { > device_printf(dev, "unable to allocate IRQ resource\n"); > ret = ENXIO; > - goto err2; > + goto err; > } > > ret = bus_setup_intr(dev, sc->sc_irq, INTR_TYPE_MISC | INTR_MPSAFE, > asmc_sms_intrfast, NULL, dev, &sc->sc_cookie); > if (ret) { > device_printf(dev, "unable to setup SMS IRQ\n"); > - goto err1; > + goto err; > } > + > nosms: > return (0); > -err1: > - bus_release_resource(dev, SYS_RES_IRQ, sc->sc_rid_irq, sc->sc_irq); > -err2: > - bus_release_resource(dev, SYS_RES_IOPORT, sc->sc_rid_port, > - sc->sc_ioport); > - mtx_destroy(&sc->sc_mtx); > - if (sc->sc_sms_tq) > - taskqueue_free(sc->sc_sms_tq); > + > +err: > + asmc_detach(dev); This cleanup is good. > return (ret); > } > @@ -826,16 +822,25 @@ asmc_detach(device_t dev) > if (sc->sc_sms_tq) { > taskqueue_drain(sc->sc_sms_tq, &sc->sc_sms_task); > taskqueue_free(sc->sc_sms_tq); > + sc->sc_sms_tq = NULL; Does this actually matter? That is, I don't think there is any reason for asmc_detach to be reentrant. New-bus (specifically device_attach()) does not invoke DEVICE_DETACH if DEVICE_ATTACH fails. Instead, DEVICE_ATTACH routines are expected to fully cleanup on failure. The changes to be reentrant here don't hurt, but they generally just add clutter. > } > - if (sc->sc_cookie) > + if (sc->sc_cookie) { > bus_teardown_intr(dev, sc->sc_irq, sc->sc_cookie); > - if (sc->sc_irq) > + sc->sc_cookie = NULL; > + } > + if (sc->sc_irq) { > bus_release_resource(dev, SYS_RES_IRQ, sc->sc_rid_irq, > sc->sc_irq); > - if (sc->sc_ioport) > + sc->sc_irq = NULL; > + } > + if (sc->sc_ioport) { > bus_release_resource(dev, SYS_RES_IOPORT, sc->sc_rid_port, > sc->sc_ioport); > - mtx_destroy(&sc->sc_mtx); > + sc->sc_ioport = NULL; > + } > + if (mtx_initialized(&sc->sc_mtx)) { Please do not use this. Code should know if the mutex is initialized or not. That is, always initalize the mutex in attach before any failures that could enter this path. > + mtx_destroy(&sc->sc_mtx); > + } -- John Baldwin