From patchwork Wed Apr 16 09:55:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 881709 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (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 47857238152; Wed, 16 Apr 2025 09:56:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744797413; cv=none; b=qv1R1bI+gRx11Z4qNeCgjb8cVCwJ97eLnCKcBlRgfKm6br95MSMTk25EuyTyMG305MIUAanjhZ+N8yRYvU58uU+jg4eu8tvu7YYtnVdD8caCMyq1r2IdiOtZpCS58C8V5qHM0LMtRuWXqJ/JyEi56TU9wXYsLJNev/uHotZxBV8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744797413; c=relaxed/simple; bh=cX6Sn6odB3ha7kuWydmTl+RgZMLnKDiJ+oPgOg3cYJ4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gs33d4SHVq7GNqxp81emdFSYO5gLXloMGQJHIx032CBXUXvsJBkiuIv5M2zV36Yj2+/6p3RRlDT+a9Uxh0YxAaABLxyKMSGSyUp4LuApPV6GOnrGiPd8RopPKIIO/XNTTLbEyYyrmksc4cEPnI3TGgpTDRgiijMyCiXBKYi2bw0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=SFrD/OrF; arc=none smtp.client-ip=198.175.65.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="SFrD/OrF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744797412; x=1776333412; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cX6Sn6odB3ha7kuWydmTl+RgZMLnKDiJ+oPgOg3cYJ4=; b=SFrD/OrFORf4ujdPllAAnGS3MJ7WyePuBFAjlb4I3rZEwdknA3rCm/+Y sXsGnTv/M5zRYhMZKX+XvbEEA8y1+PFPERljvu3n4RJ+VhpjVuaRno7Z0 iDNGQyhkiGuzu9ytWYa0+SCTx2f2IgUFYpXkp8nuqq53d/RZdftvtj5T+ RI6Lbx2pj8TuStmCwMBsOnz/1wjP+Bw4iWDGWBacApxHl37CnmYY6kE8v Kfe7cmMB8IF+9w2a0CEg5qneyTeAYXz/xBLpx6cFan4rSpDHxzkLwzMEK Ka+QgTkqrEOy6H3KrDIdDv8VyannjRr1ATgzka4GZUY3x55OvgMSEf7GO A==; X-CSE-ConnectionGUID: K4P/5yZ2QPmu9K9Ely9xZA== X-CSE-MsgGUID: D0dJilwjSPCaEWJ+P+Dv/A== X-IronPort-AV: E=McAfee;i="6700,10204,11404"; a="63743637" X-IronPort-AV: E=Sophos;i="6.15,215,1739865600"; d="scan'208";a="63743637" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Apr 2025 02:56:49 -0700 X-CSE-ConnectionGUID: VFIrXNGOSG2+VvHVl05kxg== X-CSE-MsgGUID: O8x2L4sqSeynTnKPn+QqmQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,215,1739865600"; d="scan'208";a="131323320" Received: from black.fi.intel.com ([10.237.72.28]) by fmviesa009.fm.intel.com with ESMTP; 16 Apr 2025 02:56:48 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id E1026E0; Wed, 16 Apr 2025 12:56:46 +0300 (EEST) From: Andy Shevchenko To: Bartosz Golaszewski , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Linus Walleij , Bartosz Golaszewski , Andy Shevchenko Subject: [PATCH v2 1/8] gpiolib: Make taking gpio_lookup_lock consistent Date: Wed, 16 Apr 2025 12:55:09 +0300 Message-ID: <20250416095645.2027695-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250416095645.2027695-1-andriy.shevchenko@linux.intel.com> References: <20250416095645.2027695-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 There are two ways to take a lock: plain call to the mutex_lock() or using guard()() / scoped_guard(). The driver inconsistently uses both. Make taking gpio_lookup_lock consistent. Reviewed-by: Linus Walleij Signed-off-by: Andy Shevchenko --- drivers/gpio/gpiolib.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index b8993d2d31e1..7d9cc1a9c535 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -4363,12 +4363,10 @@ void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n) { unsigned int i; - mutex_lock(&gpio_lookup_lock); + guard(mutex)(&gpio_lookup_lock); for (i = 0; i < n; i++) list_add_tail(&tables[i]->list, &gpio_lookup_list); - - mutex_unlock(&gpio_lookup_lock); } /** @@ -4427,11 +4425,9 @@ void gpiod_remove_lookup_table(struct gpiod_lookup_table *table) if (!table) return; - mutex_lock(&gpio_lookup_lock); + guard(mutex)(&gpio_lookup_lock); list_del(&table->list); - - mutex_unlock(&gpio_lookup_lock); } EXPORT_SYMBOL_GPL(gpiod_remove_lookup_table); From patchwork Wed Apr 16 09:55:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 881710 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (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 1BEC7220693; Wed, 16 Apr 2025 09:56:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744797411; cv=none; b=F333oORO/kanAQbo7AStlaiTC/TflfeDGpx3zb7r6GBlyI6O5gMPtf9D4IDJ0Lo1c8qiQK6mXK/xCKy34z9NwfgYWxT/6arW790J3IkL9PTGP830IBiWLtkhMbyqRqA4sYjDWqAERRukunoRg15QZyKgTpcVa0YEVkdNSC8uNik= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744797411; c=relaxed/simple; bh=jM3zMslPPIXuVTKq8981oZBoABPe9Aim2U0yoP3KeMM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bBjJ20zOvfVGs/MoiRCrioJ0sansbFED4XWZufWkx17LSHPIJKGJn6CzVzMlAcuYHLbGoIZ0sW+PrE4QbUWxPndGNZIMZRlYeqp6XElBstE1E7TJeByHNbrLVq1x9y8APdL5l5yTCE1ZDghueeoqR3I12VSr1GvFXvB8plFtSw0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=ePr4+aqV; arc=none smtp.client-ip=198.175.65.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ePr4+aqV" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744797410; x=1776333410; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jM3zMslPPIXuVTKq8981oZBoABPe9Aim2U0yoP3KeMM=; b=ePr4+aqV/eIelPTvCPVJKUplhOV3evfvtepdxkx0eYisExggsPZ22p+P 2og17Rpv7khod7Tlh5BMbw3YMknBsWfAvnbE+iyaX6J5qBUIiNx1cUysY gOpPl5BTbKDLotYQigzWTSzE9QKuuP0CxZGaSUzu7s6/YEfM9I3UH79eN kvFlTtH8yun7fN7n1zYWLLMvUoA0j/v6fW9ujmnPvXuwt9LQ6T1OO3O4C U3VHFp6O6TDL7KyJnc6gxDLSmgjuD5xwm3fFXiwHtjH0msEHy+NcfMJIJ YrcXvbnb6dHurlwDjRIt4DRQSJerrnKLGzOR7s8Bp7R8+hS6x3zjhcINi Q==; X-CSE-ConnectionGUID: e0xVhAczQuyMVfHPTc3P9w== X-CSE-MsgGUID: 2HecljEiQXyK+XlXiKn9Aw== X-IronPort-AV: E=McAfee;i="6700,10204,11404"; a="63743631" X-IronPort-AV: E=Sophos;i="6.15,215,1739865600"; d="scan'208";a="63743631" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Apr 2025 02:56:49 -0700 X-CSE-ConnectionGUID: 5AZSd5pXQP+Sterdh35KGQ== X-CSE-MsgGUID: xJt+oloqQVels8WV3F4SIQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,215,1739865600"; d="scan'208";a="131323318" Received: from black.fi.intel.com ([10.237.72.28]) by fmviesa009.fm.intel.com with ESMTP; 16 Apr 2025 02:56:47 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id F0F8522A; Wed, 16 Apr 2025 12:56:46 +0300 (EEST) From: Andy Shevchenko To: Bartosz Golaszewski , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Linus Walleij , Bartosz Golaszewski , Andy Shevchenko Subject: [PATCH v2 2/8] gpiolib: Convert to use guard()() for gpio_machine_hogs_mutex Date: Wed, 16 Apr 2025 12:55:10 +0300 Message-ID: <20250416095645.2027695-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250416095645.2027695-1-andriy.shevchenko@linux.intel.com> References: <20250416095645.2027695-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The driver uses guard()()/scoped_guard() for the rest of the synchronisation calls. Convert to use the same for gpio_machine_hogs_mutex. Reviewed-by: Linus Walleij Signed-off-by: Andy Shevchenko --- drivers/gpio/gpiolib.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 7d9cc1a9c535..d6a161dd737d 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -888,14 +888,12 @@ static void machine_gpiochip_add(struct gpio_chip *gc) { struct gpiod_hog *hog; - mutex_lock(&gpio_machine_hogs_mutex); + guard(mutex)(&gpio_machine_hogs_mutex); list_for_each_entry(hog, &gpio_machine_hogs, list) { if (!strcmp(gc->label, hog->chip_label)) gpiochip_machine_hog(gc, hog); } - - mutex_unlock(&gpio_machine_hogs_mutex); } static void gpiochip_setup_devs(void) @@ -4439,7 +4437,7 @@ void gpiod_add_hogs(struct gpiod_hog *hogs) { struct gpiod_hog *hog; - mutex_lock(&gpio_machine_hogs_mutex); + guard(mutex)(&gpio_machine_hogs_mutex); for (hog = &hogs[0]; hog->chip_label; hog++) { list_add_tail(&hog->list, &gpio_machine_hogs); @@ -4453,8 +4451,6 @@ void gpiod_add_hogs(struct gpiod_hog *hogs) if (gdev) gpiochip_machine_hog(gpio_device_get_chip(gdev), hog); } - - mutex_unlock(&gpio_machine_hogs_mutex); } EXPORT_SYMBOL_GPL(gpiod_add_hogs); @@ -4462,10 +4458,10 @@ void gpiod_remove_hogs(struct gpiod_hog *hogs) { struct gpiod_hog *hog; - mutex_lock(&gpio_machine_hogs_mutex); + guard(mutex)(&gpio_machine_hogs_mutex); + for (hog = &hogs[0]; hog->chip_label; hog++) list_del(&hog->list); - mutex_unlock(&gpio_machine_hogs_mutex); } EXPORT_SYMBOL_GPL(gpiod_remove_hogs); From patchwork Wed Apr 16 09:55:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 881707 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (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 897D2238D3B; Wed, 16 Apr 2025 09:57:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744797425; cv=none; b=Oa9+08X7pLqFbOVmlo7oIdShmVO6FV+WS1qEOzpZWtKKOKfPCFdgw5BTszuqRakuLAudZV8nz0Y11ebKwpdPgNtqt5t79hh1nA8dRigX5JB/WPiNMK6WkgA/4X7Bep7XFFL6U3a0LL8qfBcJSVXxmXLHKhw8iIOV9Ye4HpEfeAs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744797425; c=relaxed/simple; bh=mEAJfKTxnmGzJXvHWnS2NYncYtqJHnPpta/r+gzwIPs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fyk2uINgb31OUTmpLCuORX3tsBTcYCSuHSNZZnZ77IGH2BtDYvl6XPvCV6Lnv2M6IX567b+Grk0aWlFWVLB0LK3EwME9entrWkNewpXi3N+x9ERabkI1vfFbyc0DLyLXElf7a0ApLGD/BwfNfUFEUtChQ47LMSlWijhe9+hvkkw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=ROlvuxnt; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ROlvuxnt" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744797424; x=1776333424; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mEAJfKTxnmGzJXvHWnS2NYncYtqJHnPpta/r+gzwIPs=; b=ROlvuxntvXKSL1/hiBq3W4CyZQgoLGqWgT4CFZq4VTqDGl+o2ch70bC/ YA5B9cMotIn4svwTYJtdnzVDGqAQaErWDHrd/kCCiGSxBNnC7L9dBZuwY s6HFgQkVDvcBkQB2tY+/I3n1B0htPzQJIa/K6E7iHsCt0g1AJvzHiqhhG dpPE2+j6pkWDZ6QdAjRcbvtRoZPZybmQtQvRsbBeylsynTnFvxh/IDMpi gi7dhqlSHwE1zTB75wuXT8i138DYVtFwfZ27NMtBJCbJRl7crni8NIWLj zzCSbGdkXLRCe3OZOYUvsU3YT7M6kdvfXCt7cin9G1ctplLKIJbX7Olr1 A==; X-CSE-ConnectionGUID: pSiP2UXTRpSAtVIH8QebFw== X-CSE-MsgGUID: 6/bqMS6jSj6kF09SWfw8DQ== X-IronPort-AV: E=McAfee;i="6700,10204,11404"; a="50144312" X-IronPort-AV: E=Sophos;i="6.15,215,1739865600"; d="scan'208";a="50144312" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Apr 2025 02:56:50 -0700 X-CSE-ConnectionGUID: yBzS+E0vQfC69+F+OVYF6A== X-CSE-MsgGUID: A8m+Yg6oTR2Gza+q5loj5A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,215,1739865600"; d="scan'208";a="135259304" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa003.jf.intel.com with ESMTP; 16 Apr 2025 02:56:48 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 09339481; Wed, 16 Apr 2025 12:56:47 +0300 (EEST) From: Andy Shevchenko To: Bartosz Golaszewski , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Linus Walleij , Bartosz Golaszewski , Andy Shevchenko Subject: [PATCH v2 3/8] gpiolib: Print actual error when descriptor contains an error pointer Date: Wed, 16 Apr 2025 12:55:11 +0300 Message-ID: <20250416095645.2027695-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250416095645.2027695-1-andriy.shevchenko@linux.intel.com> References: <20250416095645.2027695-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Print the actual error when descriptor contains an error pointer. This might help debugging those rare cases. Reviewed-by: Linus Walleij Signed-off-by: Andy Shevchenko --- drivers/gpio/gpiolib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index d6a161dd737d..7f8e8c33207e 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -2443,7 +2443,7 @@ static int validate_desc(const struct gpio_desc *desc, const char *func) return 0; if (IS_ERR(desc)) { - pr_warn("%s: invalid GPIO (errorpointer)\n", func); + pr_warn("%s: invalid GPIO (errorpointer: %pe)\n", func, desc); return PTR_ERR(desc); } From patchwork Wed Apr 16 09:55:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 881706 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (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 1F0BF24502C; Wed, 16 Apr 2025 09:57:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744797426; cv=none; b=TR3GrGtZLesFvNARk1ssh/bfwmhV5Ey9b27f14cO5sAwwAbZi9JKnBDy7VMUZzzEF5NgU+8rc5qIEsii1MyGTHEdiMjGnnrtD6Le5AyDlGaYBuV7QhrL00EEWC1LKmZeKzUB0NYJMJ5wBeuq8jpuC7MqztdlJNWeOPyjf0d+KAI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744797426; c=relaxed/simple; bh=IhlW6Wu/axGKaX+oNbFSThpIYklJNdJRYZAvQ7gbYRM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S8onnFFZ3pAlumb7ox1zigg5W8irEC9vk0kMH/UNeoAO6DJSJs1whKBrpZ2nngfg/lrAYIodE9sh0jl/4TMWeTiBpy4Drc+3U/W/7YT6dF91a8dboRpt6OaZI3caF4d02mAHCv6NvD7Ea9s0j5zs9zsWc2ivX++3qry1+agF/6U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=l9o4X4tO; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="l9o4X4tO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744797425; x=1776333425; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IhlW6Wu/axGKaX+oNbFSThpIYklJNdJRYZAvQ7gbYRM=; b=l9o4X4tOXTd9Gu7J3wK7fRw0IJ/c5buwOAiF/v3GfR8xP9n6z1oBef8j 2+CT+D9iUasKh9dG3iH0H0xxfnGOU1huTvqnSDPaMVTYyMecUl9JGiEMQ hnOGynhsibwvRUOl9x2dcTS1O5nrDx0cYIkeDKvD4O7/BdgFZf+s/Mw5o 6KN+d8gzUKzBeBjPZwWBUQl0PNrUvlbMVuaL3cM7zCfJniIq6Tdj7MsR1 8/r2+ma7oVqCaCkib93phlmbLiUeQFslGQWLAHE741iDTOg9kuoXZKfjm UgcXointAaCGxhmiLiSUMLhRwXJXYRkA3HplZH9fzlBfGiuAT2CLX9nFr Q==; X-CSE-ConnectionGUID: xjl9qwioSM+4VJmTS1ubIQ== X-CSE-MsgGUID: Ro9Wx6SCQDW6Gge3lJUqIg== X-IronPort-AV: E=McAfee;i="6700,10204,11404"; a="50144321" X-IronPort-AV: E=Sophos;i="6.15,215,1739865600"; d="scan'208";a="50144321" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Apr 2025 02:56:53 -0700 X-CSE-ConnectionGUID: YnZxj4g0TViZQhQ3EmCFQA== X-CSE-MsgGUID: Jm0I/7j+ST+0IbGooQjPCA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,215,1739865600"; d="scan'208";a="135259321" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa003.jf.intel.com with ESMTP; 16 Apr 2025 02:56:51 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 2A409741; Wed, 16 Apr 2025 12:56:47 +0300 (EEST) From: Andy Shevchenko To: Bartosz Golaszewski , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Linus Walleij , Bartosz Golaszewski , Andy Shevchenko Subject: [PATCH v2 6/8] gpiolib: Call validate_desc() when VALIDATE_DESC() can't be used Date: Wed, 16 Apr 2025 12:55:14 +0300 Message-ID: <20250416095645.2027695-7-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250416095645.2027695-1-andriy.shevchenko@linux.intel.com> References: <20250416095645.2027695-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Call validate_desc() directly when VALIDATE_DESC() can't be used. It will print additional information useful for debugging. Reviewed-by: Linus Walleij Signed-off-by: Andy Shevchenko --- drivers/gpio/gpiolib.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index ad2e68f66500..3f3371e427fd 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -421,11 +421,8 @@ int gpiod_get_direction(struct gpio_desc *desc) unsigned int offset; int ret; - /* - * We cannot use VALIDATE_DESC() as we must not return 0 for a NULL - * descriptor like we usually do. - */ - if (IS_ERR_OR_NULL(desc)) + ret = validate_desc(desc, __func__); + if (ret <= 0) return -EINVAL; CLASS(gpio_chip_guard, guard)(desc); @@ -3982,13 +3979,10 @@ int gpiod_to_irq(const struct gpio_desc *desc) struct gpio_device *gdev; struct gpio_chip *gc; int offset; + int ret; - /* - * Cannot VALIDATE_DESC() here as gpiod_to_irq() consumer semantics - * requires this function to not return zero on an invalid descriptor - * but rather a negative error number. - */ - if (IS_ERR_OR_NULL(desc)) + ret = validate_desc(desc, __func__); + if (ret <= 0) return -EINVAL; gdev = desc->gdev; From patchwork Wed Apr 16 09:55:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 881708 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (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 E46F5238D3B; Wed, 16 Apr 2025 09:56:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744797415; cv=none; b=FzMCnU0Ycsm5u6JsJN8GS0MTcVxfv2w1M9WeyJWmb6K+QS2SdiNwqCbvOFAdlWs9kTr7jZYw3Z8CmMfsSXVrJzN/A8JQHT1+pY+5+P4tkTjvWP3qvvTyrrfj4GRtkh+F1SJamS0zkXVS6gGEveKOjZAWeUVFgUCibmCU4h7x+Q8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744797415; c=relaxed/simple; bh=gLZPBb6tb6Bvp+DJa0qiKRTWFJZiDmh1mf/1qkujX5k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KCSFs/sw9v60PkP3hjoVewefxC+Y0N2dJiRwGenbaU3XKxbgoJLbaCvN/lQMTRSrDtgca/HZ94xchqSKDeW4zf51RvmjGqGiPiFgb31do2tHS3qu6S5MGupLdQFQ0Z59+KBagObSAL60Pg3y2GnD0EPU8S1g914y17opuc9Lo0Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=NtrunQMv; arc=none smtp.client-ip=198.175.65.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="NtrunQMv" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744797414; x=1776333414; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gLZPBb6tb6Bvp+DJa0qiKRTWFJZiDmh1mf/1qkujX5k=; b=NtrunQMvOrEfhcnSoFc/MzjkAXXYJAcTy02quE0DASZE/clU1XEiJw0j 1a6kLg0+kS+XtD9YouekgUvECsavNn1zCnrkBYMn9mgrZGfk6jI4FTWH9 WAqwa79FFAAmM73MbR3KGFmO59wwf0tcc4bhvFsPwSlHWWzY2Qs/s8EAU kGRaqGvfhIEgtf2x4XVXTMv1tECcpbkq0jw4uX7OVollyxyyiIH5ILELH QukAeL8+3gbfsZyhpgeAFBm975GGA10LQg9G/mkTNJE6iPFZjdhKVcNdY kah0Udeo2EJQyDxraPrmFUyKcycg5289EGDvIlaty+U/+NOfyLu+0UJJI g==; X-CSE-ConnectionGUID: ZKOdaeSyT/SkXIIepuwd2A== X-CSE-MsgGUID: riVQAYtsSRWGVM6I8rYbxw== X-IronPort-AV: E=McAfee;i="6700,10204,11404"; a="63743647" X-IronPort-AV: E=Sophos;i="6.15,215,1739865600"; d="scan'208";a="63743647" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Apr 2025 02:56:52 -0700 X-CSE-ConnectionGUID: 4xBP6AaZQgqnJZzDvQ1BRA== X-CSE-MsgGUID: KX3wyM63RrSyLnk3GOZE1Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,215,1739865600"; d="scan'208";a="131323324" Received: from black.fi.intel.com ([10.237.72.28]) by fmviesa009.fm.intel.com with ESMTP; 16 Apr 2025 02:56:50 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 3FB288D1; Wed, 16 Apr 2025 12:56:47 +0300 (EEST) From: Andy Shevchenko To: Bartosz Golaszewski , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Linus Walleij , Bartosz Golaszewski , Andy Shevchenko Subject: [PATCH v2 8/8] gpiolib: Remove redundant assignment of return variable Date: Wed, 16 Apr 2025 12:55:16 +0300 Message-ID: <20250416095645.2027695-9-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250416095645.2027695-1-andriy.shevchenko@linux.intel.com> References: <20250416095645.2027695-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In some functions the returned variable is assigned to 0 and then reassigned to the actual value. Remove redundant assignments. In one case make it more clear that the assignment is not needed. Reviewed-by: Linus Walleij Signed-off-by: Andy Shevchenko --- drivers/gpio/gpiolib.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 7a669218e42c..c787c9310e85 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1015,7 +1015,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, struct gpio_device *gdev; unsigned int desc_index; int base = 0; - int ret = 0; + int ret; /* Only allow one set() and one set_multiple(). */ if ((gc->set && gc->set_rv) || @@ -1040,11 +1040,10 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, device_set_node(&gdev->dev, gpiochip_choose_fwnode(gc)); - gdev->id = ida_alloc(&gpio_ida, GFP_KERNEL); - if (gdev->id < 0) { - ret = gdev->id; + ret = ida_alloc(&gpio_ida, GFP_KERNEL); + if (ret < 0) goto err_free_gdev; - } + gdev->id = ret; ret = dev_set_name(&gdev->dev, GPIOCHIP_NAME "%d", gdev->id); if (ret) @@ -3068,7 +3067,7 @@ int gpiod_direction_output_nonotify(struct gpio_desc *desc, int value) */ int gpiod_enable_hw_timestamp_ns(struct gpio_desc *desc, unsigned long flags) { - int ret = 0; + int ret; VALIDATE_DESC(desc); @@ -3101,7 +3100,7 @@ EXPORT_SYMBOL_GPL(gpiod_enable_hw_timestamp_ns); */ int gpiod_disable_hw_timestamp_ns(struct gpio_desc *desc, unsigned long flags) { - int ret = 0; + int ret; VALIDATE_DESC(desc);