From patchwork Fri Jan 3 03:03:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koichiro Den X-Patchwork-Id: 854929 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 D4B994C62 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=1735873457; cv=none; b=pdy2PC1obf7InLKP2vE0eRoXi7pn3oIbrterY1QPZNTa27jHegmBzhHxdJNDqMXsOa1sI9OQdglbfiCOLxHMSLqDe+R4WREVDM2IPyppKMoSVSGnVcEO26Ia/3gIH11g0SqvLRiWyER+qdZ1GiGrNEcph+BGK/o3dXniWvxkuHI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735873457; c=relaxed/simple; bh=HO08RPGJzed4ppqZ+jQm2FIefTr2FHu7Tv13x0myX08=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IztY7mOxP7WTL7+UplonRt0c2e5FYixGK/un6KsDATT8akkN5W4tXgckEkZzlo/vS8JSldi2Fnly/c/6rFCJ0E+tSyxP/7N/3vARap5f6azWsQKo3Z8oa27+C/y7SFO8COYwB60cv/PROYFA1hE/Qd2Vhj+ljlOFcNSJUlZgR7M= 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 3FA4E40FAD 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-2161d185f04so119904345ad.3 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=aYgC7c0R2oaTT5BLTybNnJEZb0lTCcxAnJDyngFWgoIr60KYkLANYcXSgr5506WBEP O6KQISxVMsBc4KE3QeCNpID8OtZi2mdukD8901QOoNabprzfLhwF54xnXH/N7XCEZm3S nA8oO/gLHBecvpxcthSIM4AVVv4dCNyZir/Z7paatoThtJ2pWqf+KPqEjhARc5AUqucq QtB6/4okl4Zv4+Mb2BwjYZnjLyKOlAwVIcyDLsLvfIr/vHeaCbO6tkAetd2KCjUW2Vep fJksCWfELqweRoBiRJkG9Sfhmfn3KmtY2/k8Eu790Xn6B4CF1HZ0SMVNuGsF4gDIcWdH qLRQ== X-Gm-Message-State: AOJu0YwowV2c98MbCSSxBkHlghrn1Mv4R8wUov7AHhQbmN0FufzXLV2z ZGoV1UcM3RhGUV+K8EAi1eHgcY0/8oR9zt0Ep1EvNRrYK7Cv2ih7loYh0i+XG0KhE+eGZ+EG5GB BYVNwRUtDFaF/8e0E/yZOHEZUqMDgHH16m+71FCyixk1rAbFZaA56Nj/MHAigSl7l7nI5znJVxY RiFt+ceqU= X-Gm-Gg: ASbGncsiQe4yWMe9njwo9e71mgf8be5b0BqIuTwV6180kRy3e+Ku/2a/dhg6FkUqLRH bVjYmTSxcUIwkRHhP9w/17e+lVEctum5468ObU/aqrpGVFVb2BCFBGd1DTohTlASmk40RYRpFqS xPcj+XLKL2BdRkWv9DI2IYLEZksM84PvOunxl6WjygV2tS6j/TVgxyiaqgzovjvc9f9NWqRX1lU wBfAICboKd8rfBaz2nK6jmuyIv5khvwteX+4exIjJ7jrRt+HZq1mSYOJA== X-Received: by 2002:a17:902:ceca:b0:215:83e1:99ff with SMTP id d9443c01a7336-219e6eb3a33mr565079095ad.27.1735873451785; 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-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 GPIO 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_device *dev) pdevinfo.fwnode = swnode; ret = gpio_virtuser_make_lookup_table(dev); - if (ret) { - fwnode_remove_software_node(swnode); - return ret; - } + if (ret) + goto err_remove_swnode; reinit_completion(&dev->probe_completion); dev->driver_bound = false; @@ -1498,23 +1496,32 @@ gpio_virtuser_device_activate(struct gpio_virtuser_device *dev) pdev = platform_device_register_full(&pdevinfo); if (IS_ERR(pdev)) { + ret = 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; } wait_for_completion(&dev->probe_completion); bus_unregister_notifier(&platform_bus_type, &dev->bus_notifier); if (!dev->driver_bound) { - platform_device_unregister(pdev); - fwnode_remove_software_node(swnode); - return -ENXIO; + ret = -ENXIO; + goto err_unregister_pdev; } dev->pdev = pdev; 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; } static void From patchwork Fri Jan 3 03:04:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koichiro Den X-Patchwork-Id: 856380 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 C2A8B1AD3E1 for ; Fri, 3 Jan 2025 03:04:18 +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=1735873460; cv=none; b=jFGWIGLxn+MBwoygDAXIMgqnqcTKVR8dPF16sBeft3zYh1/t90c4IOPgFkIjCcAickzDTIaQAVQQxiGAD4wxMzAt1ZMnDK67HDQwMu4vVIF+XF1YXnYWpyIxc416q9q6KW+Dvi1ATjIrPuqE8x8CyqQDKRuJLi1H2sqrod+GGP8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735873460; c=relaxed/simple; bh=8ChtnRZwJDC04xlfJouTjNvR/nV1ghrWuZERWwclicc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pQ0e6/4dpO5s6PmB3aytkxO/FOuAyLEbDqnh7M1RaQqsPXa0opkvGtb4IOwB6x1Zxgx9cQR5BTkdZCLAfxiE1SAefxhjwd8+dRgkSNSL/vLerkfso5wqJNC1Atf77QqW39WKIpL0XrVUc1JeQrki+dDbjXDWFT+UahtYPtF6h1E= 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.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="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-0.canonical.com (Postfix) with ESMTPS id 83A2C3FA4F 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-2ef9e4c5343so26299700a91.0 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=EVyS5x9Pv6T1d3ErvlscUJzy/c3PBa8DWOeAuzB0JS7ld5f1DJNc+rrcjeSwmkFR8A 3Gy9u/mR2COtxDkZAT2a7bC0h1Yt/YiTtwzurcXdo4Kuo1dojYh7f9uauwMldh18z0P4 kjYx3UD/y8DBWDRrfPCqEK9eF31sRDhT5IX3lSZrF6a9b5h8lKrV/bMmH8+uF3PPeuJ0 Oh3w1fAbtUgRSP6fqn+TE27+UyE8xj+y1nzYCMjkiITZe2Z66WBeoXW7Vk41MptroTao 04EBcouiP58/xjD1eZmcib5OLhVqkzM7NrwWC4AXszBkLUIGPmYmjuBDw8C+QU2zQSPb eqLQ== X-Gm-Message-State: AOJu0YyY07rnntSyCg4xG41QtQnGK3naulMoO+cHSkzZH028CXzeodzR stqh5wHH0Y+9HQosbhj9/sdlZZwsfZafPmHXgkWzzK56O7pWnMGOQb7CrgU/BWw731xSGe7f92z 25IxfCznDvPJ8Uj9j9RmxB980vZVvXkHMZ1uaBr9ib7YhThCpZTIapOE78SKRGlAOvAoQZAzxk/ KENmXVmqc= X-Gm-Gg: ASbGncs4Cq9KzAi9dvQ2Z9N5YNcMMOCAMkyh6apJc+1WNxasn5bcDkSp1iE9RlYHclQ yb0aJmqMQu+UK2vK73yjF0+ZJANByYffKscpClzX4UHbSzEFr5imdb85HjssVOb4n8rCso5tU0I sNLctDntNCy6eIVsb9Ssg7awPhuniE7RkERVEKy/MydLo1xPaLlsbNFH719D3bHY7kOPsLeJ3+M trHTH+cpZKqzhl9ERIWqhQhHG0v8LzbU+oG5kJ0aAkkiK341VTSfMynew== X-Received: by 2002:a17:90b:2e4a:b0:2ea:b564:4b31 with SMTP id 98e67ed59e1d1-2f452e3db0bmr69946871a91.19.1735873453832; 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-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 GPIO 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 = gpio_virtuser_get_lookup_count(dev); struct gpio_virtuser_lookup_entry *entry; struct gpio_virtuser_lookup *lookup; - unsigned int i = 0; + unsigned int i = 0, idx; lockdep_assert_held(&dev->lock); @@ -1424,12 +1424,12 @@ gpio_virtuser_make_lookup_table(struct gpio_virtuser_device *dev) return -ENOMEM; list_for_each_entry(lookup, &dev->lookup_list, siblings) { + idx = 0; list_for_each_entry(entry, &lookup->entry_list, siblings) { - table->table[i] = + table->table[i++] = 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); } } From patchwork Fri Jan 3 03:04:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koichiro Den X-Patchwork-Id: 854928 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 AB9721B0F3C for ; Fri, 3 Jan 2025 03:04:20 +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-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) (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 E71973FAA4 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-f69.google.com with SMTP id 98e67ed59e1d1-2ef9e38b0cfso15868781a91.0 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=RwoWwFgZtpMETqMTDDnUJoL/l6aSCx51i+wA+wPy3wPLmv3Y29NV+lt0Q5alrK7/03 ia1geCTYAgAvofAd45r9oNK/wudR1u0HV09gf3sgicFunqHxeTIghIgbObOjbXFdohBr FI+9qEjmIGxGJ9ze2EhRl+qQiMSyX4EfQ3wTw5uwYxt/dnjixV3H3TNqh2k7HcDS4zd+ wmjHbsCtITRblYrqs2oupzQaH8oaGaSwxZwaBMjvCjfjmmthcJXY3Yqq9FyICUWnYVjv ktYqvYFZhJmn6LgrlXlI6otNWR8PfRqungz+Ou3unG7zul3qWrvlYr2Yoqm1V+y6YxbN Sp/w== X-Gm-Message-State: AOJu0Yzu3nLu5YxTNvq/cMAhilV8/23vk7THtINqv6rsUamErZcczSP/ BmHY89pUj+xb8r2w1CEgpXFMJJMQ51+UywfveScV/nMjGSdT2lWAyaPI0G49y6h84FwFPaSPBoC ntdTibUPZcv1p2UKJs+x/f1dkes2LLKVWZbXWpvksBcedCLKV1ibEa4WdU+2iQRqBM5pJ5s4jKC CYGGWgedk= X-Gm-Gg: ASbGncugHrvky9WL47ugAs9dQpOUmVtSWvGF9Pp0JHHm7oDQjuW4YgEEhXJGyQ5MKtg 1cNWBzQLRQzQJFMWy6B/bvM62Y+aJsEPqfvN75hPer/6T6CDB6HORD0bhBcbTWu3B58Riu7paWE NssO3XeM9VFwSQ02LGLhQ1uL3rbchPAjWivAUnwn/X5blTtB8j4M+3Zi/3r8m2MeDQjPz0rWQDX KPLr4BvKuyI+s0c/JnTFvZpu/y/b6Y4ReMqbd3IbvMVLKbiaFaT8Mic3w== X-Received: by 2002:a17:90b:3cc6:b0:2ee:aa95:6de9 with SMTP id 98e67ed59e1d1-2f452eed7e1mr71974689a91.33.1735873455906; 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-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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); } +static void +gpio_virtuser_device_lockup_configfs(struct gpio_virtuser_device *dev, bool lock) +{ + struct configfs_subsystem *subsys = 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 config_item *item, if (ret) return ret; - guard(mutex)(&dev->lock); + if (live) + gpio_virtuser_device_lockup_configfs(dev, true); - if (live == gpio_virtuser_device_is_live(dev)) - return -EPERM; + scoped_guard(mutex, &dev->lock) { + if (live == gpio_virtuser_device_is_live(dev)) + ret = -EPERM; + else if (live) + ret = gpio_virtuser_device_activate(dev); + else + gpio_virtuser_device_deactivate(dev); + } - if (live) - ret = gpio_virtuser_device_activate(dev); - else - gpio_virtuser_device_deactivate(dev); + /* + * Undepend is required only if device disablement (live == 0) + * succeeds or if device enablement (live == 1) fails. + */ + if (live == !!ret) + gpio_virtuser_device_lockup_configfs(dev, false); return ret ?: count; } From patchwork Fri Jan 3 03:04:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koichiro Den X-Patchwork-Id: 856379 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 A62271B218D for ; Fri, 3 Jan 2025 03:04:21 +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=1735873463; cv=none; b=HmuI6+F6qkDyyzVYExOrjJptcnV2eIbph0UGO1kor6iLMhxKLMagZWLPHTrtTs7QfojAVgnfruLrjWFMWfgMQjEHFYM0/8aU57aRkT5varTIU9w6sxtXvmvjRoRZ8I8lZWCBqGbUfDedm2Q6YIY4tUFUwlUJrgCna1bOrc5ow/o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735873463; c=relaxed/simple; bh=cMG1/1MMnZC5j0tafg83V1P3/epd9tHHHNaDsyBmqgw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jUEOtF+Hs8m+7T8hW1MQnxjKgrLOi6bpdnveYcSBEbz6rb2jGdI19AyAR2ir47CHQjoVDNuY/WrHW8mSF7pCEgy4TB0GB7wSY/f2QXEhFn3O+Nwwgk1nGDUhXSn0aq2o3vdT5BFTq2omYgVGRE32vOZ37uwIJXgWvoma0zxPAYM= 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.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="Kzgyafz4" Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) (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 A08623FADD 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-f200.google.com with SMTP id d9443c01a7336-2161d5b3eb5so140423665ad.3 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=BDxzOib3FcD8jA2/njDFAmBiYn5W68XN1Y3qq8xTT/4tqPyTlq9Bm63hMNeX75eHIh SSd54NAak+k3b1jj+euSXrG7dXwOloaxIFTdImZayAguI40rYteurWeGeKbemLon2zS1 jdeT1o+H1RZs1+VDNXdE5u6XkxFSzjaEVCpr2JxIBD8/AAcRJFDkvOaFAZLHkaCJoDwg pA78Tx2dWFQh1i1UgIRWA+4omujoV5Fa4DQdnALc+4xF1DBcMGyj29CbW+gACsX3WYsJ 9/cEtcVk+qtoOM5AF0LA9SkVztWdaDscnGPQW4Nh6yI0Cm5BSby5Rwy2ECKirwfPY2pE u1Bw== X-Gm-Message-State: AOJu0YxyyHOrYREMfcQpxSyrmxL7Cz966BcW0S71cVgm6/lez1InIBml v8Fn5NxnwqBf7hY8x/Wvn+nWc3vIbuGJHFGCjEKj9Q/8X6A67S6KfcDQ+3WWFyu958L6eX+objo YozNpA4B0dCBeKgF23KZO5BxUrNitOw4lAzREl1wKEwkUWmDDY+P7wS3h3VwcO9KCoRcyahQZ44 L3+hZDrtM= X-Gm-Gg: ASbGnct+6D5aaUVWP7UvIpzzpTKtJXvpjhpofT4Zf1KaWaoo0i7+q/oNJ8NXj992sBv VMi576B4rjOXVyDzsf9s8gvdBu9tHjw7b8TkZYfwJqqY4+5umW0Dbo+14Ash5f1ae+JCq9Di4Vr /mtZY9GmjBp7kyr8Qr/7ian8dBVzwy75p5cUjzMRu6mkuAa52J+gcHGhaYdR5yOJfEaYaD6dyAH gDiXoQO5T/0y/glQo6w10FGtRbbYmbKLRM3YZvrdC0phjL/dz90GG/3lw== X-Received: by 2002:a17:902:ec82:b0:215:827e:3a6 with SMTP id d9443c01a7336-219e6f1447fmr669964315ad.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-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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_sim_device *dev) dev->pdev = NULL; } +static void +gpio_sim_device_lockup_configfs(struct gpio_sim_device *dev, bool lock) +{ + struct configfs_subsystem *subsys = 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_item *item, if (ret) return ret; - guard(mutex)(&dev->lock); + if (live) + gpio_sim_device_lockup_configfs(dev, true); - if (live == gpio_sim_device_is_live(dev)) - ret = -EPERM; - else if (live) - ret = gpio_sim_device_activate(dev); - else - gpio_sim_device_deactivate(dev); + scoped_guard(mutex, &dev->lock) { + if (live == gpio_sim_device_is_live(dev)) + ret = -EPERM; + else if (live) + ret = gpio_sim_device_activate(dev); + else + gpio_sim_device_deactivate(dev); + } + + /* + * Undepend is required only if device disablement (live == 0) + * succeeds or if device enablement (live == 1) fails. + */ + if (live == !!ret) + gpio_sim_device_lockup_configfs(dev, false); return ret ?: count; }