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: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; }