From patchwork Fri Jan 3 14:18:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koichiro Den X-Patchwork-Id: 854925 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 C20C91FA826 for ; Fri, 3 Jan 2025 14:18:45 +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=1735913927; cv=none; b=RPUGG8cjBXQa991KSbytKzTy2FD9IViIe4UeftCr3KL8jDWEx+LpJD6QSehBTQz8Nl8+JjmpGb6fBCgE1FR8RL2hQqLL2/W6s8N+8/mgJdhC3h3qBnceT8xUbtNT8GRP+bQQKg7FqUGiSv8V3PfvKs8qA5gYKjR/4oeNDt6YlSQ= 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.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="Y0bE/gw7" Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id E46433FAD1 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-f70.google.com with SMTP id 98e67ed59e1d1-2ef6ef9ba3fso17456984a91.2 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=kCccUhJXR80ZijuvlHmoOXFpbQOqUjVpJXh9gju+yUmA7WfohFAxMgJKBsLMQ9C/be 6sEJXDLy0D6AwQPTPPWc7TomGR7JvePsPkcV11CeSaY4hVdDtK1YXKOsy3Ytzvdx1qJZ jGGuCHBuhgXP0a8dDE0TzroGoiiMzL1sEqvK48EVF9cr4i0TO5kURXuTShNRzsN3CakJ O5w5a68IbCS2QTXdUFn3hYUW//6bEOLFDxQPdlE/TKH8FK2bssK56ywDFLJhMygYKHfT DxGr1kjZUXv/4uOCqwy4lP+qEbfcQd/db/Xyb261Yuq8f+eE5fEuBEE/S+DFP1GCl4u3 u9vw== X-Gm-Message-State: AOJu0YzInWiMdic+nYuKlvqJSvDhjSi7ON5rGznfZPxjckyLFd9joWvB qlvybdUpebxvABgddINSPWEdL0w/xCkHnxHtGHyuPSUiRdt/KzsiAt+gx0tSKuVE9h0Meh/gkWI ZzWOV3iUK5Id9iI6Dkr5gYf0sJ1o8U6bIgGzjoDV8MY7kp5b9KlQuLKnGo4AKu8Elf2rnYeAWGG Ufuyobgug= X-Gm-Gg: ASbGncswOAmuEEQU1sWBnat1iE+csIO57R88sB551sGe+G0RGbYG5Qy4XmYBh5mL7j6 JAHRgfELcJgoF5GnZOXpzdV950Jjl/wWswpI0w0Y4xlu1AxCr9cYdttYOhCNsRLGtXEsaccQCrl 8N9RyhzhdIxUu4/w2BkJxQDQy6iFcHympz56q8L67ugTOIS1OZ0BxuPPRlSp/hbcdzGE09ol/7G yXw7H+kBMUt2ATeAnOx1fbpa2NZG+98iOanRTsdvK4DvOXPXfYnTcba9A== X-Received: by 2002:a05:6a21:158d:b0:1e0:d89e:f5bc with SMTP id adf61e73a8af0-1e5e046155fmr80534295637.11.1735913922148; 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-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 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 = 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 14:18:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koichiro Den X-Patchwork-Id: 854924 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 CE0EF1494B2 for ; Fri, 3 Jan 2025 14:18:50 +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=1735913932; cv=none; b=ptqjqMh0KWSBrfCvGxhO8eJGgXcWogab2kapvaV3eX/uDaktaGWCX4Yx5hn6lv4fsEHvPXtRg1z01wQNHDD4jigbvrbWgM2bMx2Ik/EUsQ3wxZxAHEb9q40lvkLzzBM4DuNmNU8W8H0RnFPsH8BzrvknKMz7B2Ikzo7MCQ6QRm4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735913932; c=relaxed/simple; bh=cMG1/1MMnZC5j0tafg83V1P3/epd9tHHHNaDsyBmqgw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KGUmKRPmijjUJFdRIwn6BWjeeoad71EBOmTQVtsWnMPJlLUnwdpMVtZIfhL0sHsTsDwVMN7Wyl4MOy3/pwhGQc0Y7Hi2k4ZwtGTkmwjuW+nr2gMyt4Z9PYOyT2S7c1QT3E3n40RswvQ9OoH0hdm8a9gaxrMsCizb/LuFwtiZqdo= 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=db69reB7; 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="db69reB7" 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 5D8CC3FAA4 for ; Fri, 3 Jan 2025 14:18:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1735913928; bh=KnRRrmEz3ZlIIsMVIhLEqcdV5rbJka1OKmEC4NqPpMo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=db69reB7u9ioH1WH+sENpsbvmEmrFV4VQjO0gWmVw8/nAEnWLi9oWVTCg2WJ1lu7O 5z2pilh6p3jbmMhhWUNnLEWNXBNYMTio2bPDCW+TiqRCJiEZYfFN3oPRc/PMqy6+RJ xoopsDMjDs+CGbXO+svjXt5spfiIpWQJ+CHIqE7TGlaqtcIUiPzE10LIN95VLDHltH BZRoydzGoEwhJYZuuwecDsZeWxBKoaHVI6gIFJzmDeJmAL9c7SpRQX9dcIuHR3kp9u 7oHbBiLW5iOXxgKhhTrp8CS+mqVUQJ3Yxa6GtdPVLanAKkOT+0/gK+IPQIVY6m+y2Y lnhFs/pcH+jqQ== Received: by mail-pj1-f71.google.com with SMTP id 98e67ed59e1d1-2ef9204f898so16737135a91.2 for ; Fri, 03 Jan 2025 06:18:48 -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=WCBhoI/CP6S8MYMbtZFtRfRGPznSSVo++Kqa+PfABH53GhRXVcvllvaFkEph+/JFJM AEnkykt0PVOajakIdcOeIxOmwdSv1BifT29WadJm3iOrDDX2PtuXjU5kTew6kA8hyeB7 S4mK0oc5Flzjld383e3VChOnSdrLQFjA4WPaQJB2gbkHTR/ANJBUaNI7I7MsSlBJ3/ae 0s69VrQty+DVLr1T1waODQvaqQHjXa7ZaoXUGNg4pPpTUeYGrBH1Wor/EaXOJDo+hti5 kxrAt+yTjBCPhHkOmJp5qSv3vY1E1J+/ZaiMCqvdUcXyhZvHjVEa6zwLS6N1baL63mxL L+ig== X-Gm-Message-State: AOJu0YwjkGEgDbhO1xnI3BbUpArdwViq9M6U+YFjPo2GLwQPXaIEewqQ lkjy4ntg53LZ3q4plYVyMKoAuZzcseceLPc6Ju5zgAnh1o2S85jEfE1nLkxiWSmgGniFJ1n29e+ hM4U0kp5Zj6S1Uk/GF8h3PlBuKBMpHhtdM0nguPbIjXUIGlgptiU+pt1iCoVHc8XT5g/u6zVNLm oeC4LFwBY= X-Gm-Gg: ASbGncuQ4nJmr8qhiAwMm8/ybnj/w3v/S7f35+8W6HyzJWP+b88i0sMlLOA1K+4mK3v HKu6yDNNNzBSlcBdXTMf9siBL5j4y/gdyOA5RYcX3mMjI5yqr9pI3O9tbB+pYp2swOZCL0nncwh lVMheXL6XaWzxzaJEeCx6xMYYj8tGThhPqDiS/eVih4PWeg73ex9MIxdXFX0cWuKADPI9YDvTR6 /PU2IVhuTq0xPztszYo4yljMEDqsVT7RCz9DyO329g8lBQ8xMl3xHRQpw== X-Received: by 2002:a05:6a00:ac5:b0:726:41e:b310 with SMTP id d2e1a72fcca58-72abdec84b4mr60827623b3a.12.1735913925732; 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-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; }