Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1155826rdb; Wed, 6 Dec 2023 10:01:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IH+ZjAnM+39rzkx2A5QYJvjVkk5OI0lkqNvp0QR1fmPkZUelcu9DUKmmtCHLeK9WbMo4FBi X-Received: by 2002:a17:902:dac4:b0:1cf:59df:23e with SMTP id q4-20020a170902dac400b001cf59df023emr1825277plx.12.1701885718847; Wed, 06 Dec 2023 10:01:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701885718; cv=none; d=google.com; s=arc-20160816; b=FTb/KjrxqRAawmu9yd/IgAbPJeI1gd9mr9SysLPtvELYaeGBNsotTS4KoniiQeSE+n TERK8SDiMGYsz4LkxD++dKrHK4VSizkLNSh0YlvLrhSy8w/ICepzGHfZkOO2seQ0OE4a PRER+fIzcP/+h+Fq2znplzsEYXqoX4oZbsnJfbp4PB3fyf8IQeinMdTFXvC1DhQ4+WzF 0vRKWA40P9g4EleRVeae7biXyxfQ9jX57TchjoMD0Ubtq7jo9usxMquGMLjda5oJUzPp j4bz+KFxDjhOSJK0/LYZb8GEzxPrSdd7NiDFhCEbF2wWoGE79siNXcQDjZk6vQqKyLY8 yJvA== 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=y5CeRdGPovBcG2vhwh+tYEQC3q9IztnHWadZgS2nBiE=; fh=zTMCn1ZD7i21SpaVENoR10gnESfmUYFhexKu2tybiYQ=; b=kmjtdxGpowfQBROJlN5q+r77Q21HziByocu7yzBs8+SWe8t82BUskKQ8y33OCpQ1N9 PXabURdnH2/6PU0LsuhN33aASVYR8pGTysosjbKS9fr0IEO/C2+tDFR4EVi4aoi46+rM r4GCodLtjvzWDo9MoGhgDLseVuPRsPL1xx4qz/GkRTFbX17IhSl57flwQ29SOcHQILj3 nSBEbUN3A4fRCycZ+taciqovblg6WOULWJoVzSht5vkuLLRIEPCGm49nO/rTpIPS8x+R AZg20wP34qYcoiFE06hCVz5eXqYTzgK3pItsujxPobh8YkVoC9o0rpg3nL+SBXIf8hrh JMyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jTlpYh08; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id q16-20020a17090311d000b001d1d4761a26si143922plh.499.2023.12.06.10.01.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 10:01:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jTlpYh08; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id 3A5938297C4C; Wed, 6 Dec 2023 10:01:54 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379044AbjLFSB2 (ORCPT + 99 others); Wed, 6 Dec 2023 13:01:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378992AbjLFSB0 (ORCPT ); Wed, 6 Dec 2023 13:01:26 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C950139 for ; Wed, 6 Dec 2023 10:01:33 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ECD92C433C7; Wed, 6 Dec 2023 18:01:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701885693; bh=H5aehIkSq278H36IsVkzvOoDv3gkPy7Av2ps6FIv0zE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=jTlpYh08jw2nAFSqYhqehungn9Mnu0V+inN0V6ZwgJ7uLp4iI+oxXCQLd0zFOjIoI 2J3Q1NHO3KKZOqpxWSO8gGw9xcLBG12LRq3AQ/c8JVU5rvNMTcyzf9vtVvIvb2cyrg yRaYDhO45Nyrju3g6u4NyQMExg3eKJtcnSdZjp04zh+lipRvWYG48INnZbgQmBKbt/ 05BibzMRGO2IgZyyNGWiuNeCjP05NlV/cbT+GCSiWhZx3QINrpBZ3fD9MKWGZO8QG9 FQznCSleYsfVqqxBG9iie2mQrLv1UuIYSx4bEgHwoIhHqebaynRbjMNpTdMzjsOS94 JjeGM13X5Xrmw== Date: Wed, 6 Dec 2023 18:01:26 +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 v3] iio: adc: mcp3911: simplify code with guard macro Message-ID: <20231206180126.6e78ed29@jic23-huawei> In-Reply-To: <20231205-mcp3911-guard-v3-1-df83e956d1e9@gmail.com> References: <20231205-mcp3911-guard-v3-1-df83e956d1e9@gmail.com> X-Mailer: Claws Mail 4.2.0 (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 morse.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 (morse.vger.email [0.0.0.0]); Wed, 06 Dec 2023 10:01:54 -0800 (PST) On Tue, 05 Dec 2023 12:16:33 +0100 Marcus Folkesson wrote: > Use the guard(mutex) macro for handle mutex lock/unlocks. > > Signed-off-by: Marcus Folkesson Hi Marcus, One follow up issue inline. > --- > Changes in v3: > - Return early in good paths as well > - Rebase against master > - Link to v2: https://lore.kernel.org/r/20231127-mcp3911-guard-v2-1-9462630dca1e@gmail.com > > Changes in v2: > - Return directly instead of goto label > - Link to v1: https://lore.kernel.org/r/20231125-mcp3911-guard-v1-1-2748d16a3f3f@gmail.com > --- > drivers/iio/adc/mcp3911.c | 47 +++++++++++++++-------------------------------- > 1 file changed, 15 insertions(+), 32 deletions(-) > > diff --git a/drivers/iio/adc/mcp3911.c b/drivers/iio/adc/mcp3911.c > index d864558bc087..f4822ecece89 100644 > --- a/drivers/iio/adc/mcp3911.c > +++ b/drivers/iio/adc/mcp3911.c > @@ -7,6 +7,7 @@ > */ > #include > #include > +#include > #include > #include > #include > @@ -318,44 +319,34 @@ 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, > MCP3911_CHANNEL(channel->channel), val, 3); > if (ret) > - goto out; > + return ret; > > *val = sign_extend32(*val, 23); > - > - ret = IIO_VAL_INT; > + return IIO_VAL_INT; > break; Why keep the break? It's unreachable code. Same for other similar cases. Jonathan >