From nobody Thu Feb 12 23:04:50 2026 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4BF114F10F for ; Fri, 3 Jan 2025 03:04:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735873456; cv=none; b=ON9o3LuEhtBeZULnZOzC3WZGJY6hUNDr9QKeHwXIAsTz8TEhAertlg8ds4zgKuSMj+LPb6FLVPKN9sEbQrpoLBJUBlbtMB9wzkNaiLkoni6ooRHDIw1vX1CwadM3dRtia851tXZgmGtcdcdlKu7D1i02yxPTyuvYzTb/RbIaB2s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735873456; c=relaxed/simple; bh=HO08RPGJzed4ppqZ+jQm2FIefTr2FHu7Tv13x0myX08=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ADUTptx4QhWKSaN27qFrSIQkHpjNh9tf0+rvmCNVJ1fZZfm+P28lPoBU1mkIr1EKGxVVtBnMehM2aDp23YGaD4W32CeqyMrBuCaItKsujO9UadI+5MYQkT2ICphhtH+wxmlpSENWV6gSnHiWw+HoYcQedDVMDNlDAlmF3pUyrR0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b=GLFN9/qN; arc=none smtp.client-ip=185.125.188.123 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="GLFN9/qN" Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 1BAA140FAA for ; Fri, 3 Jan 2025 03:04:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1735873453; bh=cksCAqWYBujQdwWe5V+2vXqBxqUQWT0G6DdOeqkhr9I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GLFN9/qNHUFeUq9D3fSckxDWCb8jr8Pi8Lf+Qm+mpDfVSSpAuqqOLh176MQWGtQ3z VBPX3ictp1ShjiB5/rTDyyAf5SBQZhptH9oMyYguM3GXwMIH6hsDjxx8p/N38+nNAW uN3q3tId0jb5fI01GgYfQsdiiYD1A+mwqjwWAXTOn89VwNeNo7cJOGE6LQib52GWup k9O6VpcdRzkwFyUn6Ne/QQQsJ4vX/SBR6ib4hjd6o0bHWld9colFV+uoT8/CmsBNnw 1aIgmgLtQXrfcXR8S2Ybm5SNyqOJaTrjFyvHMcB8eq10aZoFEecaqNZkGslbSs2muY WzAa+5vv4kA9Q== Received: by mail-pl1-f197.google.com with SMTP id d9443c01a7336-2165433e229so164523115ad.1 for ; Thu, 02 Jan 2025 19:04:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735873452; x=1736478252; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cksCAqWYBujQdwWe5V+2vXqBxqUQWT0G6DdOeqkhr9I=; b=VgjhGwUHMkd8ZNv+7LpQXBvSmKtH7Lm02meHdaNLiHSCqizUSVDHaEvRZsyUn+Jmdj ylejpVZDW6CS0DxSkWcc6qG88difxKINZx33ybZIZS9xn3M1KZP39mP/c4/1CkvGNxJ0 PZZhBif7/tQzQODdeUh/iln3eB66/dAIvs9X0JYVjQ2XeiayVyV56oykXr1f8+Id2j/q 0cZPpt1mlVoMKvay6bT1EerI7TjtOqAaAZwf5wjYzQNgTw6j4N+2zOgHTFGI30kXrrKc lKRcq1SFrLsXaHfEKSIGVuSiiqVOFrJWtEVnu4sLiLeiYcwRvug61/QC5jJtl5vt7tGZ kzcw== X-Forwarded-Encrypted: i=1; AJvYcCU/186v8lwP+7FCwcNFwyS/v+eAMEvev1D5MJT4J+snNrpBJm8MnWGMqogBkfvOuk7YFNGZ3SG5NLjTk/s=@vger.kernel.org X-Gm-Message-State: AOJu0YyR3vW6KoQg5VpluDTuC+DVX8ccpazB5IyWM+yiDsGaNYNeMDyz ZUaWlcy4y0HwlXmzGA246t8xB+Nhbva96EK1hKsm0eblvqv1J9OqB6n5icaizFJKPC62SuOU6zp veuyy5sRkKjr/JvN86/JsW6k2Vx3t+hTrBf0+W0XZYE1fg/IkZWebPrI9FiEq54ICtr+OIlVss0 edpQ== X-Gm-Gg: ASbGncuIw/QKu16BULFElCY3mZVK3KB9tnDwJjp8hccpcUO510xiih9D3xSzUkRM92l 18ReBkdn2oeS4rrpDgkB7y1tiZCABovsWJQW6isH7SpIc+DL5RysklyV28zBNwVI0tuXsxKgBXl Z7yvBuuIAa7vHKNdCR21QtzLjRScvAIFzlwDRt2aH7sTo2UzMnrnkvKHtewjfmRrjIXht8gcqlJ to+fK/SobboioSSTxO2NNEBHKRNeq5OIotHuU0R2P85yC6O7h/BGqhs7Q== X-Received: by 2002:a17:902:ceca:b0:215:83e1:99ff with SMTP id d9443c01a7336-219e6eb3a33mr565079075ad.27.1735873451772; Thu, 02 Jan 2025 19:04:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IHGBER2IvdTscZDfzvf/elpBjJTjHsAhRcm73v7vt/2knmlf2lYW0VN6rGpYrctLrSfO1co+w== X-Received: by 2002:a17:902:ceca:b0:215:83e1:99ff with SMTP id d9443c01a7336-219e6eb3a33mr565078855ad.27.1735873451426; Thu, 02 Jan 2025 19:04:11 -0800 (PST) Received: from z790sl.. ([240f:74:7be:1:cb9e:69af:fb16:54f4]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dc964e92sm234468215ad.18.2025.01.02.19.04.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jan 2025 19:04:11 -0800 (PST) From: Koichiro Den To: linux-gpio@vger.kernel.org Cc: linus.walleij@linaro.org, brgl@bgdev.pl, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/4] gpio: virtuser: fix missing lookup table cleanups Date: Fri, 3 Jan 2025 12:03:59 +0900 Message-ID: <20250103030402.81954-2-koichiro.den@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250103030402.81954-1-koichiro.den@canonical.com> References: <20250103030402.81954-1-koichiro.den@canonical.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When a virtuser device is created via configfs and the probe fails due to an incorrect lookup table, the table is not removed. This prevents subsequent probe attempts from succeeding, even if the issue is corrected, unless the device is released. Additionally, cleanup is also needed in the less likely case of platform_device_register_full() failure. Ensure the lookup table is removed whenever the device activation fails. Fixes: 91581c4b3f29 ("gpio: virtuser: new virtual testing driver for the GP= IO API") Signed-off-by: Koichiro Den --- drivers/gpio/gpio-virtuser.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/drivers/gpio/gpio-virtuser.c b/drivers/gpio/gpio-virtuser.c index 91b6352c957c..ec5abfebca3d 100644 --- a/drivers/gpio/gpio-virtuser.c +++ b/drivers/gpio/gpio-virtuser.c @@ -1487,10 +1487,8 @@ gpio_virtuser_device_activate(struct gpio_virtuser_d= evice *dev) pdevinfo.fwnode =3D swnode; =20 ret =3D gpio_virtuser_make_lookup_table(dev); - if (ret) { - fwnode_remove_software_node(swnode); - return ret; - } + if (ret) + goto err_remove_swnode; =20 reinit_completion(&dev->probe_completion); dev->driver_bound =3D false; @@ -1498,23 +1496,32 @@ gpio_virtuser_device_activate(struct gpio_virtuser_= device *dev) =20 pdev =3D platform_device_register_full(&pdevinfo); if (IS_ERR(pdev)) { + ret =3D PTR_ERR(pdev); bus_unregister_notifier(&platform_bus_type, &dev->bus_notifier); - fwnode_remove_software_node(swnode); - return PTR_ERR(pdev); + goto err_remove_lookup_table; } =20 wait_for_completion(&dev->probe_completion); bus_unregister_notifier(&platform_bus_type, &dev->bus_notifier); =20 if (!dev->driver_bound) { - platform_device_unregister(pdev); - fwnode_remove_software_node(swnode); - return -ENXIO; + ret =3D -ENXIO; + goto err_unregister_pdev; } =20 dev->pdev =3D pdev; =20 return 0; + +err_unregister_pdev: + platform_device_unregister(pdev); +err_remove_lookup_table: + gpiod_remove_lookup_table(dev->lookup_table); + kfree(dev->lookup_table); +err_remove_swnode: + fwnode_remove_software_node(swnode); + + return ret; } =20 static void --=20 2.43.0 From nobody Thu Feb 12 23:04:50 2026 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 03B86194AE8 for ; Fri, 3 Jan 2025 03:04:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735873458; cv=none; b=MHf2e9it6SHqD9trtN03OigCL3qdmxN6bGyVlU2hxaF/4eVnhhdJsbeSVx8/CpnUpqG19NZn4gUpGPPthvzGvk66mmiSoBqqbpBSbT5iTOCNHK8OTYafD3KBK3dPBdfRvj0LOztT1bMME7bjuvhoXdECu128+7SXcRYrliLCNtc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735873458; c=relaxed/simple; bh=8ChtnRZwJDC04xlfJouTjNvR/nV1ghrWuZERWwclicc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=in0kLxhAclqAkFrBzDiy+pQT9y3N570JzkhrW7tdn2IzvRmVVCHdI9lQNjEi/SPXD8ZF3TCiR+L/DtmUx7rlvIYrhcqrIumkuSauiWdeFmnKwnosr4EZDwVYnKUBFtpiLjYmlJaOjbQFHItR/zbgxnlDyhYXgjQYC0mu4fgJv1w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b=qmx9h5n+; arc=none smtp.client-ip=185.125.188.123 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="qmx9h5n+" Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 7813C40FAE for ; Fri, 3 Jan 2025 03:04:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1735873455; bh=e3wTN7GG0fZy/9Mvu4ekzfXCmbA/5cGr2RaVYo8MjsI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qmx9h5n+Se/gsoUn4hOFfakVhcQoeM1XTlE3XmKYmm2CAktxcIjcFyUOENuwevcZR pTlYjcdBHrAxcwVdiOtKKEGLTkA/W4WM6Y8aiFNwLJJ0nwf4PgKv/VvljeMgQvZd+7 Mf3eVCYhk4L0h+gk8iJs/SNuWb1f76CaFfgQyksTDem/3pxvjH6jOAXX9JxMqaM91b XzAGyg4qarPWeshsIMQHHfYTW/0MQGjfbgdCkFcUoNQEGDaqSsynjd6KYaKYBPEm9Q pYuepw5R7WcIoG7ktW2kyzCyBllZEmdIx948iQZ2cXxRt4U2gDM1dY79G3vzXBTBv3 GGkcdc8J8TEig== Received: by mail-pj1-f71.google.com with SMTP id 98e67ed59e1d1-2efc3292021so26287740a91.1 for ; Thu, 02 Jan 2025 19:04:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735873454; x=1736478254; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=e3wTN7GG0fZy/9Mvu4ekzfXCmbA/5cGr2RaVYo8MjsI=; b=khVxcEJXB1O7t8KGOE24/ZlarXxaVPp+Ok+dz8uZIcJaBUq2tLZ7p8xV8lL7ezMk9c CWlKVrrxo18DOaEsjIWZM1hJXuC0YmgbJdjHvs/68jB8lG43io7JwvE5J25MJdXlFh9L 0APAOOKJdtRToSBqsswCHxwYvgfU/HLwE1rhUdrP0qJKfhAbri/vy+f9elX/aMRKxnk6 +5knhjeOb/QInITyM3RqJONCfJgJhOrgXjFioeg2jG4tkXR1YsUpGrYguyfjMnOIv4/O 9PMKzG4YShZvvElPH2wZ9UYVJaSCGwkzUgmJekauUL82U/YlERFmMrswbcgrPjBN5ktc GIag== X-Forwarded-Encrypted: i=1; AJvYcCUsPauFHSCyjLjk6aXtzP5s8eD1Rg1VVsJ9tL93ZhDaxrWZlVkmPIeICsYu5k+ZL90KrjjpDJ27onqmkZs=@vger.kernel.org X-Gm-Message-State: AOJu0YwoMM3oH3T386cxRhE9jARVMELZcbucsSFbuRmvJmnooZwc8ch1 ZonxrMVsoFUYn1RD95hKlhnPveWgIAdQJ/0UMrt+cuxuc6oVmA7Ms7f/UD7z8tTfhdCdC0b5hgm OWJaka3hWsTHVoph1m/okPqmGzoUsbO3grvHj5o4P+FfjkhUZevHei5ylJemLUT2Y2FEaj5WrXu Vxqg== X-Gm-Gg: ASbGnctGujZ3eNz53vyf5RTbCPBJVsVTyuemzvsEcXHRrsK0yUvguicMBSvDcYMraKR kRF2tM2I2eHRjj2v9e3crhdaul4Qo4TqZ7tI96XtdsFeJkDUg+dd2a/tOQxcnJk/wT3wx45oP9+ Rlsj9jOTV+T/Yy1IuyAdaGS5ky0cNAWvdXNS1pQT/XVeVpZ+ScjPhnxm5H7jC7ZhnKWIaMHFxRN EXHrzrLzX1v+z2DoBzt6jXFRzI/FK+stnPCKnjiWXWY2QBy/U/doFHocw== X-Received: by 2002:a17:90b:2e4a:b0:2ea:b564:4b31 with SMTP id 98e67ed59e1d1-2f452e3db0bmr69946869a91.19.1735873453830; Thu, 02 Jan 2025 19:04:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IG1hiK2a5+CO233sG3Qpkn6XXVD3vSsm9fOlhx32heiyY6Mfxi9/aS5dOjiAQEQ/d/43Wr6UQ== X-Received: by 2002:a17:90b:2e4a:b0:2ea:b564:4b31 with SMTP id 98e67ed59e1d1-2f452e3db0bmr69946849a91.19.1735873453546; Thu, 02 Jan 2025 19:04:13 -0800 (PST) Received: from z790sl.. ([240f:74:7be:1:cb9e:69af:fb16:54f4]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dc964e92sm234468215ad.18.2025.01.02.19.04.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jan 2025 19:04:13 -0800 (PST) From: Koichiro Den To: linux-gpio@vger.kernel.org Cc: linus.walleij@linaro.org, brgl@bgdev.pl, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/4] gpio: virtuser: fix handling of multiple conn_ids in lookup table Date: Fri, 3 Jan 2025 12:04:00 +0900 Message-ID: <20250103030402.81954-3-koichiro.den@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250103030402.81954-1-koichiro.den@canonical.com> References: <20250103030402.81954-1-koichiro.den@canonical.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Creating a virtuser device via configfs with multiple conn_ids fails due to incorrect indexing of lookup entries. Correct the indexing logic to ensure proper functionality when multiple gpio_virtuser_lookup are created. Fixes: 91581c4b3f29 ("gpio: virtuser: new virtual testing driver for the GP= IO API") Signed-off-by: Koichiro Den --- drivers/gpio/gpio-virtuser.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/gpio/gpio-virtuser.c b/drivers/gpio/gpio-virtuser.c index ec5abfebca3d..3ea00321225d 100644 --- a/drivers/gpio/gpio-virtuser.c +++ b/drivers/gpio/gpio-virtuser.c @@ -1410,7 +1410,7 @@ gpio_virtuser_make_lookup_table(struct gpio_virtuser_= device *dev) size_t num_entries =3D gpio_virtuser_get_lookup_count(dev); struct gpio_virtuser_lookup_entry *entry; struct gpio_virtuser_lookup *lookup; - unsigned int i =3D 0; + unsigned int i =3D 0, idx; =20 lockdep_assert_held(&dev->lock); =20 @@ -1424,12 +1424,12 @@ gpio_virtuser_make_lookup_table(struct gpio_virtuse= r_device *dev) return -ENOMEM; =20 list_for_each_entry(lookup, &dev->lookup_list, siblings) { + idx =3D 0; list_for_each_entry(entry, &lookup->entry_list, siblings) { - table->table[i] =3D + table->table[i++] =3D GPIO_LOOKUP_IDX(entry->key, entry->offset < 0 ? U16_MAX : entry->offset, - lookup->con_id, i, entry->flags); - i++; + lookup->con_id, idx++, entry->flags); } } =20 --=20 2.43.0 From nobody Thu Feb 12 23:04:50 2026 Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4319114F10F for ; Fri, 3 Jan 2025 03:04:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.122 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735873462; cv=none; b=cFUNUZtBQsqTJVjliHMRUTsxQvO0y9PzsSEc71PwCjYk3oqkM6+cliQPPE1wAkBneapjwmDjwOh5LAMlToaEZQ/HO+BGd240EsQUvZallg8G1Q7gvpC80I4xQMFGz/ynYAOdoptdWoAXWJ/Skmq+TfY1r2E534bCCSBnaWdv1tY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735873462; c=relaxed/simple; bh=JunSkXQS/WrxUltD0lGrTV1bGckYdkmYNn3tEKfXHBM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fd1RjT39thzm19u8ssElvBC94u8nU68hTbve6/E+uUfe7MH9Y4t0MFaCII1VXNh/VfGE7tYVCAkWBmiZ+3v2xaBETdCj6daVNJ1yzurtmgXFgUAIxXhzStrg9ZJqRl4+l5xNYm0E7K7lSlsUcOMqnvZlKNc/insFGNoOwijK4Ag= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b=kVENGoKc; arc=none smtp.client-ip=185.125.188.122 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="kVENGoKc" Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 5CBB73FACF for ; Fri, 3 Jan 2025 03:04:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1735873458; bh=5OyXQEUStRad/LSx/VEF0lCffTMLCTZxVZyqOqZw17k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kVENGoKcU51x7/ReBDqMWd8Y6sAPnjfLHIWltn3cEUcMYxiVbsF/E0dSNzDQheQvT uXufKG846JR4nCrzindrf5tCfcZ9EarBwCD1q4bPnkdofCCvQOVzI8QMLGbTgdw5SH Sqr8bQBFlyWKtKvF1JtYvA7V7hAdt+Z71jYdHnJba3YYQ8CYz6CzdAY6heXRU4N3vJ lYltAHlmXG5H3o7aARFRQZ2Khqda7rKu2lFT+wffOMhiEyTuPGdXPkG3yjZCwcBOLb eSLxyamxoBDLcP2n5na7YQVqYI3Qy/kN6yZnu2gGe12fcgSM3ykAA5rRFoPPxXw760 NbrhAeLAmk3fg== Received: by mail-pj1-f70.google.com with SMTP id 98e67ed59e1d1-2ee86953aeaso15852152a91.2 for ; Thu, 02 Jan 2025 19:04:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735873456; x=1736478256; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5OyXQEUStRad/LSx/VEF0lCffTMLCTZxVZyqOqZw17k=; b=jJkse3dk5e00IznPuyYV2BunLZ8zPNJTkCjMLHic30iEGXvaLMdoT6p3Nk7Y4j7Kh0 Lv8RKe3mO8ZheUioeB5OX0V9ZLnzJ9PNpbsaNAyhK91/ktj6iUWaOjFIEGMWzvBwobmW zI3FwRGf7v9TpcCYPSRkzbUNtIjYKAovCoP1pND7yabVh4rYaN33dQ5RjGJzx78Bl3iC Xkj8c97vS7aAzOkWgj2XPu4znVpOpEJ0TtLbDAqGaHT0j7HXy04eZyVLEVbtFak8PYcM XIzYb96rjYQOeRRjbV/tH/erXnKzDKbnHkzBC2mNdm6S9o9zki0HpLeAmi/pEQaJ2EEB iEpQ== X-Forwarded-Encrypted: i=1; AJvYcCVdAu2IBDpJ/7HD/eTYChaKcy7GQPgiM5VPrJ6J/qXCp8VSj29fFilO8MRVV2A/fsmkf10ddopzF/J3JF0=@vger.kernel.org X-Gm-Message-State: AOJu0Yzbzn1AIxcBBvwEGx12cWzbFChu4ItwE0nvmV6ymMmB+88rEJ7k 8PRS0ZwH6UtYnrTX1lrz8BhOUVmMOMhiNiUsc2zRiLvFaZtA5MoGmaVpBKXyTvHTcGHL5jvJZz9 OaTet0Nkj4tKhLX7lR99rU7VjJrbp4jpTNlS9XcMpVkjKjzpOzkJCB3PBrYqjyyhotk9j6OjcD+ Kgn9GCpksKOw== X-Gm-Gg: ASbGncvY4AGK1Bo49C4GOmfCUyztKYXH+J9qy7CrkNOzqHUJgJ2EvYSH5O9gXnR59Er tNSq3RPlJ/rtaPRmi6s3PkrDGf51AcwDJAmOUe4px1FfHmJr6USIom/7RNaX0qmas11zEHFaPDL HKxtJ2ehosujxegtHbqnm+98l4zo29+ntHJwbr86O1lj8hYbwvBAasKZJYerM8QY3+SXiyp2S1a VXy0V8CUFLJIBz3IHC7xjZaGE6mo8m/GX7aWpyPEquStq0IIFg90wKmfA== X-Received: by 2002:a17:90b:3cc6:b0:2ee:aa95:6de9 with SMTP id 98e67ed59e1d1-2f452eed7e1mr71974688a91.33.1735873455897; Thu, 02 Jan 2025 19:04:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IFCS7Cz0YzMku+ZSoXJyoGSH4F1gRWtl6eRLFX03egQucKA/MTOE24CB9WUoB0rI8QyM/3gmA== X-Received: by 2002:a17:90b:3cc6:b0:2ee:aa95:6de9 with SMTP id 98e67ed59e1d1-2f452eed7e1mr71974666a91.33.1735873455643; Thu, 02 Jan 2025 19:04:15 -0800 (PST) Received: from z790sl.. ([240f:74:7be:1:cb9e:69af:fb16:54f4]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dc964e92sm234468215ad.18.2025.01.02.19.04.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jan 2025 19:04:15 -0800 (PST) From: Koichiro Den To: linux-gpio@vger.kernel.org Cc: linus.walleij@linaro.org, brgl@bgdev.pl, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/4] gpio: virtuser: lock up configfs that an instantiated device depends on Date: Fri, 3 Jan 2025 12:04:01 +0900 Message-ID: <20250103030402.81954-4-koichiro.den@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250103030402.81954-1-koichiro.den@canonical.com> References: <20250103030402.81954-1-koichiro.den@canonical.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Once a virtuser device is instantiated and actively used, allowing rmdir for its configfs serves no purpose and can be confusing. Userspace interacts with the virtual consumer at arbitrary times, meaning it depends on its existence. Make the subsystem itself depend on the configfs entry for a virtuser device while it is in active use. Signed-off-by: Koichiro Den --- drivers/gpio/gpio-virtuser.c | 47 ++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/drivers/gpio/gpio-virtuser.c b/drivers/gpio/gpio-virtuser.c index 3ea00321225d..f41dde330bb7 100644 --- a/drivers/gpio/gpio-virtuser.c +++ b/drivers/gpio/gpio-virtuser.c @@ -1539,6 +1539,30 @@ gpio_virtuser_device_deactivate(struct gpio_virtuser= _device *dev) kfree(dev->lookup_table); } =20 +static void +gpio_virtuser_device_lockup_configfs(struct gpio_virtuser_device *dev, boo= l lock) +{ + struct configfs_subsystem *subsys =3D dev->group.cg_subsys; + struct gpio_virtuser_lookup_entry *entry; + struct gpio_virtuser_lookup *lookup; + + /* + * The device only needs to depend on leaf lookup entries. This is + * sufficient to lock up all the configfs entries that the + * instantiated, alive device depends on. + */ + list_for_each_entry(lookup, &dev->lookup_list, siblings) { + list_for_each_entry(entry, &lookup->entry_list, siblings) { + if (lock) + WARN_ON(configfs_depend_item_unlocked( + subsys, &entry->group.cg_item)); + else + configfs_undepend_item_unlocked( + &entry->group.cg_item); + } + } +} + static ssize_t gpio_virtuser_device_config_live_store(struct config_item *item, const char *page, size_t count) @@ -1551,15 +1575,24 @@ gpio_virtuser_device_config_live_store(struct confi= g_item *item, if (ret) return ret; =20 - guard(mutex)(&dev->lock); + if (live) + gpio_virtuser_device_lockup_configfs(dev, true); =20 - if (live =3D=3D gpio_virtuser_device_is_live(dev)) - return -EPERM; + scoped_guard(mutex, &dev->lock) { + if (live =3D=3D gpio_virtuser_device_is_live(dev)) + ret =3D -EPERM; + else if (live) + ret =3D gpio_virtuser_device_activate(dev); + else + gpio_virtuser_device_deactivate(dev); + } =20 - if (live) - ret =3D gpio_virtuser_device_activate(dev); - else - gpio_virtuser_device_deactivate(dev); + /* + * Undepend is required only if device disablement (live =3D=3D 0) + * succeeds or if device enablement (live =3D=3D 1) fails. + */ + if (live =3D=3D !!ret) + gpio_virtuser_device_lockup_configfs(dev, false); =20 return ret ?: count; } --=20 2.43.0 From nobody Thu Feb 12 23:04:50 2026 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A8DDA1B0F38 for ; Fri, 3 Jan 2025 03:04:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735873462; cv=none; b=FPCtbsS3yCrIrkqyQWGJlWylIKNlqJNEYgxaCmpFRfA+WP+Tyi0q+7ohqdacOje4uihXeID48140u252LIceX5PEzeChgPUU7RFLzEyWZiFpHTKfRuXslaoXx9F1RVL1t4X+LoDowI3Jqp/Q7g8LcOZlTzP316/AAkySeJleIxY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735873462; c=relaxed/simple; bh=cMG1/1MMnZC5j0tafg83V1P3/epd9tHHHNaDsyBmqgw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nwCLHbrHe6WPmJRYQ/v6TLzSMZHeAwj01WSr5OvvBBRGHXkSRRjIq/fmROvFXHCDFNMFjbiPpV7QcqMTpyePVGud7VelX6T58WKtHiBxymzGgAkUSqvSHEQts98QatPGrHzFYkAHfVWRtx9CmDaZiAVvYbzcUZcxaBCbFhIc04w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b=Kzgyafz4; arc=none smtp.client-ip=185.125.188.123 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="Kzgyafz4" Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 3C72F40FA6 for ; Fri, 3 Jan 2025 03:04:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1735873459; bh=KnRRrmEz3ZlIIsMVIhLEqcdV5rbJka1OKmEC4NqPpMo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Kzgyafz4DbtPFf7gB3fK0kIZCDTE8fGazVBLBO/pd78BF8sjhlj66wVpKfUVFbj2z t8QWWoC4Bh8PHWUHMQlfVOhzQELjwIkWMWTSYqxZvXuhX2vZcx9F3GsRQByBu64oAI /06vbxyktZxGSpLbZmM6IAShDNZ7Gq00OyYd4vZXrUKGXq5XCIywysVTcr5jliKoaf Y6zVCSVMC1pozihVukmf5t075DBMTqltZyYxoIF3pRuottamrzv+zLp1/bJATh44Sw r0UNmtOkYIY4iIL3S85M6/CqxPS9V7PRxJ2sAMiw+aitPpshOY2Pn695Cjr4wQQwK/ RKPck2JuCpi3g== Received: by mail-pl1-f198.google.com with SMTP id d9443c01a7336-216430a88b0so161639115ad.0 for ; Thu, 02 Jan 2025 19:04:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735873458; x=1736478258; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KnRRrmEz3ZlIIsMVIhLEqcdV5rbJka1OKmEC4NqPpMo=; b=Qa0IqzhoVH1jvCrBx2ucZ59pqvQpiBGP1qX0MM6s1Y5CXug9YxSMjVn1FhnS2OoxNn RYxrqyMZhbVHwEkxctrFCV1dYpCaocszsf9FTz3Zg8qHPNVh3a4ngnJ2ob5ATYoxJ1Ze AJ3nyMf/qxml83EgPXoTyUdchfWGa1gbJazoajr9eYiD77bFIb6Z8ItmdPgzwKpSW+7C e39s8MrWO6r96/0LF5ncOVR+4UkO1oaOMAKA3r74a/wmP0wk6cjPGSvegi+EfXRiNrwW Q6lerRe5UHPPl09Xg626uWGDk3wRHIZ4DJ1tkRcStPX8ifzzGmnjKmR4zymNohIiwLYL jLSw== X-Forwarded-Encrypted: i=1; AJvYcCWsqiZFP39mbTHU3fFmAYiO5Yo2GKp14JihX6NX9WodrPMGcvMqAvDiPuIyk7BuqCDK9ptRZ0FMuESeUnw=@vger.kernel.org X-Gm-Message-State: AOJu0Yytb+CxjW5L179Z6p+L/90l8fMozA+at2Y2RSHIRkSvEd5gm1D9 wfzpD7c+WCaktpPr+STNRB2AlGSVIqSsEKCupSRyrDodm74YNyT85XtZzJwUYn6Pbi/T3eXinmS I7u58xNWgsUiH3t/hQmPq1jXj7DgVuyflqpE64ofHKRCFw1sSyaznq4kxX5ydAjc0hW50BBACd9 d3cQ== X-Gm-Gg: ASbGncv6UVN4pQvyCnUpJPgvmLlU9Ck0Akukk6oYGStOoBU2BIG/fP8CKxEH+1mR1LN xs0swKSffqySCcb52OaX8OGv+k18/PRYT8ye7Q0xxCcDqoQtBPwHKvz/dDh5Y4OA/z/mN5rH3+D 7qPfycmlObRvlyZ204ahHKoWhP9ARbi5ZL/S6dZyuJid2hAaajtJghgPY16odXdnEJ/MG8u1+3/ r3/++/33tB3I5wooryIWeP8Dq5DkDC1yKrB1Qwt6OCyiPoCTmpPBaeS7w== X-Received: by 2002:a17:902:ec82:b0:215:827e:3a6 with SMTP id d9443c01a7336-219e6f1447fmr669964305ad.40.1735873457818; Thu, 02 Jan 2025 19:04:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IG9RNUp94jEV9P+9MrJZxWB37Wjl05/hcGuQKUx1SF53mS16El8k6M6J16/Z4u8N3wsbGWoQw== X-Received: by 2002:a17:902:ec82:b0:215:827e:3a6 with SMTP id d9443c01a7336-219e6f1447fmr669964005ad.40.1735873457444; Thu, 02 Jan 2025 19:04:17 -0800 (PST) Received: from z790sl.. ([240f:74:7be:1:cb9e:69af:fb16:54f4]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dc964e92sm234468215ad.18.2025.01.02.19.04.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jan 2025 19:04:17 -0800 (PST) From: Koichiro Den To: linux-gpio@vger.kernel.org Cc: linus.walleij@linaro.org, brgl@bgdev.pl, linux-kernel@vger.kernel.org Subject: [PATCH v2 4/4] gpio: sim: lock up configfs that an instantiated device depends on Date: Fri, 3 Jan 2025 12:04:02 +0900 Message-ID: <20250103030402.81954-5-koichiro.den@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250103030402.81954-1-koichiro.den@canonical.com> References: <20250103030402.81954-1-koichiro.den@canonical.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Once a sim device is instantiated and actively used, allowing rmdir for its configfs serves no purpose and can be confusing. Effectively, arbitrary users start depending on its existence. Make the subsystem itself depend on the configfs entry for a sim device while it is in active use. Signed-off-by: Koichiro Den --- drivers/gpio/gpio-sim.c | 48 +++++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c index f387dad81f29..686ae3d11ba3 100644 --- a/drivers/gpio/gpio-sim.c +++ b/drivers/gpio/gpio-sim.c @@ -1027,6 +1027,30 @@ static void gpio_sim_device_deactivate(struct gpio_s= im_device *dev) dev->pdev =3D NULL; } =20 +static void +gpio_sim_device_lockup_configfs(struct gpio_sim_device *dev, bool lock) +{ + struct configfs_subsystem *subsys =3D dev->group.cg_subsys; + struct gpio_sim_bank *bank; + struct gpio_sim_line *line; + + /* + * The device only needs to depend on leaf line entries. This is + * sufficient to lock up all the configfs entries that the + * instantiated, alive device depends on. + */ + list_for_each_entry(bank, &dev->bank_list, siblings) { + list_for_each_entry(line, &bank->line_list, siblings) { + if (lock) + WARN_ON(configfs_depend_item_unlocked( + subsys, &line->group.cg_item)); + else + configfs_undepend_item_unlocked( + &line->group.cg_item); + } + } +} + static ssize_t gpio_sim_device_config_live_store(struct config_item *item, const char *page, size_t count) @@ -1039,14 +1063,24 @@ gpio_sim_device_config_live_store(struct config_ite= m *item, if (ret) return ret; =20 - guard(mutex)(&dev->lock); + if (live) + gpio_sim_device_lockup_configfs(dev, true); =20 - if (live =3D=3D gpio_sim_device_is_live(dev)) - ret =3D -EPERM; - else if (live) - ret =3D gpio_sim_device_activate(dev); - else - gpio_sim_device_deactivate(dev); + scoped_guard(mutex, &dev->lock) { + if (live =3D=3D gpio_sim_device_is_live(dev)) + ret =3D -EPERM; + else if (live) + ret =3D gpio_sim_device_activate(dev); + else + gpio_sim_device_deactivate(dev); + } + + /* + * Undepend is required only if device disablement (live =3D=3D 0) + * succeeds or if device enablement (live =3D=3D 1) fails. + */ + if (live =3D=3D !!ret) + gpio_sim_device_lockup_configfs(dev, false); =20 return ret ?: count; } --=20 2.43.0