From patchwork Wed Nov 13 11:20:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 13873463 Received: from mail-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) (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 2F171200B8F; Wed, 13 Nov 2024 11:20:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731496817; cv=none; b=qmQgkvNQYJ6te9dtSP2xiUe0YJK06kab177WqO3INj0peDq/K2UwbIKyLCh4RpdXCGzadXMMtO9qtKYCCmSOdWDMj1fHx+d9tN+VdgzKXXTOdDvx6SbtW9VUpfE9OWLKgMwaadV1Qbu0Pf1S+KY6cY/BLSxdlxFZ/S276a8Qj6E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731496817; c=relaxed/simple; bh=os6NKRV3DiBYSPOB+jwd9UanJgfU0jAP2AO4Z1GIi2I=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=AhWdQBSG49ZaiF2paAPgWdbbDJ9PN3R4tO75Rh9xKSAvzDDGbiZ5mQBUiiuODWucyr5CHvjgtcFZlijMuCwwgzTtedwkn7NKUDtB4T2oJvfuTDvYXHmj18NNXpGSMgg8gvpyuHyAzZYfZDdNKl7TEf5i+9XnrubQGNIZN1I/LHg= 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=GM1JRGqO; arc=none smtp.client-ip=209.85.208.181 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="GM1JRGqO" Received: by mail-lj1-f181.google.com with SMTP id 38308e7fff4ca-2fc96f9c41fso6709441fa.0; Wed, 13 Nov 2024 03:20:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731496814; x=1732101614; 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=1hbj9OsuVyivUpj0F9cGsgeSME0OksJ9+laGHOnSVXE=; b=GM1JRGqO4uKE1wmXGsOrn8O4nYnyAtHRAOAdpzCTvi5Zn9ado4u89eC5vXHl+5NVDX yE+UoKdcH21gfqSrNTx+Sy0Z5eLHSssSAPIScjZlpXpIIOtZljcA5lPzmyfsnOq8zBLx sgoFouzHi7XMgQ/Wxcjg3ZzbDhSYTtEq9C2jgXASiJRupBdfjUJ0wtV08u5qA8oPnA5M jfF6nlHHl9WmlKtqcQ0EyqED7IA5Z1lzg4TOFeg6KNH1CrbyvoF8RbNyatsLrZnll+Wu NNSerlGiIkEoim13M0kty3KCqudOeafx+wvLlh8VRZ9tsZqgQSfhV1SsX3UukHzMG9sY LjCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731496814; x=1732101614; 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=1hbj9OsuVyivUpj0F9cGsgeSME0OksJ9+laGHOnSVXE=; b=VhgXREUFYUAZ3LqYjAYliX4AEFBi6mt07kKEYnZJtNPnt5G7PgcaMONfEgzM/SJqx0 JK11J7wO7opeB4623rieDx8A+3mmxFkEIRBYyw+GIG84tw40ocbxZcvg/ZTuiWcMznlA s0xpUH9PjWIt3MZ/3qf739vD2fNjN0jArp6rrNB/+k2EWmM7Us+L2DF3Utf1w5Vf7cFt AsdoQSQG/wIiSAvTd+dt7cvFk5hZmB67fHqr0xpzWg3ob5rCBVisOk3Ir1NBFooJMXeW WwkGSsMrmoeEtIiXEUc8rSB39MRMDXuwkQYah0an5XfrhN8vRzJvCRPP81EiJ6rAmFKr Rx/A== X-Forwarded-Encrypted: i=1; AJvYcCUkhh38Wf0uc1AjVD3+/IoQzRGjXENa+CJcqE1IgM9lhkgf5vHtYIpLjKV7GLmnvfoasn9d9kezrK0l@vger.kernel.org, AJvYcCVwfpVXzxGth9f3V4VO9w074SrT6Lb5mGKTN72dFxZ5RmjSVi50AWQr6GfAndWxdQciJHrDQCjLfosl@vger.kernel.org, AJvYcCWKmxCkwgR3bCyfkur+D+BqkaKwzSiQMWiDLVXz7KhiZvlLuViHRpQRorUMS0k1xcefMo+lYhy1rFsa1pVM@vger.kernel.org X-Gm-Message-State: AOJu0YwTsU5dVvm+EOMioiDxOzmb0CY9zGRAwKObe9A4shz1tw21jJ4w qah6eTbpKMwmxvpa6mnp4DKfuOZjWpRLHEK22fijN76Ocz+Dh0JR X-Google-Smtp-Source: AGHT+IHXn4iXxA2U9pThQOnrrgVLz1QpNkFzGPtAT6wxdiOH2IWX7M5CPlQrdjoqW45JdSEFgXqZ+Q== X-Received: by 2002:a2e:9ac7:0:b0:2fb:5bd1:c293 with SMTP id 38308e7fff4ca-2ff209f4d0amr50833241fa.21.1731496813985; Wed, 13 Nov 2024 03:20:13 -0800 (PST) Received: from mva-rohm ([213.255.186.46]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2ff179d4aa8sm23347541fa.97.2024.11.13.03.20.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Nov 2024 03:20:13 -0800 (PST) Date: Wed, 13 Nov 2024 13:20:04 +0200 From: Matti Vaittinen To: Matti Vaittinen , Matti Vaittinen Cc: Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Matti Vaittinen , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/5] iio: accel: kx022a: Use cleanup.h helpers Message-ID: References: Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: A few functions in KX022A need to use mutex for protecting the enabling/disabling of the measurement while configurations are being made. Some of the functions can be slightly simplified by using the __cleanup based scoped mutexes, which allows dropping the goto based unlocking at error path. Simplify error paths using guard(mutex). Signed-off-by: Matti Vaittinen --- drivers/iio/accel/kionix-kx022a.c | 61 ++++++++++++------------------- 1 file changed, 23 insertions(+), 38 deletions(-) diff --git a/drivers/iio/accel/kionix-kx022a.c b/drivers/iio/accel/kionix-kx022a.c index 32387819995d..321bb2c35578 100644 --- a/drivers/iio/accel/kionix-kx022a.c +++ b/drivers/iio/accel/kionix-kx022a.c @@ -5,6 +5,7 @@ * ROHM/KIONIX accelerometer driver */ +#include #include #include #include @@ -448,7 +449,7 @@ static void kx022a_reg2scale(unsigned int val, unsigned int *val1, *val2 = kx022a_scale_table[val][1]; } -static int kx022a_turn_on_off_unlocked(struct kx022a_data *data, bool on) +static int __kx022a_turn_on_off(struct kx022a_data *data, bool on) { int ret; @@ -469,7 +470,7 @@ static int kx022a_turn_off_lock(struct kx022a_data *data) int ret; mutex_lock(&data->mutex); - ret = kx022a_turn_on_off_unlocked(data, false); + ret = __kx022a_turn_on_off(data, false); if (ret) mutex_unlock(&data->mutex); @@ -480,7 +481,7 @@ static int kx022a_turn_on_unlock(struct kx022a_data *data) { int ret; - ret = kx022a_turn_on_off_unlocked(data, true); + ret = __kx022a_turn_on_off(data, true); mutex_unlock(&data->mutex); return ret; @@ -912,18 +913,19 @@ static int kx022a_fifo_disable(struct kx022a_data *data) { int ret = 0; - ret = kx022a_turn_off_lock(data); + guard(mutex)(&data->mutex); + ret = __kx022a_turn_on_off(data, false); if (ret) return ret; ret = regmap_clear_bits(data->regmap, data->ien_reg, KX022A_MASK_WMI); if (ret) - goto unlock_out; + return ret; ret = regmap_clear_bits(data->regmap, data->chip_info->buf_cntl2, KX022A_MASK_BUF_EN); if (ret) - goto unlock_out; + return ret; data->state &= ~KX022A_STATE_FIFO; @@ -931,12 +933,7 @@ static int kx022a_fifo_disable(struct kx022a_data *data) kfree(data->fifo_buffer); - return kx022a_turn_on_unlock(data); - -unlock_out: - mutex_unlock(&data->mutex); - - return ret; + return __kx022a_turn_on_off(data, true); } static int kx022a_buffer_predisable(struct iio_dev *idev) @@ -959,33 +956,29 @@ static int kx022a_fifo_enable(struct kx022a_data *data) if (!data->fifo_buffer) return -ENOMEM; - ret = kx022a_turn_off_lock(data); + guard(mutex)(&data->mutex); + ret = __kx022a_turn_on_off(data, false); if (ret) return ret; /* Update watermark to HW */ ret = kx022a_fifo_set_wmi(data); if (ret) - goto unlock_out; + return ret; /* Enable buffer */ ret = regmap_set_bits(data->regmap, data->chip_info->buf_cntl2, KX022A_MASK_BUF_EN); if (ret) - goto unlock_out; + return ret; data->state |= KX022A_STATE_FIFO; ret = regmap_set_bits(data->regmap, data->ien_reg, KX022A_MASK_WMI); if (ret) - goto unlock_out; - - return kx022a_turn_on_unlock(data); - -unlock_out: - mutex_unlock(&data->mutex); + return ret; - return ret; + return __kx022a_turn_on_off(data, true); } static int kx022a_buffer_postenable(struct iio_dev *idev) @@ -1053,7 +1046,7 @@ static irqreturn_t kx022a_irq_thread_handler(int irq, void *private) struct kx022a_data *data = iio_priv(idev); irqreturn_t ret = IRQ_NONE; - mutex_lock(&data->mutex); + guard(mutex)(&data->mutex); if (data->trigger_enabled) { iio_trigger_poll_nested(data->trig); @@ -1068,8 +1061,6 @@ static irqreturn_t kx022a_irq_thread_handler(int irq, void *private) ret = IRQ_HANDLED; } - mutex_unlock(&data->mutex); - return ret; } @@ -1079,32 +1070,26 @@ static int kx022a_trigger_set_state(struct iio_trigger *trig, struct kx022a_data *data = iio_trigger_get_drvdata(trig); int ret = 0; - mutex_lock(&data->mutex); + guard(mutex)(&data->mutex); if (data->trigger_enabled == state) - goto unlock_out; + return 0; if (data->state & KX022A_STATE_FIFO) { dev_warn(data->dev, "Can't set trigger when FIFO enabled\n"); - ret = -EBUSY; - goto unlock_out; + return -EBUSY; } - ret = kx022a_turn_on_off_unlocked(data, false); + ret = __kx022a_turn_on_off(data, false); if (ret) - goto unlock_out; + return ret; data->trigger_enabled = state; ret = kx022a_set_drdy_irq(data, state); if (ret) - goto unlock_out; - - ret = kx022a_turn_on_off_unlocked(data, true); - -unlock_out: - mutex_unlock(&data->mutex); + return ret; - return ret; + return __kx022a_turn_on_off(data, true); } static const struct iio_trigger_ops kx022a_trigger_ops = {