From nobody Sun Feb 8 16:11:58 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 9980A1494B2 for ; Fri, 3 Jan 2025 14:18:43 +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=1735913926; cv=none; b=XYyCMVs3nKuvGuNHNQSAhUAxWctgW7QW+gSOuBpj7OEV16xcX1tMwJNpp3sQptDoDrmdaqxwWHJPeMdi0kXYW0DzsIgGFG9m+BXYZEUW0yBlybV2o6wD/r6kybUQDtiUiBiBj23dKkF8YG9+O6oA8ZrXOqGVsjb7VlLkX0EYdN0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735913926; c=relaxed/simple; bh=jP5wiY4Hjf6NHVox7oDrw9gPO0f53fe7WOrwgq5lWCE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XlIG13K8J959QUbG7TAbIGIqZcGUGjkyrWXBw/CVeMn1oc2lEit6wZZtVhSpm/ZFuOS14nJ5Lv9sFuGyLHAEw7eiBIu1fO3Vdz3wz3tk1Bo/h69fdY2VaDnk0uFAEq3dm/TkiMV6OqL/U4JQ8kTBGzBt3UfCgGv3pRx7qLI5CtQ= 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=UT/ES1er; 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="UT/ES1er" 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 CDE4C3F6A5 for ; Fri, 3 Jan 2025 14:18:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1735913921; bh=ZASmDFrSHCizrNYJB8JpDX9RUKYLSDAVuT6OOqcLRZM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UT/ES1erHeo2uABJyJJCIY0gvapyJMuCisnnr+8UoaDDFUfu1KefgKqdAacFoezk6 GFAeENWpToxGKCdjROMWdsQglsnGMO5pxABQhUw/H0inyg3kOCRjUpG7sXQp6RrBi2 qY0dmiKuXJVrV6xq6Qsg203GitUZNuRx3C6OM7LDyYHcp9hde2JB+M5nKYalTWvKfq /PzcPj2RjMwBXMv1mAm8ssLtHZCx/O46Ic4apjMFiGStAFTFrs19UtCQ/gQTmrwID0 0Z/5IlUIGX1wHM0ShsiLe4rn0OUVNHdSDhIwQf/sRxlEGF5BnLz5tQXnTO0FUW83bu E1xYktnclSUaA== Received: by mail-pl1-f198.google.com with SMTP id d9443c01a7336-2167141e00eso163961395ad.2 for ; Fri, 03 Jan 2025 06:18:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735913920; x=1736518720; 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=ZASmDFrSHCizrNYJB8JpDX9RUKYLSDAVuT6OOqcLRZM=; b=wECn33BTrqR3/moC9SNKE/pVodrYtJOpvl9AVj5ya4faJmL6F1RvXdQvvGpFJVN4wc DU8QzsxpW4XUEjGCsasOK76/WMsHWDxkghs7t2D3i4ax3cJyo0BEmieG/cdiY2DoIFdH k1mmG/sj41UI/krL2kKN/Do7jTJ++mihNHJPkVtG/Pt9CAyILt0PtqWNx/OpG8z1NeTM WXM1ct0Hw2H2zuD7EuCO9IZHPK6E5aOxH5oejdsRv9UeID7mk2mPcF4sCKOWkyGLP8Hy wTmRezRoOHxViHnafyXrqNwcUfr4Qx9zwddHtqbPlkkeBWmD/4psoVCMRezVBbna89fD +l5A== X-Forwarded-Encrypted: i=1; AJvYcCVpE+Jw0RJw+hN5rMW4Z2uUwH1JlzSzrKXh6PxVuQOGuF7You7TRTks/uB7vKDz2D9XVUP0h6CSYHLScgE=@vger.kernel.org X-Gm-Message-State: AOJu0YxOFXp+1jZcFhQBdJGVwyJHwlsntFgx+FDS6ggMYOZt/KzZmF14 +JM41RYom6nRYPdOg59Ahj5Uur+hPxsv0JICpb6IBz3KOsyeU9CLhibLIObeWqRZEMEjToYawC8 BdZ1ZCZrPYMsQCpER4bQd7bd0mdtTh+dV9hfm3k1t2VrivqS2j88YsvhVRF9P2PgXYWloi/PB8Y gaKMR/6t+TpA== X-Gm-Gg: ASbGnct0XNA1EJgEAlfIgzLiDjxfLemh5aKqy980jZhjPQiFL1nHHi9CJ4R2qKKHZkr LG7T5Sytc05J+pyXDnYPJRZCmrNTnyP4y/5wCDo7Naxy+2gOywQW83pGVLakA8wYxNH5AAvaC36 9+fTCrqCQoQZiHFDQmYaXmO5FdVxFtRJqioZRZLoU5vdVe/JBq/CkqEPOTu1zt/8xhhxJ7TvEtx sJxg0xl9Gdcgy7IhD3sYQzwgl7TE3N+yivZx/Ao7puSX6UIqgpjlXcHyQ== X-Received: by 2002:a05:6a20:7f87:b0:1d9:3b81:cdd3 with SMTP id adf61e73a8af0-1e5e0446330mr75040973637.1.1735913920284; Fri, 03 Jan 2025 06:18:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IGm3Kja89gSgoWB37SsFC82gysqHLLpOOCP6TvpCB3iQy7oMAN6+NUKnLxb5xzVfUWyR/mfBQ== X-Received: by 2002:a05:6a20:7f87:b0:1d9:3b81:cdd3 with SMTP id adf61e73a8af0-1e5e0446330mr75040939637.1.1735913919933; Fri, 03 Jan 2025 06:18:39 -0800 (PST) Received: from z790sl.. ([240f:74:7be:1:cb9e:69af:fb16:54f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72aad8fd7b0sm15502908b3a.139.2025.01.03.06.18.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jan 2025 06:18:39 -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 v3 1/4] gpio: virtuser: fix missing lookup table cleanups Date: Fri, 3 Jan 2025 23:18:26 +0900 Message-ID: <20250103141829.430662-2-koichiro.den@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250103141829.430662-1-koichiro.den@canonical.com> References: <20250103141829.430662-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. Besides, a consistent memory leak in lookup_table->dev_id was spotted using kmemleak by toggling the live state between 0 and 1 with a correct lookup table. Introduce gpio_virtuser_remove_lookup_table() as the counterpart to the existing gpio_virtuser_make_lookup_table() and call it from all necessary points to ensure proper cleanup. Fixes: 91581c4b3f29 ("gpio: virtuser: new virtual testing driver for the GP= IO API") Signed-off-by: Koichiro Den --- drivers/gpio/gpio-virtuser.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/drivers/gpio/gpio-virtuser.c b/drivers/gpio/gpio-virtuser.c index 91b6352c957c..e89b1239b635 100644 --- a/drivers/gpio/gpio-virtuser.c +++ b/drivers/gpio/gpio-virtuser.c @@ -1439,6 +1439,15 @@ gpio_virtuser_make_lookup_table(struct gpio_virtuser= _device *dev) return 0; } =20 +static void +gpio_virtuser_remove_lookup_table(struct gpio_virtuser_device *dev) +{ + gpiod_remove_lookup_table(dev->lookup_table); + kfree(dev->lookup_table->dev_id); + kfree(dev->lookup_table); + dev->lookup_table =3D NULL; +} + static struct fwnode_handle * gpio_virtuser_make_device_swnode(struct gpio_virtuser_device *dev) { @@ -1487,10 +1496,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 +1505,31 @@ 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: + gpio_virtuser_remove_lookup_table(dev); +err_remove_swnode: + fwnode_remove_software_node(swnode); + + return ret; } =20 static void @@ -1526,10 +1541,9 @@ gpio_virtuser_device_deactivate(struct gpio_virtuser= _device *dev) =20 swnode =3D dev_fwnode(&dev->pdev->dev); platform_device_unregister(dev->pdev); + gpio_virtuser_remove_lookup_table(dev); fwnode_remove_software_node(swnode); dev->pdev =3D NULL; - gpiod_remove_lookup_table(dev->lookup_table); - kfree(dev->lookup_table); } =20 static ssize_t --=20 2.43.0 From nobody Sun Feb 8 16:11:58 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 2B7991FA257 for ; Fri, 3 Jan 2025 14:18:44 +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=1735913927; cv=none; b=nCCnPDxqBCPRRa8LVnB4GXRFl6/D5jFfpjbBORLo0XUeRR1YOWjzSfYcVAhzi20xUBJVSA2tyEdA/g+rtJG+c9pOCl/pjOLGr/d+53D7gCUjCKrBhibJ43yk/3f5TNxD+PHV+ZyfVI3J4SybWI1d4fKCazuHgv27fuIOefWgF90= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735913927; c=relaxed/simple; bh=xj5FmQy3EE0y/q2Xy2BJboeLtnYBdNtJ3Xh0zZTuVpo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VrURqDM/6l8241xoifSchJS+Hb5GIDJfwy36z8nu2vLOy02GUWntQPHma9uBOf2wp452PA0gIySqR+wM70yarfrlamAR0uMedjKBFgs12oNnBi/Px51dvSrE6AsziRNFqfg5FmPPRQdGdSrB7uG1KrCoi1lqiiNVMMq5izUUWj8= 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=Y0bE/gw7; 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="Y0bE/gw7" 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 7ADD63F370 for ; Fri, 3 Jan 2025 14:18:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1735913923; bh=aIXIXU9c8w5b5nDvjabg7EfpeGBd9Yb+6lOtjZAAkgg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y0bE/gw76xTOS/o+IiooB+oVqYOQ4IX84YaRPvit/B/coxXoS5aF7PzUnkPtKpEGt x8DY6UHmDvwoS58x2QV/67EuSF6EMwe/5T4gmunZ3A7LE2wxM1cBgvHtfg9mlRcBam uePuociPtiIOc7nnEVHaTe68Hzt2Kr13BxTLgcYH/6iEQ7KL2ez81g86QS3Ms//Ysb wQ5GRsbc8yZceHRysGWf2yOMhgEqgGJxSymEB9kEpkxrAx8DSHNPuRqPWBvYGYC4ST IgcFoSWA1ZB+OstCgHa1H8mueGBMdeE/n+rImu4DSV4MwvETzN07dmH8GsQfZ8qapq rE4xvMXzAH/VQ== Received: by mail-pj1-f71.google.com with SMTP id 98e67ed59e1d1-2efa74481fdso17461746a91.1 for ; Fri, 03 Jan 2025 06:18:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735913922; x=1736518722; 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=aIXIXU9c8w5b5nDvjabg7EfpeGBd9Yb+6lOtjZAAkgg=; b=WrnhcXww6mlxjWDIjGt7f7V/uCcGWajIK236kOxEpGQUvOvjm8RkdbT3+24cZfuJRU McNPVvdFNW1ECIc6JdxAvvxRZx5PodrchLcPR6tt8+QTogxS2iqirEnPKCN1JD0z/2Od DNS9YYOTHVCEymvyco8It/7fKcskirIZjSEg+IZVo01Xxv/MXFVE3GosYsLX93IZCY2Z TgAbmsfLcHR84iJV/J1sNvYAiyEM2pbytKo2ccq2+iMYYkhAfUGWpR/srQkbwcKnf5vu Hqxs1nUyDxWEgec8BzdLhTH4FHRrv4Y9ZYbEGnouibE/zdmPSvshbdsn676dHgWT0aWX ywww== X-Forwarded-Encrypted: i=1; AJvYcCWPKNN3B/TwzQn15y15ZDX7sMoQK3a9m2VK99bqLnyxZ0MtLc9TQ0soV5zFAtUpiIDveATJFE8BTubxMlo=@vger.kernel.org X-Gm-Message-State: AOJu0YybWQbzMWf7BU48desxXALZIurWEHNjJHWhe+CVB6f+/e7kMSAB 8pu1R4pJZlWRQ+y8qm65t+HwFtiLJsGsJqiWq0DmovCv7yWsM0T8Kz0rogo4liZJZlvbMNL3egD yyGRZ5JSnniUE6eVIa7r363auSTaAIvqX2/2x4dkAGbeBawvKPZaHImnXEccd+ITpXl/4z4xFRA gLjw== X-Gm-Gg: ASbGncscrtVyfAJpzMtEtgZCQ3CzqCYaZ6v+tMjbfWwLSAk+ZjTWDIzPL+S+XzrcNxm 1Bvd6NCQInqYgFwfR4youybEAoj+Mo82cd0g812MvNbQkKhpWmKrD0dYT9XUm/sEOz5pCHa01B4 EVNQM9hPvObADcVx1LMHgP0VSsdDFn0neC4dMjqtxccRqKYMb9Up6xgj6YvUXJL6oOQCc2oQ1hn DNj30rvib8/UujBaLhClZghbZGPPUfAdvWkRtLNfvGz8xGukn5Zv6CarA== X-Received: by 2002:a05:6a21:158d:b0:1e0:d89e:f5bc with SMTP id adf61e73a8af0-1e5e046155fmr80534298637.11.1735913922149; Fri, 03 Jan 2025 06:18:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IEN7lGI6hgY4m24rOhupEAR1EGnbf4GcSyjURqmpRkx74cLuFLXXVpAWTSFzzaDgKf5SmnY6Q== X-Received: by 2002:a05:6a21:158d:b0:1e0:d89e:f5bc with SMTP id adf61e73a8af0-1e5e046155fmr80534265637.11.1735913921890; Fri, 03 Jan 2025 06:18:41 -0800 (PST) Received: from z790sl.. ([240f:74:7be:1:cb9e:69af:fb16:54f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72aad8fd7b0sm15502908b3a.139.2025.01.03.06.18.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jan 2025 06:18:41 -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 v3 2/4] gpio: virtuser: fix handling of multiple conn_ids in lookup table Date: Fri, 3 Jan 2025 23:18:27 +0900 Message-ID: <20250103141829.430662-3-koichiro.den@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250103141829.430662-1-koichiro.den@canonical.com> References: <20250103141829.430662-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 e89b1239b635..d6244f0d3bc7 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 Sun Feb 8 16:11:58 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 E876E1FA267 for ; Fri, 3 Jan 2025 14:18:46 +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=1735913928; cv=none; b=WD4xiO4WeNMpqXxoYOTde/kOJUf7pBDXDZL1S1x1pUob81nS6//odZbx52jjqoaHbWzzD32j67w4oT9bciY4E57aF/Yamg/znsOJQzKEUne5SYJhMkAGIdoPBH38XjZ/Ef0wM1YvrSFAuOgm3Z8C8cHkRPYROXynX4Omm1ESjc4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735913928; c=relaxed/simple; bh=xhS0Z22ILzihE8+EF1GLpM5S8o9zaVB9Z8Ix+uBto78=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ryVFAdnMyv6MkJeXEjIeYFNt2LjOdyfalAYedAKpRvqLlW6ChuKQ1Q2X/5W2KyGeOkRPH2S+R71RMMhValRcl8N29UKQSUfD6cUwYMBpYr9zNPkaJJg3s0R+LAS6yG929XyouqgV8lSOX1Txo81D3DKBdCiIJxRw5XZZ00EX4LU= 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=KOcgr2up; 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="KOcgr2up" Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) (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 4EF0540FA6 for ; Fri, 3 Jan 2025 14:18:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1735913925; bh=oQRkhk2ers1PY8gk4vucPTfvdzK6lgBgnNx9ctUlNu8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KOcgr2upYvpYn3d5UxI0N+eOXwd8InmoEPIq12jVZHOa7Eccy8/hkgqUmR4qRWjMK vRz7nzBsRg1lLcM+rHPADeWLybtbscFpxh6PQB1Iu+iIXCmrTv4XW3tsE2YmQkx2aq gnd45zTw/CqYjg+WQ48G0PgvWmH0Qxqhkrgd0BACyauUxtXXM3vFni//6zg7zcfeBQ OUw5YHxvdTeIGMD/gVyHXissf478WndQl1EPKtn51Okydu++QwiQPYHPVJf2Y/kmxE vcs7XJqjZSn6beg+2WL8GhMXUdmuZvkQukz0fK8VQ9+FYvn9cG60n7cl78GPa/6bjK xWHsxeRWFU66g== Received: by mail-pj1-f72.google.com with SMTP id 98e67ed59e1d1-2ef7fbd99a6so16484311a91.1 for ; Fri, 03 Jan 2025 06:18:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735913924; x=1736518724; 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=oQRkhk2ers1PY8gk4vucPTfvdzK6lgBgnNx9ctUlNu8=; b=fepkFYTsEb1G8lzjJLg/Y9yVgwG5NOVR7B/CbdjC3K55mdzeB2aQxOCmAQEmloZ9iF I8jQ5eCkjzVQAR/Q6B7tIzCFUe6/jK/ByLFOSLej8gZ0u2xYqysJI7ddF3ucGSc7729m bNouQqYxmrWFHaawpD4oVHH8Ihe9KhGOuYQdnTcsmEBG0YKqNpEbLgIQTe3w2jHxQVsQ bQGJDXHTbeMu/qVZtfBCca+whwUMTWpu5P+vBO28RajpoKgEGqb/jGASeA8c1pPoRF0+ cRTTEAtUY5FWSxUhhZOE/Jcv/dYy/ecwZarc0nwGebr/F450hCurvc6cj0Om/7nUkJFl ESjg== X-Forwarded-Encrypted: i=1; AJvYcCUWUwRlGrmtpJUUPVSWkIVwhST0bQcDNDZkXE/1Ja0n0vz3kZL5KFkVoVzBTVz/Nz9qn9MJV13WzkJktTE=@vger.kernel.org X-Gm-Message-State: AOJu0YyvKJZNDHsdjPB0Y264RwtWo87EzxuDONgt3RQcNH8byLqjCQ3X +d20H1ker7zogwuzKUy/J26eeF9JHLK+LmegQPJwbOEHfdMMQI8ivRe21TwWNihD9GlopT6RCZJ 3wrurXW8niuLMF1lU46AUp4CHzPBl1J7DoCWzxCjjxG40yHs6f9Util2+BZv8+ZblG8/vEXH9DX ftVg== X-Gm-Gg: ASbGncsSrZekmyL5dVXIysa/dOd9vC3ueSoZ3uXxIJjkR+ldLlepGdrpNcffUAIo4cH B969m55U5eomsSZXk82jNHAyYiQtwn3bVsT5eKg9GqMhD4QBNduN/+PWOvmUc4M3mkZF4mpEXAd fW+GlAkHmrd6BQnoPn8X5CnvOEH2XczqRF3wygVuH8gNTLNkFeDfR6thUwzaFIVmcQ3RBimlDkw N6sQi92EI0PYZjg4TaSQaSQ2RPDIcs/vg7H/NTNIxCE8z815as4nYFbCA== X-Received: by 2002:a05:6a20:12d5:b0:1e1:a6a6:848 with SMTP id adf61e73a8af0-1e5e04a2ea0mr84790426637.25.1735913923818; Fri, 03 Jan 2025 06:18:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IGfuLuntJGswpyZlgdgJtqQiNv5lyTRdKl2lvQlfrLGdmckhmZ8HvOlcs4HTDI0rd06bQdpNw== X-Received: by 2002:a05:6a20:12d5:b0:1e1:a6a6:848 with SMTP id adf61e73a8af0-1e5e04a2ea0mr84790392637.25.1735913923515; Fri, 03 Jan 2025 06:18:43 -0800 (PST) Received: from z790sl.. ([240f:74:7be:1:cb9e:69af:fb16:54f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72aad8fd7b0sm15502908b3a.139.2025.01.03.06.18.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jan 2025 06:18:43 -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 v3 3/4] gpio: virtuser: lock up configfs that an instantiated device depends on Date: Fri, 3 Jan 2025 23:18:28 +0900 Message-ID: <20250103141829.430662-4-koichiro.den@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250103141829.430662-1-koichiro.den@canonical.com> References: <20250103141829.430662-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 d6244f0d3bc7..e89f299f2140 100644 --- a/drivers/gpio/gpio-virtuser.c +++ b/drivers/gpio/gpio-virtuser.c @@ -1546,6 +1546,30 @@ gpio_virtuser_device_deactivate(struct gpio_virtuser= _device *dev) dev->pdev =3D NULL; } =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) @@ -1558,15 +1582,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 Sun Feb 8 16:11:58 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 C28D81FA8F8 for ; Fri, 3 Jan 2025 14:18:48 +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=1735913930; cv=none; b=H/qCjmqKaRLHIVUUxR8/pCnJDRLCVMLMI2bADGjHFg3S07ecO3nCwnjn8y2s5cdE0TTDPVP65wFqZ5+IWQkHT/8PkIuvcSfuIA4ers/9K3Ie7ZukceJeDI0V0Dyf4qGGwNOKdBJ2ognUiQo89LhK/o6pQJpQK9dZl49Rn+ayFGY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735913930; c=relaxed/simple; bh=cMG1/1MMnZC5j0tafg83V1P3/epd9tHHHNaDsyBmqgw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DrqLrBrx430liGjH1sU24e367D86OJwAnH7FH85VgRNRF+oYclUHg6S8pwr4NUYvtHo1AjGr9S7Uj/qIgU9SrywmdXRkam2U6v/qcK1/kWlWsWCaH/ul0kQfOze+q5EbxPvuUxTQa1R4J+xyQ1J6wQxBNe20we2yQ5cJhJQUhR4= 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=Uqq2ZuOX; 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="Uqq2ZuOX" 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 1D75B3F6A5 for ; Fri, 3 Jan 2025 14:18:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1735913927; bh=KnRRrmEz3ZlIIsMVIhLEqcdV5rbJka1OKmEC4NqPpMo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Uqq2ZuOXU3Rf5MmbXknU56Ny6z2JBFo6qfZVZ7AcXgl83ei1hWDmN06c+SaBxnVc5 PczNnRuI9jopJXiNWEO3FdvzuqZ8HDKIvMGgnSdM00Gr3a0FJThT14mg4f4NrgO2uP dADBuRyi5XutQJerCz8YoB4oS1ggOaf+t4PpPvLzXGHBwFDocUl/0lMxhVPGeeskIo IejPmn556fl9a70JN/DgNKYfZPbhDbVTjnn5yVRvVCd/NGV10bqYJEaR8429B396DU U+dA+m8t+bVjPfhj84HEO3nbc/l8yFqMN1iwn0A2+wzT8AeWDQ4RHhD2XA4Je80hVF jV3l+qLJ67IWA== Received: by mail-pj1-f71.google.com with SMTP id 98e67ed59e1d1-2ee6dccd3c9so16736077a91.3 for ; Fri, 03 Jan 2025 06:18:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735913926; x=1736518726; 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=ZHxarmVIT/sYzqvb1RQeHSVNfD0RZfWZkGbgnBkyD0ISRQ93LD6RxilZkaQTKdMzZU feY1S40HUGe/duIgVI5EYXUBd0WDUwMl2ux2+cGM24pyydklTM5CSvOM9sBch8nUuZmh 9/0T5CBwfkoO+HOuQbELUpu9vo4LRB/G3tflliRUKMzW8jmC2MMOZWfeyOfWTVTqwM+o iqXSeQKV6sn1AWUWZcfNkG2JnsSchKnberIUAcypFHJzY2W1XY9Aq0ZeNnq3KSVYuMMm xFjyupcsmiozOQa48gaw7+g/qdsSby+6xUHz9HOWM1k2OyBNHVU0UWlPP5oPWPDkmA9s QpMw== X-Forwarded-Encrypted: i=1; AJvYcCUv3RJsw07Fv0kXzPkBAI3L7fv8rQ4ozqZIQapVhfDwhYfgbB7D+jGNwXOpP5Mu4MF/KibtP3FU4FN2qSA=@vger.kernel.org X-Gm-Message-State: AOJu0YwmxTr+5aNC4roX0b3ILjKR4yB5VnVrDWj2eOw3z9tGKzdPGREI oEl/aC82BWDxTjBCvEesAVgBXY/quKl9svbwho/SRVN231ENSJcM20UEShR2eC1Bp/l9LHoJrvj gdICgqq7eNh9reqIBSoEJS0GZ5CPaoRmlEWmXHdjALLyxtl49fO4KxrD2R4i66WshIRhWD2ao64 +Cxg== X-Gm-Gg: ASbGncvwMUAmu5CSwinvd2SrmZWtZO8KEqRdYw63NWna+PcYqJ6ti8jXeLsqAonsbl2 UPgae74yeLnerG36dW9E4a8itXx9yAQ0jUJg/OJPSuAuxbcMDsC8xlFhEJnXP/9hli+IGohE3KI kEpL95Q3ozw8wDvetStXbfC44mvkVGXEvf6JmGMbc82JKEpmVqWorU4/pziVNSyYlDRFNn5N70g zAGuThsmCeaBKg4xLLzcoaSeNx1NiZC0MUex5cvR3ZOcouSVOF7Pl0+tw== X-Received: by 2002:a05:6a00:ac5:b0:726:41e:b310 with SMTP id d2e1a72fcca58-72abdec84b4mr60827624b3a.12.1735913925735; Fri, 03 Jan 2025 06:18:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IFv7U382CtqgSsXMIMAYCsMVFfbR/QUYppP1lRrSvlMvPwHSv7X7/iZbJAG/Su+h6fW2JOd6g== X-Received: by 2002:a05:6a00:ac5:b0:726:41e:b310 with SMTP id d2e1a72fcca58-72abdec84b4mr60827591b3a.12.1735913925377; Fri, 03 Jan 2025 06:18:45 -0800 (PST) Received: from z790sl.. ([240f:74:7be:1:cb9e:69af:fb16:54f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72aad8fd7b0sm15502908b3a.139.2025.01.03.06.18.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jan 2025 06:18:45 -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 v3 4/4] gpio: sim: lock up configfs that an instantiated device depends on Date: Fri, 3 Jan 2025 23:18:29 +0900 Message-ID: <20250103141829.430662-5-koichiro.den@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250103141829.430662-1-koichiro.den@canonical.com> References: <20250103141829.430662-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