Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp592952lqp; Sat, 13 Apr 2024 09:58:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW5TzltFiqsISOci360ZpSHxNYblaeNtK0obB3TWFOS0W6L8HWv5dHOyHi1lfESWHI1E5gpuTSojaWY79OT7H6En+iEI9Exm3VOlPWCCA== X-Google-Smtp-Source: AGHT+IE/INEKfkFy5R08N3ZJ1wDTHvLDPjl/qfJ02YCIiR5n4BJrGMHgg3m+7u9y9mPHFOPmCNfz X-Received: by 2002:a05:6359:3782:b0:17f:7807:320c with SMTP id vp2-20020a056359378200b0017f7807320cmr7162640rwb.5.1713027529755; Sat, 13 Apr 2024 09:58:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713027529; cv=pass; d=google.com; s=arc-20160816; b=cP2Qnyzz86xiDxjFDQ0fv6Alh8uG+Bdzmh9RMbXPH2Ha4Wz8cfuH0p6PV1xPz1qxsu TCfc+Q4H23tZW7YZS17UmNSvqnHkQSrWgcGWVtPlLlXzYRUF4p8fSWF6/OnssF+0rD+I VO7ysPrOoLwFEqg1tbziTdp9G42ZJGQMaqUD2GzAQ0QfTyI3KF2PCazSXCT6m5nb2Zvq 6hAZILiyfpHGEA28YK9S3okd2VNkaDKhIiR6JcsjTk/U6i0odNoTN+zH5iCJgXwk3bon V2ncrPWowvpdMvAZ7TL5urZIEvzfjDNB0pF767tgi11jKhK59JFmWPE5fmUaA+w2zlug OPZg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=tvLQvpWL4DaXZhddjVn4nPVPTxKsvRerpbcOdn9FIL0=; fh=QOo/yt/OkESGDalaU5QlkfrbKKthXTAyOlhKEhI1tzs=; b=M6v8/l0KSPq6JPojYLY+Z5Y6py2rtsTGdYCKEKytOZ07nWZxFiC/IaJDFI3sti+c2K agwpUfAwD8VIIKVE1CEI+UdfYgnwLV5j6AkqT247g9HNewjmCgWrKSFFxTkfwck/ZiCV MACz0DnatPw+k8Zlm9qnbLQ8EvUd+EX8y/HiWEfiLnAAN/ng4QRaKTsy1IUrfyn5M9V/ 9Gp1aJrYg9IlGZOwcRCApXzCRu6KMIAKe1TVcTdou7fJmlt3f5MwOejJZUlRwryrHOWm rDiHQA1JKjE+v+0/B4IkTWSzpQtpwK7dj32AD6TlA0zQjGy33N08It8JVAlARdm+a7vI d1mA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Qu2XvNrE; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-143817-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143817-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id l126-20020a632584000000b005dc42bb64aesi5278961pgl.617.2024.04.13.09.58.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Apr 2024 09:58:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-143817-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Qu2XvNrE; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-143817-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143817-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 619DB281E53 for ; Sat, 13 Apr 2024 16:58:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 834EF45941; Sat, 13 Apr 2024 16:58:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Qu2XvNrE" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 874C652F61; Sat, 13 Apr 2024 16:58:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713027521; cv=none; b=kt6AO19etE0l3C9TiNt9MwGH2j2EtwwJwJMosepKicS0ToCigRf8l4emsLGWM//6gVjUehwNjvNcDgQqDx3dhbxMEGsGSGze3Uc2Cbiz/e5fKBL/43jP0fn8MSge/kJtIUSWk+c5c6Sv1TUyr8ZAhJmFbZ4Vk+ssNIHZwYfGPvs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713027521; c=relaxed/simple; bh=YvxTBCT3L9qSCB4QszH6PYF5IkYVlpxMrd4uOhksnpo=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=awuxqv/mfsa5S2IV6rUuFYA2IkZ/fxen7KaLhHF/6GZysN7dPVc2xUTzrk5fk1JnU3Ux3En45EipVaZYCBhU9oEuh2074+5loslqcpWxA0QjP4bJot2BQCFD9ZvurW//OrQ91uSSix6khzrTnEBVE5MQysjsoi9hNvgxBsrRkYM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Qu2XvNrE; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1CD17C113CD; Sat, 13 Apr 2024 16:58:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713027521; bh=YvxTBCT3L9qSCB4QszH6PYF5IkYVlpxMrd4uOhksnpo=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Qu2XvNrEMP5Ae4MsnB9BVDjv/8YgbYr24/eAcGhiV6G3tuuMOMrFiYFKkC1o5PBJQ ONlG7ZCBgankGRrG35sX6zAkJtZi/hnV6wEyoQMi0so6G5cqlt6tRQTfEkEHabUxxm hfEufLrxF9wVDO6f5/5Ts+35v9wWDqde2hvEnbS1h8/CP5WzFRtocP4cqWR0LianSj 0fff22Z3Ri2J7yeoK4QGipXawk7J8GbZeeJKN93rSJw4YzqRMwpzzqipqYkkBlZvYQ 8H3UjlbSI+cOOXcNLw9XhIDH7SCBxDUlKr91htsbvmbpP1aJgcKdywtznqDCdhbws7 xw2lJZkSI67IQ== Date: Sat, 13 Apr 2024 17:58:24 +0100 From: Jonathan Cameron To: Vasileios Amoiridis Cc: lars@metafoo.de, andriy.shevchenko@linux.intel.com, ang.iglesiasg@gmail.com, mazziesaccount@gmail.com, ak@it-klinger.de, petre.rodan@subdimension.ro, phil@raspberrypi.com, 579lpy@gmail.com, u.kleine-koenig@pengutronix.de, biju.das.jz@bp.renesas.com, linus.walleij@linaro.org, semen.protsenko@linaro.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Jonathan Cameron Subject: Re: [PATCH v4 3/6] iio: pressure: bmp280: Introduce new cleanup routines Message-ID: <20240413175824.561e361d@jic23-huawei> In-Reply-To: <20240407172920.264282-4-vassilisamir@gmail.com> References: <20240407172920.264282-1-vassilisamir@gmail.com> <20240407172920.264282-4-vassilisamir@gmail.com> X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Sun, 7 Apr 2024 19:29:17 +0200 Vasileios Amoiridis wrote: > Introduce new linux/cleanup.h with the guard(mutex) functionality > in the {read,write}_raw() functions. > > Suggested-by: Andy Shevchenko > Suggested-by: Jonathan Cameron > Signed-off-by: Vasileios Amoiridis A could of corners of dead code that you can remove. In general looks good. Jonathan > --- > drivers/iio/pressure/bmp280-core.c | 129 +++++++++++++---------------- > 1 file changed, 58 insertions(+), 71 deletions(-) > > diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c > index 50bdf79011bc..51bcdf8cede6 100644 > --- a/drivers/iio/pressure/bmp280-core.c > +++ b/drivers/iio/pressure/bmp280-core.c > @@ -27,6 +27,7 @@ > > #include > #include > +#include > #include > #include > #include > @@ -499,77 +500,69 @@ static int bme280_read_humid(struct bmp280_data *data, int *val, int *val2) > return IIO_VAL_INT; > } > > -static int bmp_read_raw(struct iio_dev *indio_dev, > - struct iio_chan_spec const *chan, > - int *val, int *val2, long mask) > +static int bmp_read_raw_impl(struct iio_dev *indio_dev, > + struct iio_chan_spec const *chan, > + int *val, int *val2, long mask) > { > struct bmp280_data *data = iio_priv(indio_dev); > - int ret; > > - pm_runtime_get_sync(data->dev); > - mutex_lock(&data->lock); > + guard(mutex)(&data->lock); > > switch (mask) { > case IIO_CHAN_INFO_PROCESSED: > switch (chan->type) { > case IIO_HUMIDITYRELATIVE: > - ret = data->chip_info->read_humid(data, val, val2); > - break; > + return data->chip_info->read_humid(data, val, val2); > case IIO_PRESSURE: > - ret = data->chip_info->read_press(data, val, val2); > - break; > + return data->chip_info->read_press(data, val, val2); > case IIO_TEMP: > - ret = data->chip_info->read_temp(data, val, val2); > - break; > + return data->chip_info->read_temp(data, val, val2); > default: > - ret = -EINVAL; > - break; > + return -EINVAL; > } > - break; > case IIO_CHAN_INFO_OVERSAMPLING_RATIO: > switch (chan->type) { > case IIO_HUMIDITYRELATIVE: > *val = 1 << data->oversampling_humid; > - ret = IIO_VAL_INT; > - break; > + return IIO_VAL_INT; > case IIO_PRESSURE: > *val = 1 << data->oversampling_press; > - ret = IIO_VAL_INT; > - break; > + return IIO_VAL_INT; > case IIO_TEMP: > *val = 1 << data->oversampling_temp; > - ret = IIO_VAL_INT; > - break; > + return IIO_VAL_INT; > default: > - ret = -EINVAL; > - break; > + return -EINVAL; > } > - break; > case IIO_CHAN_INFO_SAMP_FREQ: > - if (!data->chip_info->sampling_freq_avail) { > - ret = -EINVAL; > - break; > - } > + if (!data->chip_info->sampling_freq_avail) > + return -EINVAL; > > *val = data->chip_info->sampling_freq_avail[data->sampling_freq][0]; > *val2 = data->chip_info->sampling_freq_avail[data->sampling_freq][1]; > - ret = IIO_VAL_INT_PLUS_MICRO; > - break; > + return IIO_VAL_INT_PLUS_MICRO; > case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: > - if (!data->chip_info->iir_filter_coeffs_avail) { > - ret = -EINVAL; > - break; > - } > + if (!data->chip_info->iir_filter_coeffs_avail) > + return -EINVAL; > > *val = (1 << data->iir_filter_coeff) - 1; > - ret = IIO_VAL_INT; > - break; > + return IIO_VAL_INT; > default: > - ret = -EINVAL; > - break; > + return -EINVAL; > } > > - mutex_unlock(&data->lock); > + return 0; As below. I don't think you can get here. I hope all paths have already returned. > +} > + > +static int bmp_read_raw(struct iio_dev *indio_dev, > + struct iio_chan_spec const *chan, > + int *val, int *val2, long mask) > +{ > + struct bmp280_data *data = iio_priv(indio_dev); > + int ret; > + > + pm_runtime_get_sync(data->dev); > + ret = bmp_read_raw_impl(indio_dev, chan, val, val2, mask); > pm_runtime_mark_last_busy(data->dev); > pm_runtime_put_autosuspend(data->dev); > > @@ -697,12 +690,13 @@ static int bmp_write_iir_filter_coeffs(struct bmp280_data *data, int val) > return -EINVAL; > } > > -static int bmp_write_raw(struct iio_dev *indio_dev, > - struct iio_chan_spec const *chan, > - int val, int val2, long mask) > +static int bmp_write_raw_impl(struct iio_dev *indio_dev, > + struct iio_chan_spec const *chan, > + int val, int val2, long mask) > { > struct bmp280_data *data = iio_priv(indio_dev); > - int ret = 0; > + > + guard(mutex)(&data->lock); > > /* > * Helper functions to update sensor running configuration. > @@ -712,46 +706,39 @@ static int bmp_write_raw(struct iio_dev *indio_dev, > */ > switch (mask) { > case IIO_CHAN_INFO_OVERSAMPLING_RATIO: > - pm_runtime_get_sync(data->dev); > - mutex_lock(&data->lock); > switch (chan->type) { > case IIO_HUMIDITYRELATIVE: > - ret = bmp_write_oversampling_ratio_humid(data, val); > - break; > + return bmp_write_oversampling_ratio_humid(data, val); > case IIO_PRESSURE: > - ret = bmp_write_oversampling_ratio_press(data, val); > - break; > + return bmp_write_oversampling_ratio_press(data, val); > case IIO_TEMP: > - ret = bmp_write_oversampling_ratio_temp(data, val); > - break; > + return bmp_write_oversampling_ratio_temp(data, val); > default: > - ret = -EINVAL; > - break; > + return -EINVAL; > } > - mutex_unlock(&data->lock); > - pm_runtime_mark_last_busy(data->dev); > - pm_runtime_put_autosuspend(data->dev); > - break; > case IIO_CHAN_INFO_SAMP_FREQ: > - pm_runtime_get_sync(data->dev); > - mutex_lock(&data->lock); > - ret = bmp_write_sampling_frequency(data, val, val2); > - mutex_unlock(&data->lock); > - pm_runtime_mark_last_busy(data->dev); > - pm_runtime_put_autosuspend(data->dev); > - break; > + return bmp_write_sampling_frequency(data, val, val2); > case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: > - pm_runtime_get_sync(data->dev); > - mutex_lock(&data->lock); > - ret = bmp_write_iir_filter_coeffs(data, val); > - mutex_unlock(&data->lock); > - pm_runtime_mark_last_busy(data->dev); > - pm_runtime_put_autosuspend(data->dev); > - break; > + return bmp_write_iir_filter_coeffs(data, val); > default: > return -EINVAL; > } > > + return 0; I'm fairly sure you can't get here so this is dead code. Hene drop this final return. > +} >