{"id":2232124,"url":"http://patchwork.ozlabs.org/api/patches/2232124/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-gpio/patch/20260502210354.160439-1-m32285159@gmail.com/","project":{"id":42,"url":"http://patchwork.ozlabs.org/api/projects/42/?format=json","name":"Linux GPIO development","link_name":"linux-gpio","list_id":"linux-gpio.vger.kernel.org","list_email":"linux-gpio@vger.kernel.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260502210354.160439-1-m32285159@gmail.com>","list_archive_url":null,"date":"2026-05-02T21:03:54","name":"gpio: twl4030: Use guard(mutex)() over manual locking","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"30d90e1be6cfa13069771c48cc1f1af6fca6b6b7","submitter":{"id":93193,"url":"http://patchwork.ozlabs.org/api/people/93193/?format=json","name":"Maxwell Doose","email":"m32285159@gmail.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-gpio/patch/20260502210354.160439-1-m32285159@gmail.com/mbox/","series":[{"id":502551,"url":"http://patchwork.ozlabs.org/api/series/502551/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-gpio/list/?series=502551","date":"2026-05-02T21:03:54","name":"gpio: twl4030: Use guard(mutex)() over manual locking","version":1,"mbox":"http://patchwork.ozlabs.org/series/502551/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2232124/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2232124/checks/","tags":{},"related":[],"headers":{"Return-Path":"\n <linux-gpio+bounces-35987-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-gpio@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=nQpkw0Sj;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c0a:e001:db::12fc:5321; helo=sea.lore.kernel.org;\n envelope-from=linux-gpio+bounces-35987-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com\n header.b=\"nQpkw0Sj\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=209.85.160.42","smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com","smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=gmail.com"],"Received":["from sea.lore.kernel.org (sea.lore.kernel.org\n [IPv6:2600:3c0a:e001:db::12fc:5321])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g7L4M4thTz1y04\n\tfor <incoming@patchwork.ozlabs.org>; Sun, 03 May 2026 07:04:03 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sea.lore.kernel.org (Postfix) with ESMTP id CDFDA3009F94\n\tfor <incoming@patchwork.ozlabs.org>; Sat,  2 May 2026 21:03:59 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 1181B3845C1;\n\tSat,  2 May 2026 21:03:59 +0000 (UTC)","from mail-oa1-f42.google.com (mail-oa1-f42.google.com\n [209.85.160.42])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id 649D12DF13B\n\tfor <linux-gpio@vger.kernel.org>; Sat,  2 May 2026 21:03:57 +0000 (UTC)","by mail-oa1-f42.google.com with SMTP id\n 586e51a60fabf-40f1ffba6a0so2429496fac.0\n        for <linux-gpio@vger.kernel.org>;\n Sat, 02 May 2026 14:03:57 -0700 (PDT)","from linuxescape.lan (23-88-128-2.fttp.usinternet.com.\n [23.88.128.2])\n        by smtp.gmail.com with ESMTPSA id\n 586e51a60fabf-43454951a95sm6073821fac.7.2026.05.02.14.03.55\n        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n        Sat, 02 May 2026 14:03:56 -0700 (PDT)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1777755838; cv=none;\n b=hUNaKEWl1X4zY3GWY9jlR68x7hEUmo5cFO4QOESwJVhYf4Y/5+zf9nYZzF5L5mlXrO+OqpUVbP1ecuowRz2dazPp8vTcbWuQuZ0FXGRKMXOm+wbacxpGP91DPmCnUq3BpQYKOvthzqjZAOIymFUmzWiVfMtxZO2t+q0+bjZT+u8=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1777755838; c=relaxed/simple;\n\tbh=lZd9s9yoPsQUriY4xkanImtClh6pgHtvv7FRMhtvNXU=;\n\th=From:To:Cc:Subject:Date:Message-ID:MIME-Version;\n b=fx4fC1ET0xts3eLuF1iqOmR9159gyppSURsTacqFQ3gGP6dTJpiHlQ2wSKx4gHTteK9t+GIcba/vn41snZ4YLX/x1zfERu2UQjN6WWGWQgTeZmsde5ctLUWPLkP+F0w1Vk2C9Q6BmScJ5SjgZ+Kbp1mRak656SBGWilAsrVVFEc=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com;\n spf=pass smtp.mailfrom=gmail.com;\n dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com\n header.b=nQpkw0Sj; arc=none smtp.client-ip=209.85.160.42","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=gmail.com; s=20251104; t=1777755836; x=1778360636;\n darn=vger.kernel.org;\n        h=content-transfer-encoding:mime-version:message-id:date:subject:cc\n         :to:from:from:to:cc:subject:date:message-id:reply-to;\n        bh=Rx4mDW/25vd+W+emY9Z3Sk1SnuGW0v8LhZC0rkW6q2o=;\n        b=nQpkw0SjlpND0ViXAcuq7u1VJv1Y7kWUrsjPv9RYh6W3lDg339Wjk1Fm9lzsJhQb3l\n         bMH3t2OAVgUoKqCp9uiIfqh9pYqR8Fu7P4ViXBEV1i9anzCOl1qsd17rgRsJvAJT592S\n         6ye6Xpdn4uP4Uay+EykpHS58Ha3ZUc4pplcvArg13Jxi1mulMmGZ/q45PGBTDA8HkyvI\n         ldFa9NNa82xcHUEYGS9SVcT54pWHBO7cEWieZp7ghIQeCJ8AlJkcHbWXcNmE3WF757R/\n         A8Ar2SJBdMxhj7TCsLBvwd+PD+Fg6CfGIePZEvje9u6dmjSiC5NqNa2V4WDXgvj9B0K1\n         TCeQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=1e100.net; s=20251104; t=1777755836; x=1778360636;\n        h=content-transfer-encoding:mime-version:message-id:date:subject:cc\n         :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date\n         :message-id:reply-to;\n        bh=Rx4mDW/25vd+W+emY9Z3Sk1SnuGW0v8LhZC0rkW6q2o=;\n        b=Fe9kKbLyWlj6mCwv3huaOhlmS4CZs8HgeXfM5JsvbYmAiB/AxpAhx+L4qslohNgpbM\n         4IUA0dCrg8c59bmpNdiOswvnrQcAoazMCObfhQheJThsDo8UrmqkDQadEZukhMU5t+xC\n         +X/opljHxf8sVylB+if2kO83nIpjvYPRbkD2Rrr9qbT7NFpP0RICT28/gHl4q/4dIzK/\n         fvsmxWYIVNHylrmzPiAldnQZYtdbZjGteOciUqZsPCLa945L0+983F3ucpLBPdNwfvJr\n         XhexA5pcpPbRDv8LzF19bLYVuNxuEbYUVEAMuyFzEbGXXxw7msl1q4BtvFPlbwPJPD3H\n         k+yQ==","X-Gm-Message-State":"AOJu0Yy7NBkzP6AHWX6iRMU1zVSlDrp8woVZzO+dx9T/CvuAuFYM+cbM\n\tl27cM11ImD+bCx5oDxUbxT4XQA8YyMg4N8oVEe+px4DQg6MiJIfMdO+x","X-Gm-Gg":"AeBDieu7ON0CjRtVIQqTnOxspjOdSqjcIWjufqf75q12culgbkgowyUPKdn03HKszkd\n\tq6HeB4DzJjILJq2in+FGSsXgRUTxgz0Aa9SWQ84GPuo6tiXUlWy5rZ9KXU6c4Rs/1kr15EuXzxV\n\tm3/3s1Yc26OvcenbU7QQd9CUw6eWwRLy/JywowvfC1qRmdRUU5WSFj0eTL+26f1JDOUT2HeQaqo\n\tr+GjcAqKxu6n/J9+JbVP8ma5VcsKlxoFNyoXCRPd2C/bodAh9a0UFG7WqTJ7WBnQlOmQy/7ORiA\n\tynPkqFP8Voob6Y2w84tldcpXHzMEumZZEMSlj9Oi2HA2YuhL8mpC2rGXLi0NNTmNhR9v02TN75P\n\tcLMCMxRUBDoFlCdu/knaffz8JQPZWsjSAEFligPs/FVKeCcdfJMP5Kp1qWeDeRtoDyKrE4c95p0\n\tiKVFNxOnXAZI0nNRVgqwCn0CsCS2O4C2f54r2bubsXAlpw6uttwM86MZuJOAW4JR819azYBEpOD\n\tmjudFM=","X-Received":"by 2002:a05:6870:9a26:b0:42e:49e1:e511 with SMTP id\n 586e51a60fabf-43476296ccdmr2427036fac.33.1777755836349;\n        Sat, 02 May 2026 14:03:56 -0700 (PDT)","From":"Maxwell Doose <m32285159@gmail.com>","To":"linusw@kernel.org,\n\tbrgl@kernel.org","Cc":"linux-gpio@vger.kernel.org,\n\tlinux-kernel@vger.kernel.org","Subject":"[PATCH] gpio: twl4030: Use guard(mutex)() over manual locking","Date":"Sat,  2 May 2026 16:03:54 -0500","Message-ID":"<20260502210354.160439-1-m32285159@gmail.com>","X-Mailer":"git-send-email 2.53.0","Precedence":"bulk","X-Mailing-List":"linux-gpio@vger.kernel.org","List-Id":"<linux-gpio.vger.kernel.org>","List-Subscribe":"<mailto:linux-gpio+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-gpio+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit"},"content":"Replace mutex_lock() and mutex_unlock() pairs with the RAII macro\nguard(mutex)(). This keeps the driver up-to-date with the latest\nfunction macros.\n\nRemove now-redundant gotos and goto labels which will maintain\nreadability. In addition, replace some gotos with direct returns where\nappropriate.\n\nUpdate certain control paths to make them more suited to the new\nlocking.\n\nSigned-off-by: Maxwell Doose <m32285159@gmail.com>\n---\n drivers/gpio/gpio-twl4030.c | 69 ++++++++++++++-----------------------\n 1 file changed, 26 insertions(+), 43 deletions(-)","diff":"diff --git a/drivers/gpio/gpio-twl4030.c b/drivers/gpio/gpio-twl4030.c\nindex a851702befde..df17f9c08817 100644\n--- a/drivers/gpio/gpio-twl4030.c\n+++ b/drivers/gpio/gpio-twl4030.c\n@@ -23,6 +23,7 @@\n #include <linux/platform_device.h>\n #include <linux/of.h>\n #include <linux/irqdomain.h>\n+#include <linux/cleanup.h>\n \n #include <linux/mfd/twl.h>\n \n@@ -209,7 +210,7 @@ static int twl_request(struct gpio_chip *chip, unsigned offset)\n \tstruct gpio_twl4030_priv *priv = gpiochip_get_data(chip);\n \tint status = 0;\n \n-\tmutex_lock(&priv->mutex);\n+\tguard(mutex)(&priv->mutex);\n \n \t/* Support the two LED outputs as output-only GPIOs. */\n \tif (offset >= TWL4030_GPIO_MAX) {\n@@ -227,30 +228,29 @@ static int twl_request(struct gpio_chip *chip, unsigned offset)\n \t\t/* Configure PWM OFF register first */\n \t\tstatus = twl_i2c_write_u8(TWL4030_MODULE_LED, 0x7f, reg + 1);\n \t\tif (status < 0)\n-\t\t\tgoto done;\n+\t\t\treturn status;\n \n \t\t/* Followed by PWM ON register */\n \t\tstatus = twl_i2c_write_u8(TWL4030_MODULE_LED, 0x7f, reg);\n \t\tif (status < 0)\n-\t\t\tgoto done;\n+\t\t\treturn status;\n \n \t\t/* init LED to not-driven (high) */\n \t\tstatus = twl_i2c_read_u8(TWL4030_MODULE_LED, &cached_leden,\n \t\t\t\t\t TWL4030_LED_LEDEN_REG);\n \t\tif (status < 0)\n-\t\t\tgoto done;\n+\t\t\treturn status;\n \t\tcached_leden &= ~ledclr_mask;\n \t\tstatus = twl_i2c_write_u8(TWL4030_MODULE_LED, cached_leden,\n \t\t\t\t\t  TWL4030_LED_LEDEN_REG);\n \t\tif (status < 0)\n-\t\t\tgoto done;\n+\t\t\treturn status;\n \n \t\tstatus = 0;\n-\t\tgoto done;\n \t}\n \n \t/* on first use, turn GPIO module \"on\" */\n-\tif (!priv->usage_count) {\n+\telse if (!priv->usage_count) {\n \t\tstruct twl4030_gpio_platform_data *pdata;\n \t\tu8 value = MASK_GPIO_CTRL_GPIO_ON;\n \n@@ -264,11 +264,9 @@ static int twl_request(struct gpio_chip *chip, unsigned offset)\n \t\tstatus = gpio_twl4030_write(REG_GPIO_CTRL, value);\n \t}\n \n-done:\n \tif (!status)\n \t\tpriv->usage_count |= BIT(offset);\n \n-\tmutex_unlock(&priv->mutex);\n \treturn status;\n }\n \n@@ -276,10 +274,10 @@ static void twl_free(struct gpio_chip *chip, unsigned offset)\n {\n \tstruct gpio_twl4030_priv *priv = gpiochip_get_data(chip);\n \n-\tmutex_lock(&priv->mutex);\n+\tguard(mutex)(&priv->mutex);\n \tif (offset >= TWL4030_GPIO_MAX) {\n \t\tWARN_ON_ONCE(twl4030_led_set_value(offset - TWL4030_GPIO_MAX, 1));\n-\t\tgoto out;\n+\t\treturn;\n \t}\n \n \tpriv->usage_count &= ~BIT(offset);\n@@ -287,9 +285,6 @@ static void twl_free(struct gpio_chip *chip, unsigned offset)\n \t/* on last use, switch off GPIO module */\n \tif (!priv->usage_count)\n \t\tgpio_twl4030_write(REG_GPIO_CTRL, 0x0);\n-\n-out:\n-\tmutex_unlock(&priv->mutex);\n }\n \n static int twl_direction_in(struct gpio_chip *chip, unsigned offset)\n@@ -297,17 +292,15 @@ static int twl_direction_in(struct gpio_chip *chip, unsigned offset)\n \tstruct gpio_twl4030_priv *priv = gpiochip_get_data(chip);\n \tint ret;\n \n-\tmutex_lock(&priv->mutex);\n+\tguard(mutex)(&priv->mutex);\n \tif (offset < TWL4030_GPIO_MAX)\n \t\tret = twl4030_set_gpio_direction(offset, 1);\n \telse\n-\t\tret = -EINVAL;\t/* LED outputs can't be set as input */\n+\t\treturn -EINVAL;\t/* LED outputs can't be set as input */\n \n \tif (!ret)\n \t\tpriv->direction &= ~BIT(offset);\n \n-\tmutex_unlock(&priv->mutex);\n-\n \treturn ret;\n }\n \n@@ -317,10 +310,9 @@ static int twl_get(struct gpio_chip *chip, unsigned offset)\n \tint ret;\n \tint status = 0;\n \n-\tmutex_lock(&priv->mutex);\n+\tguard(mutex)(&priv->mutex);\n \tif (!(priv->usage_count & BIT(offset))) {\n-\t\tret = -EPERM;\n-\t\tgoto out;\n+\t\treturn -EPERM;\n \t}\n \n \tif (priv->direction & BIT(offset))\n@@ -328,10 +320,7 @@ static int twl_get(struct gpio_chip *chip, unsigned offset)\n \telse\n \t\tstatus = twl4030_get_gpio_datain(offset);\n \n-\tret = (status < 0) ? status : !!status;\n-out:\n-\tmutex_unlock(&priv->mutex);\n-\treturn ret;\n+\treturn (status < 0) ? status : !!status;\n }\n \n static int twl_set(struct gpio_chip *chip, unsigned int offset, int value)\n@@ -339,7 +328,7 @@ static int twl_set(struct gpio_chip *chip, unsigned int offset, int value)\n \tstruct gpio_twl4030_priv *priv = gpiochip_get_data(chip);\n \tint ret;\n \n-\tmutex_lock(&priv->mutex);\n+\tguard(mutex)(&priv->mutex);\n \tif (offset < TWL4030_GPIO_MAX)\n \t\tret = twl4030_set_gpio_dataout(offset, value);\n \telse\n@@ -350,8 +339,6 @@ static int twl_set(struct gpio_chip *chip, unsigned int offset, int value)\n \telse\n \t\tpriv->out_state &= ~BIT(offset);\n \n-\tmutex_unlock(&priv->mutex);\n-\n \treturn ret;\n }\n \n@@ -360,21 +347,19 @@ static int twl_direction_out(struct gpio_chip *chip, unsigned offset, int value)\n \tstruct gpio_twl4030_priv *priv = gpiochip_get_data(chip);\n \tint ret = 0;\n \n-\tmutex_lock(&priv->mutex);\n-\tif (offset < TWL4030_GPIO_MAX) {\n-\t\tret = twl4030_set_gpio_direction(offset, 0);\n-\t\tif (ret) {\n-\t\t\tmutex_unlock(&priv->mutex);\n-\t\t\treturn ret;\n+\tscoped_guard(mutex, &priv->mutex) {\n+\t\tif (offset < TWL4030_GPIO_MAX) {\n+\t\t\tret = twl4030_set_gpio_direction(offset, 0);\n+\t\t\tif (ret)\n+\t\t\t\treturn ret;\n \t\t}\n-\t}\n \n-\t/*\n-\t *  LED gpios i.e. offset >= TWL4030_GPIO_MAX are always output\n-\t */\n+\t\t/*\n+\t\t *  LED gpios i.e. offset >= TWL4030_GPIO_MAX are always output\n+\t\t */\n \n-\tpriv->direction |= BIT(offset);\n-\tmutex_unlock(&priv->mutex);\n+\t\tpriv->direction |= BIT(offset);\n+\t}\n \n \treturn twl_set(chip, offset, value);\n }\n@@ -388,15 +373,13 @@ static int twl_get_direction(struct gpio_chip *chip, unsigned offset)\n \t */\n \tint ret = GPIO_LINE_DIRECTION_OUT;\n \n-\tmutex_lock(&priv->mutex);\n+\tguard(mutex)(&priv->mutex);\n \tif (offset < TWL4030_GPIO_MAX) {\n \t\tret = twl4030_get_gpio_direction(offset);\n \t\tif (ret) {\n-\t\t\tmutex_unlock(&priv->mutex);\n \t\t\treturn ret;\n \t\t}\n \t}\n-\tmutex_unlock(&priv->mutex);\n \n \treturn ret;\n }\n","prefixes":[]}