From nobody Wed Apr 8 01:25:49 2026 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EBCA53C13E3 for ; Wed, 11 Mar 2026 08:59:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773219589; cv=none; b=sb/18DhKXjiu/FajukeM1s1wIkrKKXKNyWdwpsHBRKNI4dLiTKvtmKtd2WXzmMNi098NLIy8THDPwU5VEujzFEN2/2JFiaoQSZz42+tDOXjLROwIGpOCBoQJvj03GyIR/QLjmYAnXUbSTbWGdZqTlmt4kH5aO6VALoLGvR9tsYc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773219589; c=relaxed/simple; bh=4HRczWwf+idD5YLdFOtxKhZolR3r0ySv0HVp0ZcqQKk=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=V9aeNcb4LzSYCdYxTiDNum4VilS+dagFKueG8pI3JUTZySiLNLbzc7KGHID/r/FCholOFXIb/C6LvBC6clTWzca4M/kDmDmKwFVUti5Ro4emF+27h4yLmPsmEu1OCyt1UOZH8KniZOUez6H1LcMvvag3VWTt7GXHpz2mNkk+xgI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=FANwrZ/o; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="FANwrZ/o" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4838c15e3cbso125089135e9.3 for ; Wed, 11 Mar 2026 01:59:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1773219584; x=1773824384; darn=vger.kernel.org; h=user-agent:content-disposition:mime-version:message-id:subject:cc :to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=zkM4bGnCAz6GhYRTPSestmLq7baCdGcGpIWjoPgO3YA=; b=FANwrZ/oL5qdO7k7z0jekmidjT9UZ1vmNnRoFJKLBA7NOGqljCA4SW1cB80O5HfM5O Fa3oeZN29LItLaZfXgQrWe5RB2hDiRVuzf4K0gWD5v8b5P8T5aw+6DrQf9e6OAWpEHn0 2o7TAgLTGWgRoT/AZAsXOl6Y1SQdgfpLU8MWs80lwZbz91AtTmTE16DESNaxUNJ4CxQx +JYahmdBnvr/el6ZYqcrqJcFvrbqOAW9AnneawxdfKt+mPZC5tKWW6HG1mHpsrIn7TA6 mJuE3+qfhwOmdYkfMV9tr9++kLoG4iyTu4LvSX/YNxJogpn4k5fSsZoYA4sVE7HQ/L33 EiPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773219584; x=1773824384; h=user-agent:content-disposition:mime-version:message-id:subject:cc :to:from:date:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=zkM4bGnCAz6GhYRTPSestmLq7baCdGcGpIWjoPgO3YA=; b=bS6IAdNgEyVBmckZT5Z1rK5oujns82+UgtNRD61x5wIOulCzJw5cqcMEYzlLdq1O9R jdmfWi17zDekjlBTpMH7rnqGIv7glNWvwbhrLZ8Fo/m4F5BjpPOGkLYo7QUmY7g7XARS XYU5IqiMPctuhmxnRFYdt2hzrrDt0CLh2ocIq8tSdxhubDlOMI2smJvmxTjD13x/aCUK bj22FgLlqmM8Dv/oGOPPnR4Tzd5crKUYFPNH52iE7EH/2sxD7sWYCvMilBV9TijH0y3T UHxQVURo0ECNc+YZfa4+Tzb2LRu+7JgQvd0DbVhRGvFOriqgmyoFT1NRPvNiW3yfHnvC 4XrQ== X-Forwarded-Encrypted: i=1; AJvYcCUnPeg5gP5orSe0wjaYm4UY4gerO3GjJKnKn2JuSA7irq8FwjGXm4KezZpgNJMIT4W07XsYxRDjiX+61iU=@vger.kernel.org X-Gm-Message-State: AOJu0YwiTewa3+8qBzgM4tJywzoml9x3Chenjflae/alfaG01Vs1ig/0 svLHROJUe1t3JtjNMkc7eDoNwaT05jKa8MjIuRsccqqqDybOhU1MzyLPhfaHgdMWBbI= X-Gm-Gg: ATEYQzyh1nWf2/4JOZHT5kxMtNQyIMmq9ER+AUpNAproXfV4jwuiICzgXZfkTCVGCqc rBFrN2HLRVtBP+q6jFPdxo670N4yKAr3IJXcB886g1NcLrdZSbFX7RefZcI9DvNMu34Abm8LrfY 3jJgCJ7b51QyCzoi5yQKzSi/NTTeQsUqibIgqkduSAgote9mDduWwIrx4dGrbUON+QT6fxkrepE A5rGtSmodk0wg0dk5mIkG74RZUFnFny5JeyU3Axe6xVqguuIeiOEbyBQ2QwEiLFPFKU4g+Zt82v u6UBc7cEu6UwsN6xph2I1vdk4d/xRd6WpQVy+DcnIFoLyW7Gjt250mnJw8aBvWqG9AUp8aVIxn1 pHL635xOEck4gPMjaO5ZKkNof46BjA8giFK/OLZvuR+uR9+b6rjysLOSyoBC7lN9PVScL644apW WophwdJM177KI2MHGlr3PcqIerbyBaVTN88zK95whywx+zukcvFYL8ThE= X-Received: by 2002:a05:600c:1f10:b0:485:3f58:da6 with SMTP id 5b1f17b1804b1-4854b0a55efmr32579185e9.2.1773219583737; Wed, 11 Mar 2026 01:59:43 -0700 (PDT) Received: from r1chard (36-228-122-64.dynamic-ip.hinet.net. [36.228.122.64]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-35a03005f7fsm1492215a91.15.2026.03.11.01.59.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Mar 2026 01:59:42 -0700 (PDT) Date: Wed, 11 Mar 2026 16:59:26 +0800 From: Richard Lyu To: Linus Walleij Cc: Bartosz Golaszewski , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Richard Lyu Subject: [PATCH v2] gpio: max732x: use guard(mutex) to simplify locking Message-ID: <20260311085924.191288-1-richard.lyu@suse.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline X-Mailer: git-send-email 2.51.0 User-Agent: Mutt/2.2.13 (2024-03-09) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Convert the max732x driver to use the RAII-based guard(mutex) macro from . This change replaces manual mutex_lock() and mutex_unlock() calls, allowing the chip lock to be managed automatically based on function scope. Refactor max732x_gpio_set_mask() and max732x_irq_update_mask() to improve code readability. This allows for direct returns and removes the redundant 'out' label in the set_mask function, resulting in cleaner and more maintainable code. Signed-off-by: Richard Lyu --- v2: - Sort includes alphabetically as requested by Bartosz. - Add missing include . - Link: https://lore.kernel.org/all/CAMRc=3DMfioFeJD=3Ds_w0PQ2jD4npHr9y7nMh= u3bXUwrr0D8roPgQ@mail.gmail.com/ --- drivers/gpio/gpio-max732x.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/drivers/gpio/gpio-max732x.c b/drivers/gpio/gpio-max732x.c index a61d670ceeda..257742f95949 100644 --- a/drivers/gpio/gpio-max732x.c +++ b/drivers/gpio/gpio-max732x.c @@ -10,14 +10,16 @@ * Derived from drivers/gpio/pca953x.c */ =20 -#include -#include -#include -#include +#include #include -#include #include +#include +#include +#include +#include #include +#include +#include =20 /* * Each port of MAX732x (including MAX7319) falls into one of the @@ -207,22 +209,20 @@ static void max732x_gpio_set_mask(struct gpio_chip *g= c, unsigned off, int mask, uint8_t reg_out; int ret; =20 - mutex_lock(&chip->lock); + guard(mutex)(&chip->lock); =20 reg_out =3D (off > 7) ? chip->reg_out[1] : chip->reg_out[0]; reg_out =3D (reg_out & ~mask) | (val & mask); =20 ret =3D max732x_writeb(chip, is_group_a(chip, off), reg_out); if (ret < 0) - goto out; + return; =20 /* update the shadow register then */ if (off > 7) chip->reg_out[1] =3D reg_out; else chip->reg_out[0] =3D reg_out; -out: - mutex_unlock(&chip->lock); } =20 static int max732x_gpio_set_value(struct gpio_chip *gc, unsigned int off, @@ -329,7 +329,7 @@ static void max732x_irq_update_mask(struct max732x_chip= *chip) if (chip->irq_features =3D=3D INT_NO_MASK) return; =20 - mutex_lock(&chip->lock); + guard(mutex)(&chip->lock); =20 switch (chip->irq_features) { case INT_INDEP_MASK: @@ -342,8 +342,6 @@ static void max732x_irq_update_mask(struct max732x_chip= *chip) max732x_writeb(chip, 1, (uint8_t)msg); break; } - - mutex_unlock(&chip->lock); } =20 static void max732x_irq_mask(struct irq_data *d) --=20 2.51.0