From nobody Sun Nov 24 04:46:24 2024 Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) (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 581A41D5CE0; Thu, 21 Nov 2024 13:05:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732194329; cv=none; b=fVyGGFTKvk9q7Ynw8S4ZrUDH6tHRwni1NGR5DLxHWpRoRGc8uX0JEzR5v7xeld2Xx99rImh4dAmN/PBHRai3Pzlku7/0pSbgOpy9+N9VfBMMTuBCM6e+ud6uJtNEmFN7AhzQJd0DIIOozMZPbFvQXfnU6IZ9B6zsAv+j87y0KmI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732194329; c=relaxed/simple; bh=eYbCCKYh66osXyNgE2HPw/2SQUZRpEzOFNSlCOyYtvU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ELvHbVJ6ACFWSRQZQZa/N38+EZ1eQkIqp+00RYkZF6xHWhcxW/8dhgIzrOQfvwCbu5aRekuADRhtAVBBdYFsVbvURziRUkVBVJEihACPrvYEyQPmSbjsfw2xUeUMpVB/4BHRoHsQILcLt4gNPgAjZcSELyavYxM8nTA/ikeS3RQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=CHhqxPvX; arc=none smtp.client-ip=209.85.208.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CHhqxPvX" Received: by mail-lj1-f182.google.com with SMTP id 38308e7fff4ca-2ff57619835so18095021fa.0; Thu, 21 Nov 2024 05:05:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732194325; x=1732799125; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=jANKLpJlY3GMOQ9x6c0D0dqa4Rq3jdtrzX/uM5HU2oQ=; b=CHhqxPvXoxlt4YX0mKvYRzDdFu8tV9EWCqK2cE95KDZcUVv0Xu3BsYgZqNxST3JBeo fy+6UOPG8rpuYujvV6dAMEegRFKuoSeWfrSRnMwGyCbusPy9Vd3+teER3l9reUCvlvLh AYd+0jwCY4eWHFMqRu/UpVTZfvE6XREbk/d6bTINHrz9aBIwCi51bZfHbogbtocUIf09 Ij/+mfe09Se1s0+gSjcENrhX3DPJmHZAKt5S2cLnXhmFQSU7yr6BwFIUsAceCtaAajq/ 499TprW1U9mT/AI6jEBYV67PPvSH4UV0aqUKSK2hZFwV7NnvwBWpD4VB7gNAtlinb7Aj EI/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732194325; x=1732799125; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=jANKLpJlY3GMOQ9x6c0D0dqa4Rq3jdtrzX/uM5HU2oQ=; b=wIeIa8PhX7w/m+17q4LN0wshNRviSKTq35Sku7U3n3gXNS/nkGSnxyeSMMXDY+uw1b 5O3ZtslD32FkfAStwhx1yTwSePqT88H1rdxcetGlApDgot568lYELDM1ETmhao0u4Xfn bcNvbcG/iKLuRYcDeE53d/eTgizWaS8lxg1uWgqCpX/yRSzyhj87PplH+93aYDLhWmOo CkYINucS080O/a8AlKQhNbPvHNajXdnd7CxGqNU0tOmForXcL0XWQNFRIbbYyHzdZAcH gIRbYU8p8DQs4SpuhpW5h+kOo2eXfRTSDB0VCAD3Tho4t2KlnKbG/ytqt/hzzt1E9f0Z QfWw== X-Forwarded-Encrypted: i=1; AJvYcCU04oKdGFLJMy686pkVsjl8KgQPMnOSrmp0Wna5qyFvxUHJiMVU4gt4n+jIb2wWmw1JPVslTZwXaD8=@vger.kernel.org, AJvYcCWHZJ5717YzhRx8sev/V1iOSzn1a2d7Am/SJ9wRAQICZgEskUfvum6G8yxvbIPATR0qe3o4yYIH2qdvYOJC@vger.kernel.org X-Gm-Message-State: AOJu0YypL++OqUZ8YyocsK1eXNdcHbNjlBnrLW4Na5q1bMTESnXoc76N bP0FxOYg/OcQG8OC88Y3vlNkWcHCG3b2VgZBGt0B6Ngmpi4ah5qo X-Gm-Gg: ASbGncuLivbFjfN76kqDtAPxmnH887zCy2myjkPsU54s3OjWSL7433o6wPVJ0oMrYd6 zHqPzBejCAMBJtcq8FORmp/H70QfqukZpbShXQhIR22/73AINStZ3tEPV3Xd1cxxZa7XMQH+XLm JnlsxMRlRE1+K6NWfrKKzQLEu2Su5zU+BDg+ITNP42BGLojBBCOZOlQNXVMDynWfJhB9Cr3ieBQ zUv5yRstNrzr8/S5Rt/LXWZU9cb7kSxqQ43m2RZAQRrW8Q8GZfb X-Google-Smtp-Source: AGHT+IGZiAUkl4yO3pIx19+eJUM3dcBKbvU9yGNh2kLVVy/5YEDbYpECuzbn2LrhBkA9QV393Szetg== X-Received: by 2002:a05:651c:1582:b0:2ef:28ed:1ff5 with SMTP id 38308e7fff4ca-2ff96a24fdcmr8791591fa.15.1732194325078; Thu, 21 Nov 2024 05:05:25 -0800 (PST) Received: from mva-rohm ([213.255.186.46]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2ff698515d0sm19104451fa.19.2024.11.21.05.05.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 05:05:24 -0800 (PST) Date: Thu, 21 Nov 2024 15:05:19 +0200 From: Matti Vaittinen To: Matti Vaittinen , Matti Vaittinen Cc: Matti Vaittinen , Jonathan Cameron , Lars-Peter Clausen , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] iio: bu27034: simplify using guard(mutex) Message-ID: <4e65a4725c211b166906f70fdb5ba90f2af0f570.1732193263.git.mazziesaccount@gmail.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="ptxAvMg++OCoXv6s" Content-Disposition: inline In-Reply-To: --ptxAvMg++OCoXv6s Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The BU27034 uses mutex for protecting the gain / time / scale changes. The clean-up for a few of the functions can be slightly simplified by removing the goto-based error handling/unlocking and by utilizing the guard(mutex) scoped mutex handling instead. Simplify driver by using the scoped mutexes. Signed-off-by: Matti Vaittinen Reviewed-by: Javier Carrasco --- drivers/iio/light/rohm-bu27034.c | 73 +++++++++++--------------------- 1 file changed, 25 insertions(+), 48 deletions(-) diff --git a/drivers/iio/light/rohm-bu27034.c b/drivers/iio/light/rohm-bu27= 034.c index 76711c3cdf7c..d2ed92d5ec92 100644 --- a/drivers/iio/light/rohm-bu27034.c +++ b/drivers/iio/light/rohm-bu27034.c @@ -7,6 +7,7 @@ =20 #include #include +#include #include #include #include @@ -395,30 +396,26 @@ static int bu27034_try_set_int_time(struct bu27034_da= ta *data, int time_us) int numg =3D ARRAY_SIZE(gains); int ret, int_time_old, i; =20 - mutex_lock(&data->mutex); + guard(mutex)(&data->mutex); ret =3D bu27034_get_int_time(data); if (ret < 0) - goto unlock_out; + return ret; =20 int_time_old =3D ret; =20 if (!iio_gts_valid_time(&data->gts, time_us)) { dev_err(data->dev, "Unsupported integration time %u\n", time_us); - ret =3D -EINVAL; - - goto unlock_out; + return -EINVAL; } =20 - if (time_us =3D=3D int_time_old) { - ret =3D 0; - goto unlock_out; - } + if (time_us =3D=3D int_time_old) + return 0; =20 for (i =3D 0; i < numg; i++) { ret =3D bu27034_get_gain(data, gains[i].chan, &gains[i].old_gain); if (ret) - goto unlock_out; + return 0; =20 ret =3D iio_gts_find_new_gain_by_old_gain_time(&data->gts, gains[i].old_gain, @@ -434,7 +431,7 @@ static int bu27034_try_set_int_time(struct bu27034_data= *data, int time_us) gains[i].chan, time_us, scale1, scale2); =20 if (gains[i].new_gain < 0) - goto unlock_out; + return ret; =20 /* * If caller requests for integration time change and we @@ -455,7 +452,7 @@ static int bu27034_try_set_int_time(struct bu27034_data= *data, int time_us) "Total gain increase. Risk of saturation"); ret =3D iio_gts_get_min_gain(&data->gts); if (ret < 0) - goto unlock_out; + return ret; } dev_dbg(data->dev, "chan %u scale changed\n", gains[i].chan); @@ -468,15 +465,10 @@ static int bu27034_try_set_int_time(struct bu27034_da= ta *data, int time_us) for (i =3D 0; i < numg; i++) { ret =3D bu27034_set_gain(data, gains[i].chan, gains[i].new_gain); if (ret) - goto unlock_out; + return ret; } =20 - ret =3D bu27034_set_int_time(data, time_us); - -unlock_out: - mutex_unlock(&data->mutex); - - return ret; + return bu27034_set_int_time(data, time_us); } =20 static int bu27034_set_scale(struct bu27034_data *data, int chan, @@ -492,10 +484,10 @@ static int bu27034_set_scale(struct bu27034_data *dat= a, int chan, return -EINVAL; } =20 - mutex_lock(&data->mutex); + guard(mutex)(&data->mutex); ret =3D regmap_read(data->regmap, BU27034_REG_MODE_CONTROL1, &time_sel); if (ret) - goto unlock_out; + return ret; =20 ret =3D iio_gts_find_gain_sel_for_scale_using_time(&data->gts, time_sel, val, val2, &gain_sel); @@ -518,7 +510,7 @@ static int bu27034_set_scale(struct bu27034_data *data,= int chan, =20 ret =3D bu27034_get_gain(data, gain.chan, &gain.old_gain); if (ret) - goto unlock_out; + return ret; =20 /* * Iterate through all the times to see if we find one which @@ -551,26 +543,20 @@ static int bu27034_set_scale(struct bu27034_data *dat= a, int chan, if (!found) { dev_dbg(data->dev, "Can't set scale maintaining other channel\n"); - ret =3D -EINVAL; - - goto unlock_out; + return -EINVAL; } =20 ret =3D bu27034_set_gain(data, gain.chan, gain.new_gain); if (ret) - goto unlock_out; + return ret; =20 ret =3D regmap_update_bits(data->regmap, BU27034_REG_MODE_CONTROL1, BU27034_MASK_MEAS_MODE, new_time_sel); if (ret) - goto unlock_out; + return ret; } =20 - ret =3D bu27034_write_gain_sel(data, chan, gain_sel); -unlock_out: - mutex_unlock(&data->mutex); - - return ret; + return bu27034_write_gain_sel(data, chan, gain_sel); } =20 /* @@ -1221,42 +1207,33 @@ static int bu27034_buffer_enable(struct iio_dev *id= ev) struct task_struct *task; int ret; =20 - mutex_lock(&data->mutex); + guard(mutex)(&data->mutex); ret =3D bu27034_meas_set(data, true); if (ret) - goto unlock_out; + return ret; =20 task =3D kthread_run(bu27034_buffer_thread, idev, "bu27034-buffering-%u", iio_device_id(idev)); - if (IS_ERR(task)) { - ret =3D PTR_ERR(task); - goto unlock_out; - } + if (IS_ERR(task)) + return PTR_ERR(task); =20 data->task =3D task; =20 -unlock_out: - mutex_unlock(&data->mutex); - - return ret; + return 0; } =20 static int bu27034_buffer_disable(struct iio_dev *idev) { struct bu27034_data *data =3D iio_priv(idev); - int ret; =20 - mutex_lock(&data->mutex); + guard(mutex)(&data->mutex); if (data->task) { kthread_stop(data->task); data->task =3D NULL; } =20 - ret =3D bu27034_meas_set(data, false); - mutex_unlock(&data->mutex); - - return ret; + return bu27034_meas_set(data, false); } =20 static const struct iio_buffer_setup_ops bu27034_buffer_ops =3D { --=20 2.47.0 --ptxAvMg++OCoXv6s Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEIx+f8wZb28fLKEhTeFA3/03aocUFAmc/MA8ACgkQeFA3/03a ocUkXQf+OkMvpzSaDdegLQ6EZwuJ68qRT8JnDjEv9LcWYMaEl9uRbosRIyTr4XzF HLDJUhOV32U6eN0EDDbI9XiF3/oJtEnQUWnYPg4kGhPH4gjwnSzwJszheRroXWnc Qenhv+cSl1p1dxCdfyp8gFu5ejH/TolPkAK0n7xL4YOYxbNFV7kq3OT4vrUdGRWm hz4XX+VqfqxsnMqUNlu/DnOypceCXB3ouCGaARQo9ETPKHVEhT27VbfwCDUcRSY8 ETguGadKRfudFngoHYyJqSD2L17pgmcUbgInB4ekRROrgtcCf1PlqQihctx/4nhK eF7nvairXRoh50CUpQCW8EPk6weRpw== =CN4P -----END PGP SIGNATURE----- --ptxAvMg++OCoXv6s-- From nobody Sun Nov 24 04:46:24 2024 Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (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 B94361D0DF7; Thu, 21 Nov 2024 13:05:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732194349; cv=none; b=YJ6k2ef7axjsJlRFYq9Te5csTOIOh+KvA1u1cn/2cwiWEqT/TdUk6pvA59yJquratwlXG2SS1h3Tode9DyIHKSLsMgcKQnhw7XMdYmLTfBwiLBT5krzIvlKg9vJ55beUxNHShgM4iKwOrpf7O51DibLk17BRj9ni+I1QhbBmKDU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732194349; c=relaxed/simple; bh=6npMatVCZI+oeHWmt/V2F2Ut5alI7SeDaNexlDHDHGM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Mobz5Z0SvXxjd16rlz38B4delSHMJnhiZxO7VHJErh0gwUFedNbQ3qo3GgnZV/lVETHy4vkwexxvfSEZzmDsiU+/gxY7c97dYYbE7jx4KZv8IaeNRnXydnYqzjlqsSDzeF7hBnY7eh6gs9QFfCdXY/zGMeyaPg2XX8GpkV5WFz8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=UxMlFhu8; arc=none smtp.client-ip=209.85.167.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UxMlFhu8" Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-53dd17c2d71so68470e87.3; Thu, 21 Nov 2024 05:05:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732194346; x=1732799146; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=WOMRJJYyVM1nXqRX+JAese5bHuTXFA1dmAo4aaZJwhY=; b=UxMlFhu88Zh0S1En1TBXv2LaakEZVpWmLe3RViLdttuG3EkoTXDLZvbZH6r7KOFpGU dPEEkJ6QR8MWaJlQ2v72qZvrh5M4KyisVmhYrW3vbcpUNNY59/pgKbxTO+0xfUTbEJ0s s1cEopBtmEfN5+WomLGi+9SePrRiPz62tL25RVH8iQK9Qf3Dh7bp8+ZKKBBS2cH401i7 htijhS1px/BAtzq+ypRpb4KwWo+D9Qi7qTCmQpsrlT5SKtT7UiU+H+35DqhPJ2zOdY7s 1UfBZr8Vwr6s1gRuvKDz3vlmieThfNVZvWRhq/7SasgAGLkhypu0PnZI5Y0pu79XKAER LVhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732194346; x=1732799146; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=WOMRJJYyVM1nXqRX+JAese5bHuTXFA1dmAo4aaZJwhY=; b=Kn/1uzwwIip21U7YMpYoxKzMGT0pQEcOLkvScPMdLJsrhNSLesTkmYxr3vfnx/xckc ru8fDcrmqOG7ECkEUvFHBAIktRzbxkh8qfeNjCINxi9wXLHSIQP7Nr4vqY+EO9oNPuIU axYVe9xGnKuR4bpyJ0JFHBmaZxZTPICjTQP1PLigapBsdTQ9G749UrWjCu+rRnkBwUzQ 7ZmihjCBm7GnlqCb5hVTMXeI5cReVqppkbXoTYfCaZovRCPNtRwJXWC6tTMi4PM3EDbV LEQF3uIB4nGE6hTxAKCDhGWPhwH432WMxd3QxkWFX/SmBcvaV8c5oSUQeVB9wsDvOOJ7 tn2A== X-Forwarded-Encrypted: i=1; AJvYcCVHSDXX83yuKElgH3x4IHe65fOUT8oyHduGhdX3WWHJCKqfaL543xXgZSC1jih4HX+fgoSyfNHnXTA=@vger.kernel.org, AJvYcCWNLZ213cOe1VtdBE8KS6pbvHvI+iyaQYIZAFDjb9FPZW4gARctS9V6jB30fCc2DLkjfrTVfkKKqAl4kV1C@vger.kernel.org X-Gm-Message-State: AOJu0YwW2hBAIlVGNpc0e7JMuj7q7iDaKm0Y27AdCYDqxRAyq2T3kCTL NzMaWyZYnW+cLvMhH7Q+IEceGSgnoGGf0DhXLESlEtypXTgRj5XY X-Gm-Gg: ASbGncsqIAv6ZDyUMUcNzupEo97B719mGZG7O1c3F0tzwAv045LH8YhuJFjqThEREl2 FiOr8xw2hamfQkdEMeljJPoRHSMMK6m3vyWZYL4pu4DOMjfTt8MtUDAd2v3hU5kNCTN9ZsDPvCv x6S2B6qYDwQBovIFhkggqZtTBJ2DN8QrlmNJ6x+GroaEJQlsZXZHaZ7SAhCmjjhD04TuZIfVqgV SDJ5KkFfMtvlCsEYHYLzJRtEG4TVnkRK8rJW4EYVvp4pX0nAzHx X-Google-Smtp-Source: AGHT+IGamEeL9UVJ4CScSHAlfc1wOhqm9/9TKfz5C34BD7KTXtr/rDf5fhtXQaWfwuKzPeADMr8MsQ== X-Received: by 2002:a05:651c:98a:b0:2fb:5014:c963 with SMTP id 38308e7fff4ca-2ff8db86d5dmr40416081fa.20.1732194345492; Thu, 21 Nov 2024 05:05:45 -0800 (PST) Received: from mva-rohm ([213.255.186.46]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2ff69b16184sm18618421fa.112.2024.11.21.05.05.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 05:05:43 -0800 (PST) Date: Thu, 21 Nov 2024 15:05:38 +0200 From: Matti Vaittinen To: Matti Vaittinen , Matti Vaittinen Cc: Matti Vaittinen , Jonathan Cameron , Lars-Peter Clausen , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] iio: bm1390: simplify using guard(mutex) Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="5F1TfRMO12U7bMJL" Content-Disposition: inline In-Reply-To: --5F1TfRMO12U7bMJL Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The BM1390 uses mutex for protecting the fifo read sequence. The clean-up for a few of the functions can be slightly simplified by removing the goto-based error handling/unlocking and by utilizing the guard(mutex) scoped mutex handling instead. Simplify driver by using the scoped mutexes. Signed-off-by: Matti Vaittinen Reviewed-by: Javier Carrasco --- drivers/iio/pressure/rohm-bm1390.c | 78 ++++++++++++------------------ 1 file changed, 30 insertions(+), 48 deletions(-) diff --git a/drivers/iio/pressure/rohm-bm1390.c b/drivers/iio/pressure/rohm= -bm1390.c index ccaa07a569c9..fa1a477151d0 100644 --- a/drivers/iio/pressure/rohm-bm1390.c +++ b/drivers/iio/pressure/rohm-bm1390.c @@ -8,6 +8,7 @@ =20 #include #include +#include #include #include #include @@ -263,14 +264,14 @@ static int bm1390_read_data(struct bm1390_data *data, { int ret, warn; =20 - mutex_lock(&data->mutex); + guard(mutex)(&data->mutex); /* * We use 'continuous mode' even for raw read because according to the * data-sheet an one-shot mode can't be used with IIR filter. */ ret =3D bm1390_meas_set(data, BM1390_MEAS_MODE_CONTINUOUS); if (ret) - goto unlock_out; + return ret; =20 switch (chan->type) { case IIO_PRESSURE: @@ -287,10 +288,8 @@ static int bm1390_read_data(struct bm1390_data *data, warn =3D bm1390_meas_set(data, BM1390_MEAS_MODE_STOP); if (warn) dev_warn(data->dev, "Failed to stop measurement (%d)\n", warn); -unlock_out: - mutex_unlock(&data->mutex); =20 - return ret; + return 0; } =20 static int bm1390_read_raw(struct iio_dev *idev, @@ -546,38 +545,33 @@ static int bm1390_fifo_enable(struct iio_dev *idev) if (data->irq <=3D 0) return -EINVAL; =20 - mutex_lock(&data->mutex); - if (data->trigger_enabled) { - ret =3D -EBUSY; - goto unlock_out; - } + guard(mutex)(&data->mutex); + + if (data->trigger_enabled) + return -EBUSY; =20 /* Update watermark to HW */ ret =3D bm1390_fifo_set_wmi(data); if (ret) - goto unlock_out; + return ret; =20 /* Enable WMI_IRQ */ ret =3D regmap_set_bits(data->regmap, BM1390_REG_MODE_CTRL, BM1390_MASK_WMI_EN); if (ret) - goto unlock_out; + return ret; =20 /* Enable FIFO */ ret =3D regmap_set_bits(data->regmap, BM1390_REG_FIFO_CTRL, BM1390_MASK_FIFO_EN); if (ret) - goto unlock_out; + return ret; =20 data->state =3D BM1390_STATE_FIFO; =20 data->old_timestamp =3D iio_get_time_ns(idev); - ret =3D bm1390_meas_set(data, BM1390_MEAS_MODE_CONTINUOUS); =20 -unlock_out: - mutex_unlock(&data->mutex); - - return ret; + return bm1390_meas_set(data, BM1390_MEAS_MODE_CONTINUOUS); } =20 static int bm1390_fifo_disable(struct iio_dev *idev) @@ -587,27 +581,22 @@ static int bm1390_fifo_disable(struct iio_dev *idev) =20 msleep(1); =20 - mutex_lock(&data->mutex); + guard(mutex)(&data->mutex); ret =3D bm1390_meas_set(data, BM1390_MEAS_MODE_STOP); if (ret) - goto unlock_out; + return ret; =20 /* Disable FIFO */ ret =3D regmap_clear_bits(data->regmap, BM1390_REG_FIFO_CTRL, BM1390_MASK_FIFO_EN); if (ret) - goto unlock_out; + return ret; =20 data->state =3D BM1390_STATE_SAMPLE; =20 /* Disable WMI_IRQ */ - ret =3D regmap_clear_bits(data->regmap, BM1390_REG_MODE_CTRL, + return regmap_clear_bits(data->regmap, BM1390_REG_MODE_CTRL, BM1390_MASK_WMI_EN); - -unlock_out: - mutex_unlock(&data->mutex); - - return ret; } =20 static int bm1390_buffer_postenable(struct iio_dev *idev) @@ -691,25 +680,24 @@ static irqreturn_t bm1390_irq_thread_handler(int irq,= void *private) { struct iio_dev *idev =3D private; struct bm1390_data *data =3D iio_priv(idev); - int ret =3D IRQ_NONE; =20 - mutex_lock(&data->mutex); + guard(mutex)(&data->mutex); =20 if (data->trigger_enabled) { iio_trigger_poll_nested(data->trig); - ret =3D IRQ_HANDLED; - } else if (data->state =3D=3D BM1390_STATE_FIFO) { + return IRQ_HANDLED; + } + + if (data->state =3D=3D BM1390_STATE_FIFO) { int ok; =20 ok =3D __bm1390_fifo_flush(idev, BM1390_FIFO_LENGTH, data->timestamp); if (ok > 0) - ret =3D IRQ_HANDLED; + return IRQ_HANDLED; } =20 - mutex_unlock(&data->mutex); - - return ret; + return IRQ_NONE; } =20 static int bm1390_set_drdy_irq(struct bm1390_data *data, bool en) @@ -725,17 +713,16 @@ static int bm1390_trigger_set_state(struct iio_trigge= r *trig, bool state) { struct bm1390_data *data =3D iio_trigger_get_drvdata(trig); - int ret =3D 0; + int ret; =20 - mutex_lock(&data->mutex); + guard(mutex)(&data->mutex); =20 if (data->trigger_enabled =3D=3D state) - goto unlock_out; + return 0; =20 if (data->state =3D=3D BM1390_STATE_FIFO) { dev_warn(data->dev, "Can't set trigger when FIFO enabled\n"); - ret =3D -EBUSY; - goto unlock_out; + return -EBUSY; } =20 data->trigger_enabled =3D state; @@ -743,13 +730,13 @@ static int bm1390_trigger_set_state(struct iio_trigge= r *trig, if (state) { ret =3D bm1390_meas_set(data, BM1390_MEAS_MODE_CONTINUOUS); if (ret) - goto unlock_out; + return ret; } else { int dummy; =20 ret =3D bm1390_meas_set(data, BM1390_MEAS_MODE_STOP); if (ret) - goto unlock_out; + return ret; =20 /* * We need to read the status register in order to ACK the @@ -761,12 +748,7 @@ static int bm1390_trigger_set_state(struct iio_trigger= *trig, dev_warn(data->dev, "status read failed\n"); } =20 - ret =3D bm1390_set_drdy_irq(data, state); - -unlock_out: - mutex_unlock(&data->mutex); - - return ret; + return bm1390_set_drdy_irq(data, state); } =20 static const struct iio_trigger_ops bm1390_trigger_ops =3D { --=20 2.47.0 --5F1TfRMO12U7bMJL Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEIx+f8wZb28fLKEhTeFA3/03aocUFAmc/MCIACgkQeFA3/03a ocU2uggAhWItEd4R5MnnUV4GlzXrWakai2AQYn1X55tL7GcWXC8q4jaa0EJc6sg3 lJe+ghvqOjczyUncVUVqmIX2K6S8Db7En2bteVEC4JV9DTjU+DyeO3YCN5MOaP96 RRvnQNRVCtVcWpV+0iv4+vGMNl7ORfACcE5D0dkgyp0rgphcs+pgzlCXUoRmge2v RswMZP5lCrnLPn90BelsbzAkhsrg/4v8p8mXuQ/1HoG1jHA01/8ICnGjeW41dUy6 LDv+QsCle24pKQzc7RpyExchdNXS3neTVrG0TkO1XhC2Eyu5W/pzJqKdMDnZpdtK +U+thdvAkHbq/nPQJ/M+0xU4c/I6DA== =Dqg7 -----END PGP SIGNATURE----- --5F1TfRMO12U7bMJL--