From patchwork Tue Dec 24 06:08:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koichiro Den X-Patchwork-Id: 853920 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 18FBD1632DF for ; Tue, 24 Dec 2024 06:15:02 +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=1735020905; cv=none; b=m5gBpQilpYoPG33BX90LjUmAdFLFg1cXRqhjq0B4QBllgoH6JKaSF0HwMweXGSwBaeQLAn2SC/n/fh2VZ9u89l6sM6KoSDT+B90BdsynJ7x+BHYtPM+Qjx3HTzOZII5gSfdstXJZZp5mzpszC9no9ktAFuoYERWdjCS3AKU3xno= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735020905; c=relaxed/simple; bh=mWlR0OxQrvSUFNUtPMcxJKvGUyR3rD+rrQEear9gnso=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dtJ7MA0TGoi7RwTwGHH1SwgHn2HkHSgMeIOx/mnO6QYG3YVUYcF6p3WgHZCnipBTmBiKKUsrRXtYoE3e+650QeY6ZgQ2ph3sYmS5c2rdV3tVMd2nVQL4isZEXU2UI05vfyjniiRYj+8V7S2j/lC9f1Z+fCWt8klM94J+HiHBrkM= 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=Pom6JTnG; 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="Pom6JTnG" 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-0.canonical.com (Postfix) with ESMTPS id 665673F8D9 for ; Tue, 24 Dec 2024 06:08:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1735020510; bh=J7bcT4SjPneUM9tLI8tVI4MMK9t1QaJRrnEAS0MFCK0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Pom6JTnGWWC7HMeMmCcxZGOnkfVW3s3Ll98b0L9K8MfychNUxrFM/Ifi3wdClqaaP H6wcGhiHlPKjj0Qu0Cg2bIvLLWv/57s9Xn+kPZMPhApeB7dMj9RFDuUAt9sHpmb4ds xvkhje5keU04er1b35dFm6bhAIia1GsCbnmnPjLPcnrV7j3wXdb47UapVNitjmkfw9 0SYXZoNUex1teSjors9pNeTgujJcGfaTGFkEYt3cBwKIgWEjmvQb7nsVguRSgvT7s1 OQBviCdg0Scp98isdZ1CbQavGZf0+uTRs3NOsI5zZfmW00blCVq7W1HZoS+oagx9ys PP6lU2l9PMBJQ== Received: by mail-pl1-f198.google.com with SMTP id d9443c01a7336-216311faa51so43845405ad.0 for ; Mon, 23 Dec 2024 22:08:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735020508; x=1735625308; 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=J7bcT4SjPneUM9tLI8tVI4MMK9t1QaJRrnEAS0MFCK0=; b=gYhdhBfwMJg8vgxn7Ulfkn0YHrNzWoXI3YUy0HAeCqlWfqbuEc83ZL8NA4PGq95q74 uQZ2FvQEAWV3hXQ9D1Rjwu1ZUcvCn+jVGSSraErCmD4+i0U2EvKRzb6S/k/bQO7P/z+W TJuckx5xceDq9UkrIxr7pP213lCj1ARPt20tvlrH3n+aOeLczZJKJzif8ut5anpzimgC K/n5FSivBZxVVncVuygRItCOX4qj7oRSUEbIedYqKDe89Qjc0A5ZxdAiC3Mmbxck3nLg mdVDl6bEpISpjHFBYKUBMSbdJ37VMx47znqMDG80Nv+tZX8RVBPhimIVeLAHx8olLc2p 6GNQ== X-Gm-Message-State: AOJu0YxOKvwy6Z6W9g3FvIQtiZycKg4fPZiWpBDGgoDOjHEFBeAM8lPY oTUCfremZYo2nfZv5pLuEsBoYWM/n3hRp2GIqL/9JWsS4bOgN3K3cUDU4iyd8FK8Uv64+uQviFl 8OJbvb3g2AkpjJIlIHBDCWQyRScs4ti/LKhi+nxplZ5QNU3M66ylo3j0V+wbh1bFJAZS1Okm56/ 6jd9F3ZrA= X-Gm-Gg: ASbGnct+eu66C8wo3338WkhYHogxrv9GLtPh4w9NbOMRj3ykuTj37LwZzpWpSe7fW1S soAEW2V49NO0EfCZTGXDqJ0HJF7wSBEgyPTCfu8uxUgHAgcldKgJQ05NNdJZV/kn1kghl/QgZyT AAGRiF6RriYq193pWkd6obwhneIuDh6SGwwz1UeK/DDnCrWpSLnNG7if1vFdxmix5E0OskAavPM uMVup9q1IbmVWgIhSnId+7u7J1YvMnnsMR8lv4FhsLY3cJ6f7859BtSEg== X-Received: by 2002:a17:902:f643:b0:216:59f1:c7d9 with SMTP id d9443c01a7336-219e6d599famr267049215ad.19.1735020508139; Mon, 23 Dec 2024 22:08:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IFLN1UqghuGICJDVgUY2gGTq2Ksry/nt4WmM/Ul1mkB0GEW6R7/cUrqNpweSDb4QJBSIZM/4g== X-Received: by 2002:a17:902:f643:b0:216:59f1:c7d9 with SMTP id d9443c01a7336-219e6d599famr267048945ad.19.1735020507861; Mon, 23 Dec 2024 22:08:27 -0800 (PST) Received: from z790sl.. ([240f:74:7be:1:7315:8eec:aecb:29a4]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dca02a8csm82262235ad.269.2024.12.23.22.08.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Dec 2024 22:08:27 -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 1/4] gpio: virtuser: fix missing lookup table cleanup on probe failure Date: Tue, 24 Dec 2024 15:08:16 +0900 Message-ID: <20241224060819.1492472-2-koichiro.den@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241224060819.1492472-1-koichiro.den@canonical.com> References: <20241224060819.1492472-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. Ensure the lookup table is removed whenever the probe fails. Fixes: 91581c4b3f29 ("gpio: virtuser: new virtual testing driver for the GPIO API") Signed-off-by: Koichiro Den --- drivers/gpio/gpio-virtuser.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/gpio/gpio-virtuser.c b/drivers/gpio/gpio-virtuser.c index 91b6352c957c..a81e15a4b807 100644 --- a/drivers/gpio/gpio-virtuser.c +++ b/drivers/gpio/gpio-virtuser.c @@ -1509,6 +1509,7 @@ gpio_virtuser_device_activate(struct gpio_virtuser_device *dev) if (!dev->driver_bound) { platform_device_unregister(pdev); fwnode_remove_software_node(swnode); + gpiod_remove_lookup_table(dev->lookup_table); return -ENXIO; } From patchwork Tue Dec 24 06:08:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koichiro Den X-Patchwork-Id: 853334 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 8C74414EC46 for ; Tue, 24 Dec 2024 06:08:33 +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=1735020515; cv=none; b=f/kkBWojh26iddHh8ZNps0pZitR5Cw7k6leH0Vn2ERRYCvXcP1wro6PP5nCrDFe5nztqsL55i0b+s5IPbxJfs09KN+CfUgNatf5uE2MO9+lecDkkPKNaUjVjpSTD2qsE1ys8wUtCJE0AXZEUz3NQ3YoJEsBltkusSFhSOb/zjek= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735020515; c=relaxed/simple; bh=jjODd6E2sPP2H56rJvCjdNTs3EWlZ5GLaJEVp5Rahvw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=q9PEUhP9fT7XRSMmSCQ47+k08DtrxL53lMLv26IxYxe6PPlPqGTIm94zS9gBzvZQaTfTPlY23OX98vkkD5R17C4B0WdnbuzLleyUpa0VYfLUpZISfs3Hjc1lCDF020+o2NzWObeBZKbaGR2pI5Zv67dIQRAglEHZl9d0CKc4sx4= 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=kF8sOVHs; 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="kF8sOVHs" Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) (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 5FCF640F34 for ; Tue, 24 Dec 2024 06:08:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1735020511; bh=5ZW/PEFng4FvP68UML2UsRGI1J55AyoUOdPTFqJICxQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kF8sOVHs1BMxPjkGcZVmjz+Hz7WckZOD/SFknZIM0fq+EN5eYkKnhoWZH8+OocUcr 2O7TR2fkV5k9jUjG7g1ShHqf6XRy3XoDbzGB/gGhA9Zl8NiVCInZKtj3Wio4wcWURS psHP220cOQxQ4Ew+sshLbXfEw6Nb1DbvZdomT39rAdIbEhID5v/X4bmAiCRawidA6p c9BqfL9UsNUavUhOV34q83uT/LhmTMDbfKWZl21n3GgkBN9MzQRJ9OH1DPWhMJo163 onK18BTp2hw3tUm7FEec46joOKjzVjKEZIQ/OZlLGLviTCtsvFYAHHMJ1J0iPbNK4r NwXGalTr5mGNw== Received: by mail-pl1-f199.google.com with SMTP id d9443c01a7336-2163c2f32fdso78148165ad.2 for ; Mon, 23 Dec 2024 22:08:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735020510; x=1735625310; 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=5ZW/PEFng4FvP68UML2UsRGI1J55AyoUOdPTFqJICxQ=; b=ORa6YFhNREMPY832wnFQy88kaHFQItKoQREhntjFZIHoboUj3POBwfIVB24N5I7T/w zsLmRzG72jdR0BfOQKc83+ZOyRfqWdmF739KmSD0vp38oappqVzCOpzrD5UCrD00x04Q 8felkY+HnUqlBaQ4B2+mHVMtLDH8n6iNrFMSXRvmKo3XPbPDNC9ZbEwkA01E+AeoPKSx jjkozzXmeh3dYeAoK5EF81Cwr40zaSyn84BCTxzWZzRedgUjLFnTq4SIjE34kSozsOSM Wup6FCj3jbHyQZM8uxD417tzqzRnIrsozwo8KAptScPsVNRNfuf0j9XLu9lLiojlWUJT 2xZw== X-Gm-Message-State: AOJu0Yw0Q91nsVw4oDJJD3tAvhUQcgkeF4SJTD39iZMUR3tn0CXGke0q 4zCjzPhyj74i2LA5q4UV71mdi7SM/ScS2S+mBtbderLOcG/V14mFh2BHCfN5FOGnslHOVUB+/Fg cPEN1qgFwXXrB7EjWD4I++cFcGEWG/jf5eqxvruuIZQSH59MDhKTR7F44LSULwclxnqs27vBiEG O14QI8K7o= X-Gm-Gg: ASbGncsR1bvHicKbDJE8JbypS4uDuwDtWm7oXTF24A/eWwgVCqJfUrdNMBTgOysUoVl djJWtJZm3klHVniBoP2w1hyMnttWbqnJZuFD6J37T6Gx2WH2CQLtQbgR/WHMSyKuukLv8ymf3Qf NSuPzYexrLX2qg7UK76S6SmByqV+yQu7NaG0eJruX9sxnGBfgrJdRUEcI5g/9Trko51nt4ovGe6 QvTBe142NEBkPsTmMK0YbkkQhFZCPa3U096OFzpTO5JsTc18tRTOjTQLw== X-Received: by 2002:a17:903:24e:b0:215:5625:885b with SMTP id d9443c01a7336-219e6f28552mr222598315ad.52.1735020509990; Mon, 23 Dec 2024 22:08:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IHRFfC2tCT/DKU5w4xQITd/O1aq7SCBrIByFjq8+m/b55ZwwD1PTlzcCJJEDwXI5t8nIy4sBg== X-Received: by 2002:a17:903:24e:b0:215:5625:885b with SMTP id d9443c01a7336-219e6f28552mr222598135ad.52.1735020509727; Mon, 23 Dec 2024 22:08:29 -0800 (PST) Received: from z790sl.. ([240f:74:7be:1:7315:8eec:aecb:29a4]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dca02a8csm82262235ad.269.2024.12.23.22.08.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Dec 2024 22:08:29 -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 2/4] gpio: virtuser: fix handling of multiple conn_ids in lookup table Date: Tue, 24 Dec 2024 15:08:17 +0900 Message-ID: <20241224060819.1492472-3-koichiro.den@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241224060819.1492472-1-koichiro.den@canonical.com> References: <20241224060819.1492472-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 a81e15a4b807..c9700c1e4126 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 Tue Dec 24 06:08:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koichiro Den X-Patchwork-Id: 853333 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 7C8AD15575C for ; Tue, 24 Dec 2024 06:15:03 +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=1735020905; cv=none; b=UArTzWy+gkF1ztmLMA8OWSzFkZT05upO0+hynMX8WGvlGXQIfPms2JJAL03nakiLwED/xlfyZfAgC/NX+2DabY5xz3BY04AAQf4TAHl1SRawFJeXq0kASPP/9tfBKN6xxDFvI9u1o/5q1GMK0vbYNtGysb4WSDH1JUgOl+mBnpg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735020905; c=relaxed/simple; bh=cMvDG0BueSdf+zIzu9X8jCotHQSn0EUGYP+uv29jHzM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JgaWfLn1zWhrIc0zZ7n9P+QVKswfkMAdUZAmHanKFxuurqlHuSfYyCH2jd0dvhpCgBq80cV6Fat263H96EXFtbI+iSHbj7Eox1dqZz25DFptZUN7tPpA4hB66gP3ygsPZnQlLtwaxpKU47Ekfp5fW4YiN+aNU9wOXrVOKtnxWPc= 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=p/uTPPVv; 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="p/uTPPVv" 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-0.canonical.com (Postfix) with ESMTPS id 828F33FA4F for ; Tue, 24 Dec 2024 06:08:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1735020513; bh=bvUHNb8XemzT0n3pS2sxj6xTXk/hDt3GgdHjNnvpT8o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p/uTPPVvYPYo6XRC16m2ZeXxECkusBA0KzGt3s3SwXkC9pHKA724T8lSaaimErdem Epkk3zoJwb71o2hicGuXOwMatorkPsI2RoQN09GL0/L4AoWxwLbqbW9VLRotVdnKOj es8YzHqcNzQjhLRXSjf5jOThYN6aVxWyUpi9ZjE60l8myIVjXRfZgFo+QiR44G6YxI jJ5vmN7JtIaF36PmrWRe+5VyHhcmGbhI/bXN3VUocs5vnTHmihGvmUJWrUx/IjU5pL UnDfHJinJ767G4EnmIvReM4bKsjAy88GzUW2LPEmJaCcMUtUye68iSCtkIXwpXl0sg +ySPO9XsoLQNA== Received: by mail-pl1-f198.google.com with SMTP id d9443c01a7336-21681a2c0d5so41317385ad.2 for ; Mon, 23 Dec 2024 22:08:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735020512; x=1735625312; 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=bvUHNb8XemzT0n3pS2sxj6xTXk/hDt3GgdHjNnvpT8o=; b=n+jhKNneHS7T/d1yObEOOSTN/0Gu0NKxFbKLmV9wPCDcvSwmpy39i7GVsHc2c4mVwK 6jEx2CdFGJJxrPRfx0kiIjKRepj6hVvoiKF2KNL64Eb6XG0jg0TcVgbMO+eagGLiDYyD t7KYh5AGiPyUroS9xwhIcfvrBmVd87EMDGhNRawTJNMzqlKk7gZ9+85A3zelZPqolPGV 9y0KHIMpwTd+XDlrxHPF/fvUk45j/VDLbpaVGLLQTefrG4EHf3cXbtx1Ep8vf1jBtyBo q1mq1XnVJUxwsDTgKGA6fSo/sfmV1Q21k3nUDxXNaslrMAllUB9h92KDzvKpyaPimZ6W 0EhA== X-Gm-Message-State: AOJu0YwQRMhAUxN9kw4mgPLJwjXejCs138bnmtjvWudKFx/sG0hTOIvi KFHSfIJS52x781reuvj4IGdG7UrEsf8ahEoHG6zBfvm0lkImjbLVeLWNddVRxPa52bhEt4tGzPZ hUGsXvvBtpE2CypMvjRYJYCsSq4aAvm4W0NZMtEv2W9hD6gmsZeMfvckTKlLwLECEcxALFA87UE 8R2d6ZvhY= X-Gm-Gg: ASbGnctrqcfVghzmwZyKcgYOLkbN3iKNKorb0ONzhXtrnKLPvDH1GhMmhw7H8Io+dQP lSGnsrllGxYC9ratGfVfjcu9k4LyCdzQ0OibPalpFWu4nKqXv7RUNo9f/CMEMcP4GudheRCm1Ih NEmnw5GW05BuARl+eLdFq8Y7Ig9E6inn1CbmMU+xQLW14Wnl+34MUrTbB5F/u9qm1jk8qC/btH9 /nko36hGCJK6Sd1iT++8o1OHzXwcYHGZEnt4jCKQN/jn3rKiOrnTNwp6A== X-Received: by 2002:a17:902:dac6:b0:216:59d4:40e7 with SMTP id d9443c01a7336-219e6f25e08mr151410365ad.55.1735020512088; Mon, 23 Dec 2024 22:08:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IEOAv7tCbuJma5e2bZ7olmLZeIwdxAhJgDLtIE55BW4oJwBp6hpQcck5nq7sQNTozUTn6LFfw== X-Received: by 2002:a17:902:dac6:b0:216:59d4:40e7 with SMTP id d9443c01a7336-219e6f25e08mr151410225ad.55.1735020511776; Mon, 23 Dec 2024 22:08:31 -0800 (PST) Received: from z790sl.. ([240f:74:7be:1:7315:8eec:aecb:29a4]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dca02a8csm82262235ad.269.2024.12.23.22.08.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Dec 2024 22:08:31 -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 3/4] gpio: virtuser: lock up configfs that an instantiated device depends on Date: Tue, 24 Dec 2024 15:08:18 +0900 Message-ID: <20241224060819.1492472-4-koichiro.den@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241224060819.1492472-1-koichiro.den@canonical.com> References: <20241224060819.1492472-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 existance. 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 | 49 ++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/drivers/gpio/gpio-virtuser.c b/drivers/gpio/gpio-virtuser.c index c9700c1e4126..45b8f192f860 100644 --- a/drivers/gpio/gpio-virtuser.c +++ b/drivers/gpio/gpio-virtuser.c @@ -1533,6 +1533,32 @@ 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 gpio_virtuser_lookup_entry *entry; + struct gpio_virtuser_lookup *lookup; + struct configfs_subsystem *subsys; + + subsys = dev->group.cg_subsys; + + /* + * 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) @@ -1545,15 +1571,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 Tue Dec 24 06:08:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koichiro Den X-Patchwork-Id: 853921 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 3926016DEB1 for ; Tue, 24 Dec 2024 06:15:03 +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=1735020904; cv=none; b=laBG0BswzruNDQjG72zP0X4GAyaZIeFxzyNCmMdJ1LF/Z2rBoRpfjWeY3ti954OUca44FBACOsoA9z7dgxtHWnlD9heMBGPydtv+0uq+RdkOfM44naPNVV7KEitM4JH9hbPSw0qe/HXyxAIYS6Vs21j7KCfFfIz4x6nN7HuCFN8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735020904; c=relaxed/simple; bh=kHy7+BUJB1e02uClmhERH9WN1YkLqPbGi5wICVhX5vg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KES2fqp2fS1ot/jp2RCiAQkoKV/TqZpVDecrnaDtj1q8D4M7wJHlguP9JHldQJvZPI9A/xeSmS7kZut+EByU58Iu2lIE3BD2yqQdhc9G5i+0oV8eTkYzTw45Jv4NTWyXecXwGRPS7PePvU+8oZm+h9rUO1Pi5gRSni1iuw6GnZY= 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=thUAqVfL; 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="thUAqVfL" 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-0.canonical.com (Postfix) with ESMTPS id C90193FA64 for ; Tue, 24 Dec 2024 06:08:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1735020515; bh=XGiVUUuPl1PuSOqM5OdpjxECLZKle/lzbsG6Q9QvzFw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=thUAqVfLfKiLdzcGGslSjKWQ06Fob3eZa4NWWE1xUs4v4+hLFhzqvM/pTMHk4/yo9 AHQpFZs7HN7LgaKXvywkes2VA+rV7xMLuBMDz5rs1ZV5+YodMXIvPDUBhtgFs4K4P+ PMh5T+ycFeeNPAHteuAQiB1qDZM6vqN77wnvVHQDQIwHc4np7ZOnYGHhVDIeRJtQOk pTlpcyjqtxsOHkElpOWj1VXfTSZbo2O6ZlD8Ml0W0zC/JePQd7otm+nrFOHgH8+x2J s8rSw1FnsOwH4GuZbByxSdvrLAVwS0CL4iW9tHrfSQg/dDo47sHct4q++IumWdhqns eUAQYaOi6dV5g== Received: by mail-pl1-f197.google.com with SMTP id d9443c01a7336-21655569152so44033505ad.2 for ; Mon, 23 Dec 2024 22:08:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735020514; x=1735625314; 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=XGiVUUuPl1PuSOqM5OdpjxECLZKle/lzbsG6Q9QvzFw=; b=ratu9hLJjiQlkSwPHQcflCL85IZ+DJimCHwS45zRHXmNOyHZU3zg/nGKmhn847GhRj KJHjI/ieryxzRpsupMqgTLNP424NBWo0IYMdMxluYut1uyf5+wO3dR5qGgnGVmWVJyv8 8hpEdbZZr3APU0apImPh1KwGykuQU5U6DdkUB/uy66mmmvrvYhd9cHsfAbX1HwjqWJBw 0Sgnfs6dZ3NO7U8rRbuaj5wqjs3xIU6Ny1ILDP1MxoNSJZ01Zhl4Ok8pVvdO0dCParIn E3BxTNTWiLiOcJM19W5Gyw2e7t8f5WpIwBsNZzL2HdS9kkCEnFVzCp7CBcLMlhgRnKWE dVMA== X-Gm-Message-State: AOJu0YxjTwelaCpNotUTiDlDPKQKvbWWCiNS/uEtPpPKKZzrpNk5mGvc X+14JVqHNey4eVyusypvGJ9B4sw52Ht8pTD2Z6Fr6OKw1V5AcILCpXHdYHrqq4DGCj6b41h/kn4 fD6lk6xDhHXK5BctsxCAtZFeGBltiJLf4sLZUGScgk28lr4WOetv+kNx+jbWioruWf90F4nUcG2 SyT9qbOkw= X-Gm-Gg: ASbGncuJVOBCTCxEQf8FPXlsqO/jZwQQzdWex+GVdocaDAWPWKDwxnnhTv2Cs8NMFYs BKc3VJMIF+hCxEUDpaaxZUpFUKNFJj0kP2dVL5Q1hniiCLS+yOzF3bitwIGV1UVS5XDpsWcALGq I1QheQN5W6bcmftftDZuMN9YHkDFQwOa2CrFIoiwHZHlTmAGBKMvSEL5p1Olr+grgYb5XYgm2rx +brg0eN0dmm/rYF0uasD76CoV0TkxjMbGMyh9+K3U/0tJzna758N/1Tcw== X-Received: by 2002:a17:903:2442:b0:211:7156:4283 with SMTP id d9443c01a7336-219e70c0085mr229534045ad.43.1735020514126; Mon, 23 Dec 2024 22:08:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IHkIdhAHeoj3acO0zFnRMN64v6XmMJRufdO3WywSQS/7mHeIObHyUz54Bte8ccY6fbgkqFqnA== X-Received: by 2002:a17:903:2442:b0:211:7156:4283 with SMTP id d9443c01a7336-219e70c0085mr229533855ad.43.1735020513818; Mon, 23 Dec 2024 22:08:33 -0800 (PST) Received: from z790sl.. ([240f:74:7be:1:7315:8eec:aecb:29a4]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dca02a8csm82262235ad.269.2024.12.23.22.08.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Dec 2024 22:08:33 -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 4/4] gpio: sim: lock up configfs that an instantiated device depends on Date: Tue, 24 Dec 2024 15:08:19 +0900 Message-ID: <20241224060819.1492472-5-koichiro.den@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241224060819.1492472-1-koichiro.den@canonical.com> References: <20241224060819.1492472-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 | 50 +++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c index f387dad81f29..2bd9552c4e1f 100644 --- a/drivers/gpio/gpio-sim.c +++ b/drivers/gpio/gpio-sim.c @@ -1027,6 +1027,32 @@ 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; + struct gpio_sim_bank *bank; + struct gpio_sim_line *line; + + subsys = dev->group.cg_subsys; + + /* + * 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 +1065,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; }