Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp2549851rdh; Sun, 26 Nov 2023 10:09:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IEH3RrgQM+d08sibFjxinotj9GPkBsKO3kDcJuXdcdRMKaqZ/7RSnKPGV6zEeHi1QFToar1 X-Received: by 2002:a6b:e205:0:b0:7b3:6791:f2a3 with SMTP id z5-20020a6be205000000b007b36791f2a3mr9693318ioc.20.1701022193473; Sun, 26 Nov 2023 10:09:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701022193; cv=none; d=google.com; s=arc-20160816; b=PkrSqN5aOnizFilkfGXCxcswfYvPxkQgafvAFmWT1Ql9fvySgBQMKc1fIoPKcPLSkl nKDYQLUe2O7ocw55J8zKHfOK6Y5r6XBh+n/ZiVlR7wYVNkc9R36bTrRuM5YDYR/qiVHP ZXyc5xEilpBPAwBkyXAUvwoVq2lBwxuuPWCAxUFNLLrjKYNC5N2VHcMGZd5lO0NU1VJx 1rP5PS8t+WqLI4qBbclb5MMfWvQ8kJ6HCcBKK9NybcRhNpNrjedqAMroUoWqww+MX41M wF3XgMzE+pN46Z4MfYj5w9LVSFgqH9ndqoHYTYtrWWozvhdxPjQ0DpHQNO1s/KFkZs7R MiDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=EcOP5Q36jGfQ3qFnQnSUg8ckMaI+VW3ckzbt9Aq+oCE=; fh=zTMCn1ZD7i21SpaVENoR10gnESfmUYFhexKu2tybiYQ=; b=HFu7+OWc203cRHNiiWrtIX+TaDQza2nVSCFduEsJc/jvWzkDBoyutt6jJtS0o6Xuku qC+Ld5Lwb67h6UHy+VBTyKAoiXsmG2gY1sfYjFVsLx1RYRkOP4z/0HQIW8ln6K9UTign 2iInfkX5xuLIxAJFTPRI39OFGvlopfyFdSB6c7+95WyRYlNXB6JmFL3PPZqpzNbLp8om E/VNGfzDiaeM7NkeYYpODkL0mV8QWGikwZ6MTYitG2psxfJ22xgXa2ZuyP0Xtuys1yNG 9Ij9CWquI6KrqXyPGyXDd6J3E7w97fh7S8HI9f8Qwkr8hwR3qv9m0vryS3ZPs7Z3YbrF OjKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZCtTUJfZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id y184-20020a6364c1000000b005895c80c902si8086014pgb.438.2023.11.26.10.09.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Nov 2023 10:09:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZCtTUJfZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 3AB6C80ACC5F; Sun, 26 Nov 2023 10:09:51 -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 S230313AbjKZSJh (ORCPT + 99 others); Sun, 26 Nov 2023 13:09:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229436AbjKZSJg (ORCPT ); Sun, 26 Nov 2023 13:09:36 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8F56C8 for ; Sun, 26 Nov 2023 10:09:42 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 548EEC433C7; Sun, 26 Nov 2023 18:09:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701022182; bh=SLuAs/HbMN7WsDzAJGn90eTqZkD8vv1/cK9ItXh77Lc=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=ZCtTUJfZDgKAZfLHMXglWI/EFreOBt6VY3oj5Ly2RV4hT2e+ZeSieTCTHF40TK0yz r/9DDlQNcn9UD7uRq6dYz5wgPO4lNU5+gvYr6z1WKH77KiFNhsIf6b3fQ7ESuv7Img WQHE/yfkYMEWysyyWnf2Htrl/hZr6NMvbMPr5I5uEfK9t3eWbKLv8toHEjKQ0Iv3/M C9Z6ZBal7s3kEEq9pu89LTukGhNS+cyhiJbhzxFH6UnpOWYoUSxN6wcXFaEP4mdfwa Cgo8COHLTKpK0Gt1Fa8YBPIVqhWEvFWt6aYkA5JE5U+iibFBnGouIK5Zt3IbiuEvc5 mr87fyIc1rkTQ== Date: Sun, 26 Nov 2023 18:09:35 +0000 From: Jonathan Cameron To: Marcus Folkesson Cc: Kent Gustavsson , Lars-Peter Clausen , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] iio: adc: mcp3911: simplify code with guard macro Message-ID: <20231126180935.0c1cc663@jic23-huawei> In-Reply-To: <20231125-mcp3911-guard-v1-1-2748d16a3f3f@gmail.com> References: <20231125-mcp3911-guard-v1-1-2748d16a3f3f@gmail.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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]); Sun, 26 Nov 2023 10:09:51 -0800 (PST) On Sat, 25 Nov 2023 19:57:24 +0100 Marcus Folkesson wrote: > Use the guard(mutex) macro for handle mutex lock/unlocks. > > Signed-off-by: Marcus Folkesson Hi Marcus, Great to see this being used, but there is a little more you can do here to take advantage fully. > --- > 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; No point in having the label down here after the change. Just return directly wherever you see an error. Same for other cases. > } > > @@ -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,