Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp2034376rdh; Sat, 25 Nov 2023 10:53:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IGalSL056Ja01ZVV6Scg14m0p+qQBcIeHQPSDcKcuLTPWX3qCgXHB0sPVMk2xNRdiAP9/RS X-Received: by 2002:a05:6a00:1d88:b0:6cb:d24b:878a with SMTP id z8-20020a056a001d8800b006cbd24b878amr7443460pfw.25.1700938423853; Sat, 25 Nov 2023 10:53:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700938423; cv=none; d=google.com; s=arc-20160816; b=Y+qlOp9RB7m8MaX1mC7VUpWLeDuvODg5agx1xwP27nn4G6nQ6LhAs30nCHuRtRDy++ uf9UU5eHIURLbqQaEoPmgTDvdlQ5Tx9KeDrIa6dldjXqnFGtO1snx6kmlYzq2oSmOLys Rd7nLqABI+JB4ybZ814cIiIlOMQH5PKqhtqDyQgwFW3ppNA6yF2fTtE/WKAk8wWlLBMF niIV+SsWu7RDowNOR2Cf8gisd8PPWlPJ5G6yMBI9Tvv2SHopA6krUdK5WYy0lUPhaJFG 8fwWd/sOZ45dU0pzIg4iblHlIxFgbrq01GQrQRPC2nXt6KphKImCrSCrrKT8pDExPpr5 fZFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:message-id:content-transfer-encoding :mime-version:subject:date:from:dkim-signature; bh=+PIN7PTLxMRDTTudo4CQU8eCZFkTohE+Jd4VNyt/7PI=; fh=jiL/pPwY4X4Uy1yHBXSoZDFkQirCzC1CPmusb8ubDSA=; b=GQKk1wzPfV5JxGeMwc1g1nq6Jzj2LT44+aaRs23OaJN8QA/Q5qJ81/BoDPC4nbeYhT NZMR088YaGbxsju/aJ1UwIXOEs19jild2JMirzJjQwt7sbaGsERbdQGrP32N0F2CYbQV 2fpgEd/nBdzrPH+Qpresx/e7FS0ZzycLhSEBdpnnlJVGcLGS532HDJtTGRDIzy+YE7nj SP+LFXMvAa3x/8JuxnmMFugg/euK7PjCXuQmOYVbSr/4MQa//krp3VM6p7RlPFYQvmMZ s34nQc3uYa4S02T1FAJu5QtGndXfSLgbXnYMWNqeK3OcjL28pmnsjfYooW5JvgphQovN abhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=NdhfTqOt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id 14-20020a63144e000000b005898d997f52si6321101pgu.66.2023.11.25.10.53.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Nov 2023 10:53:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=NdhfTqOt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 434B78022C27; Sat, 25 Nov 2023 10:53:41 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229746AbjKYSxZ (ORCPT + 99 others); Sat, 25 Nov 2023 13:53:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbjKYSxY (ORCPT ); Sat, 25 Nov 2023 13:53:24 -0500 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2EE77EA; Sat, 25 Nov 2023 10:53:30 -0800 (PST) Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2c8790474d5so37612201fa.2; Sat, 25 Nov 2023 10:53:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700938408; x=1701543208; darn=vger.kernel.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=+PIN7PTLxMRDTTudo4CQU8eCZFkTohE+Jd4VNyt/7PI=; b=NdhfTqOtmB5FL13vvF5QiOWC+IReMEpoGFwT8VHZlv/CYdu3n0TsJQRy4Qhwj/m8YX kNdhp/X6h+8r8Q5fLPiQ/KkL70dX+97uMNimXfPomW9W3NhtqSxzb/3/ZLIIgVBCphu8 RLv6kNNhCt1awZXztV8VUz7Fc/3Jw9U6QPaLpgcAFHsSHDeWvgcVgwOuk2KNTewDjow1 ESGZFf6x3Nk+wb0q1I4Avr2Pa0M6ZJvpEqKcGQTbh8L8pImMAVh76YGV25bkhypjThAA 2oG/JP9q2t/bnqIKMYt4DuZKxIFJ/iVjSOS+Bqz3mgqFBcigNzty9dmBgECh79oWJTqL Qbtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700938408; x=1701543208; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+PIN7PTLxMRDTTudo4CQU8eCZFkTohE+Jd4VNyt/7PI=; b=vIubu1Lt3ADzN044wRPxg2nRuZ5JSwKaHAebUfV45a49bzqHNRqUPn2CQFicGhsBBG gc5FQFjqZFyV01QPjqgxXhzAOWs8NqXlIw8UCfvZKV/9XXQZ0tsw2lbEK/iSysmdWuhw G/wbOAOftuGrg2m3/LrIF618O2Xxxi08ZFDptkxIQYGJf5ucqayWVBDdM97MyxDv4F/z 6CHnJ9F0baesPlFH+oKx7dyXMWzf1Rw2e7d/bZXOEJsQyWOtTy7HdapLkloQAgmtLhoG GsxPlmk8kvIxYSbpXi0nbIS8wAMwvyu5Aub5f3XmjmgqCbxO45v8f0k3UNlE42L3Z+Fw f2tQ== X-Gm-Message-State: AOJu0Yy3Cl0h8hXuJBF21+NyXuxuOt/4ldytO6yoHd8LXQTMwhBpYp0C IeWxSMt4876SQvdZZbUvu/8= X-Received: by 2002:a05:6512:3b96:b0:507:984e:9f17 with SMTP id g22-20020a0565123b9600b00507984e9f17mr5994637lfv.34.1700938408105; Sat, 25 Nov 2023 10:53:28 -0800 (PST) Received: from [192.168.20.11] (83-233-6-197.cust.bredband2.com. [83.233.6.197]) by smtp.gmail.com with ESMTPSA id d27-20020a0565123d1b00b0050aa7168652sm919048lfv.7.2023.11.25.10.53.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Nov 2023 10:53:26 -0800 (PST) From: Marcus Folkesson Date: Sat, 25 Nov 2023 19:57:24 +0100 Subject: [PATCH] iio: adc: mcp3911: simplify code with guard macro MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20231125-mcp3911-guard-v1-1-2748d16a3f3f@gmail.com> X-B4-Tracking: v=1; b=H4sIAJNDYmUC/6tWKk4tykwtVrJSqFYqSi3LLM7MzwNyDHUUlJIzE vPSU3UzU4B8JSMDI2NDQyNT3dzkAmNLQ0Pd9NLEohRdCzMzU0vDVKNkSxNzJaCegqLUtMwKsHn RsbW1ADu1J8BfAAAA To: Kent Gustavsson , Jonathan Cameron , Lars-Peter Clausen Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Marcus Folkesson X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=2234; i=marcus.folkesson@gmail.com; h=from:subject:message-id; bh=rpcMjVNeuk9mH60/Jcj21hZ9UYtSsdL0mp9KTGJKGxk=; b=owEBbQKS/ZANAwAIAYiATm9ZXVIyAcsmYgBlYkOikkVW2nrOJTvvxNdrBjP3lniQ1rWFtvKhI rhPW5mwXfeJAjMEAAEIAB0WIQQFUaLotmy1TWTBLGWIgE5vWV1SMgUCZWJDogAKCRCIgE5vWV1S Mru3D/9wYfUN54XDUMDx8bY+yD8nRyvgjGeIiJIiEyiiMMfyAHlRpM36n8Z9BvvA5z8MeCZHiB8 jF4+CfgnuGrDbdsu5f8bLcS2YR5K8rvk6rarGDdOB9j+nvLXKekbtZ6NRTWaR5N+xga0Aa+2kDF r7WkTi9IPRxSlVQcuzC4cLkBP/jnK+ydeVVI2Fl9WTJsnyH9GuoVa+XnfoTvdtd7S0Y9hWd0hZs g4LLDmC8yXNQzKcGDgCS7qNukc3KK06u3hvXqg8ifaHZSVIWs/ZBUOorDFfJDIvfYz0s+vtO3H2 4DFeBEgSuRQjmn/i5i2PUCoK0UTUfo9ZE2P3aZE7SLg3PL1ocoyH6f0GRPBvKF8oYimHMYXqpvF 0yPx94cdoHNfKe50OeJBlEfGKls5E+HQXhrlaVyfB/x5qpiSHYvxTKhY8mFOSNBd53a+rgwKKCw Klnl3kfAAp9OvKTjwkgQbPIUdykFd8IMHfXFcvczhJH+urCoGBOdU8ns3URz99Xp5BNL7CTkfrn Efu7Pf0OALhBJKdyn5ZQXa1kG7uV4YjxwvEtVB5fEYHc9D5+ZOApOZRL2Jbl2P42ylb7Zwuxo/9 4iDbepIDdU8T1npu1yQxusWsj/QUexMsKcSagIaKu9QgPrHPpvdYGCvxN7EoWmUNAWaVksGWMVq V7u04KvzCPUe1Kw== X-Developer-Key: i=marcus.folkesson@gmail.com; a=openpgp; fpr=AB91D46C7E0F6E6FB2AB640EC0FE25D598F6C127 X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Sat, 25 Nov 2023 10:53:41 -0800 (PST) Use the guard(mutex) macro for handle mutex lock/unlocks. Signed-off-by: Marcus Folkesson --- drivers/iio/adc/mcp3911.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/iio/adc/mcp3911.c b/drivers/iio/adc/mcp3911.c index 974c5bd923a6..85bb13eb6f3b 100644 --- a/drivers/iio/adc/mcp3911.c +++ b/drivers/iio/adc/mcp3911.c @@ -7,6 +7,7 @@ */ #include #include +#include #include #include #include @@ -168,7 +169,7 @@ static int mcp3911_read_raw(struct iio_dev *indio_dev, struct mcp3911 *adc = iio_priv(indio_dev); int ret = -EINVAL; - mutex_lock(&adc->lock); + guard(mutex)(&adc->lock); switch (mask) { case IIO_CHAN_INFO_RAW: ret = mcp3911_read(adc, @@ -207,7 +208,6 @@ static int mcp3911_read_raw(struct iio_dev *indio_dev, } out: - mutex_unlock(&adc->lock); return ret; } @@ -218,7 +218,7 @@ static int mcp3911_write_raw(struct iio_dev *indio_dev, struct mcp3911 *adc = iio_priv(indio_dev); int ret = -EINVAL; - mutex_lock(&adc->lock); + guard(mutex)(&adc->lock); switch (mask) { case IIO_CHAN_INFO_SCALE: for (int i = 0; i < MCP3911_NUM_SCALES; i++) { @@ -263,7 +263,6 @@ static int mcp3911_write_raw(struct iio_dev *indio_dev, } out: - mutex_unlock(&adc->lock); return ret; } @@ -350,7 +349,7 @@ static irqreturn_t mcp3911_trigger_handler(int irq, void *p) int i = 0; int ret; - mutex_lock(&adc->lock); + guard(mutex)(&adc->lock); adc->tx_buf = MCP3911_REG_READ(MCP3911_CHANNEL(0), adc->dev_addr); ret = spi_sync_transfer(adc->spi, xfer, ARRAY_SIZE(xfer)); if (ret < 0) { @@ -368,7 +367,6 @@ static irqreturn_t mcp3911_trigger_handler(int irq, void *p) iio_push_to_buffers_with_timestamp(indio_dev, &adc->scan, iio_get_time_ns(indio_dev)); out: - mutex_unlock(&adc->lock); iio_trigger_notify_done(indio_dev->trig); return IRQ_HANDLED; --- base-commit: ffc253263a1375a65fa6c9f62a893e9767fbebfa change-id: 20231125-mcp3911-guard-866591e2c947 Best regards, -- Marcus Folkesson