From nobody Thu Sep 26 09:16:36 2024 X-Original-To: dev-commits-src-all@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 4XDnz92m3lz5Wm1k; Thu, 26 Sep 2024 09:16:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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 "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XDnz90gD8z4441; Thu, 26 Sep 2024 09:16:37 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1727342197; 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; bh=Xtn26OwEtNQSuua9eqpToml74XFechz1MAO4K09O0G4=; b=p427LH0ekO4IFiLvSg3JcQNZbieuFhJRFVtu65EXqC8X0VJ3hhgTon6guwiNUVz4GADZ7U DWUdUPPRXh5oeqDUZCAjZALTmQimCK7rj96aXpuRChmbDc66I04WzPCpc40NAL03MiH46u gp2DmveMvXjuE5rz/PH9x5IbgNbQNaA7hq44a/XXZGgyaRpcAfy2uHUEPzwl4tCaQuba5A EbsK/xUwuH9dPDPzi6szPzF9VYG5HJ1OS/8s191PDK4XXKoMgev4IwZxCqB6QHiPBsh/9r ttqFO5robeurHxv7/UBrRxceCmRC9Dv1KLsXPU1h7kaIAD92o0NPwJxLVsz8cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1727342197; 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; bh=Xtn26OwEtNQSuua9eqpToml74XFechz1MAO4K09O0G4=; b=tC+D2K7aeGwdoJCCJl+A6kpaNucUcRNx4MPobPNpXkuqFW9NP3Wl+AIfuZ6Ytc24mUs9+p wzvNB04t7c8AjO65869wCB56udVRyWQxsgg5Nevmh2pspHYi9iacyU7fPqCVwi0KO5dZJV Hbjvs2NWh5hkjiNW2DkQrT1tfG6WTsPZQBXLU2Qs9hN4qOb/le2WAKFZ9ayonDET3ADPOn oKBwIMjFZSsdzZhJugFyQvXTHIQsIfBezNI3aA3r97of7w/5cwAEk2r9HVmU2mvLBvulgN mnrgQOR6f/LMWB3pZ3RrBGOvoAi29nPZnSjvahX6AfwVlqpTCsRWgJeqdxoOsg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1727342197; a=rsa-sha256; cv=none; b=Ed0ITR8s7huq3YJRMm+JRks09o+C16ToKMkclGDKx73IvLQu9EEAYtCG57wHWQYNsfzgqq Co/bTr7v9bVsWMgHhaoEgEdZtw8WKjKy9m8PybR601NAa4Ugq4CZ2yc6dIZvHmC25QndpB uU+G3jHVQ9b1xTHpv7tmEi8XL3Wu4a7WGLP4mSBGc1mKksHreAOb2/bzZoXD5/xrrcntwC 8bNZcKBW1wR2gRnXjFEKag/L9lswz7jpAiMH52Nu0QvIoDh8iQSb0Awbl32vegcqiHvJFS KPZRqebKKU1OFScwEa+kph8QLCt94eCdiKYgmO9ASYqkBBvnQnqWHrsrhQdIPA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4XDnz90HpxzrLV; Thu, 26 Sep 2024 09:16:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 48Q9GaGp077383; Thu, 26 Sep 2024 09:16:36 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 48Q9GaFt077380; Thu, 26 Sep 2024 09:16:36 GMT (envelope-from git) Date: Thu, 26 Sep 2024 09:16:36 GMT Message-Id: <202409260916.48Q9GaFt077380@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Tom Jones Subject: git: 99adbd1b3f3b - main - gpioc: Fix handling of priv data during open List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: thj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 99adbd1b3f3b2c198a8994c9681655978a7d9a1f Auto-Submitted: auto-generated The branch main has been updated by thj: URL: https://cgit.FreeBSD.org/src/commit/?id=99adbd1b3f3b2c198a8994c9681655978a7d9a1f commit 99adbd1b3f3b2c198a8994c9681655978a7d9a1f Author: Tom Jones AuthorDate: 2024-09-26 09:13:41 +0000 Commit: Tom Jones CommitDate: 2024-09-26 09:16:17 +0000 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 --- sys/dev/gpio/gpioc.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/sys/dev/gpio/gpioc.c b/sys/dev/gpio/gpioc.c index 4ebf958d6974..b9d95338e211 100644 --- a/sys/dev/gpio/gpioc.c +++ b/sys/dev/gpio/gpioc.c @@ -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