From patchwork Thu Nov 28 09:01:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 13887803 Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (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 AF8F714E2DA; Thu, 28 Nov 2024 09:01:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732784520; cv=none; b=InMra2o4aueXzRcfTlv51i3CklznX39zr4QuBM4ymewFIJzL5zN/kiVAnvtu2/67H2XFv0OLsB+RhYaoc4qjOmcikThLyS+cqZtK93hBTzm2/BwuTA0RUaiDwB7Gug/1bG8YJNdCcjODAaZ3v6RiVopG/mEgPZgkXgTz07lrmw0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732784520; c=relaxed/simple; bh=9iAKaGh/DbLk003XwnkBukVNgkdYG557ngzrsYJV5+8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Gv6fIxVhOJdtP7+LK9K8aPJgmvcgGSme3CG3a3v0DRer2IZCQyJYYhsawxx+bxJY9SjeMEbY7PEEBQliKzWSffIhcU2bpfke+VXdE7/5Z12rw/iR2S9DHzKQVOoYRsRbqZSZUXSpLUWWbfzzshoJJcW5V5vc/o/q9/8hAtTcp3A= 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=l0A1PnIh; arc=none smtp.client-ip=209.85.167.48 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="l0A1PnIh" Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-53dd668c5easo647442e87.1; Thu, 28 Nov 2024 01:01:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732784517; x=1733389317; 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=LbQqOlzyfbKc10JjBshjc/RutnEOn1xDG4DaodXmXpI=; b=l0A1PnIhj5I4iz/zNvrsAju4dbx6VFZ1Pz2QvHS3BvBo7F14A1JB3gpOp65h8pBHZC 7YnffSSwOCmcyGcWsuFyMTI/I6l3jxYUjtIjRF5A6I30ZHG1cWGlsDHIImj5eGHGS55A e7JbbFBMPhupGKoXZQrv0hBA6Nyk6eXbY49TITRKWPx1kp8wIVR8/gXFaa1EqbBxSN+D SChAku8QJu3OIEepp1Gr57xeVJX0uSoVro5B0MJP6PfoP4L+zDImBi0Q8EdDKZ/0Ft8s 2EBKO0kpSJFiGKT/X16Vmmwnius2eDTy4JO90C3Hal8wIexqPfXM1oZz1lGd7/A5HtYa O2vQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732784517; x=1733389317; 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=LbQqOlzyfbKc10JjBshjc/RutnEOn1xDG4DaodXmXpI=; b=fumYOD+AZEEfacR+gqPSw5qFhenIick388JvKMGRKe7UbcawfSpWHb5c3GvLbl8WTr 3yTEEhPvM6KBR3Z90BmA4/5h/BYtrBVINbwArWi8BpTs8HeQvHs7BPaX8NN2ZM7DXY3b Fbb1zumFkPbEA4J/xW+a+32SAOFt/SbJeccZeT7ZHFHnufFptIFC01tyMzb7sjc5XFVE 6yzpxfP4+MWfuNRMf1y4a2eguaORmIEUtDEeZXWvYdrqh15WK4xReUw8gmCcmCPbnKBJ l5b7ATBug2GA0TL9sdJrTLtERnxkowZNuEd/SxpPAPtoF11g5nARDGinGPCgBEH6X0G5 sYMw== X-Forwarded-Encrypted: i=1; AJvYcCViuFGWDJbXvnPOQDBmCPwmsdHIM7jx+oIPddYLQFAzEmtpctlIiIlf/gV9IwDVDJGQDInbP/1GcoEtq1YX@vger.kernel.org, AJvYcCWILNDHekI6JnDRpii7sbQKPbrWJV1qurbwHy6lx7IfYNxZKxNyWqTaXxeCIKx/NV2MVx0BBgDoSSEq@vger.kernel.org, AJvYcCXmAZO2dWE9EXcIA/LHzeGSfr3SThnWl9ZARNbtNQaC4BORRsmt7YZI8BJnUDWmZcjTzHDCrZ2aL7ru@vger.kernel.org X-Gm-Message-State: AOJu0YzbnrJ1fY9CHfFbn/RTas6PZ9vj2LJCUY5MFgPLs1Nc88AVs+ej AK0ERRi5v+aHYI5Gj2hgv2weotLKIjM9kwyhICw5pqO4Vqnv/St6 X-Gm-Gg: ASbGncsOEZzWkgwFK2tgHO2y55VuVpoUBvcgJbrMsM11gWCKX9V9maLQXpUqZRVf3nX 0aweId8Hy8SjqaDjn+C1sjCJUpG3DAMFKpRFD/JBefFU4uoZrSudgpQH7M92D0DaMxaIsjbDS+/ ST77vTbZAs6AU0xKHbGP67l86UH0bo24notHvZdWcn6CaeEwgZWvwgGdC/IndwWjLcHxVq1xm9n BYbQwR1z5iHy7Nf3S48mojJh3tT6CBhnBkSqqwe6NohZcWnByNt X-Google-Smtp-Source: AGHT+IH7b7LC8Gj4Da9G3lVJLBr0b5tyTNivx9nqJbSGKQjXhyr7EugaEPgGYa4XTpFLOju08KI95A== X-Received: by 2002:a05:6512:2806:b0:53d:f7f5:bede with SMTP id 2adb3069b0e04-53df7f5bef1mr240716e87.25.1732784516450; Thu, 28 Nov 2024 01:01:56 -0800 (PST) Received: from mva-rohm ([213.255.186.46]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53df6496864sm115023e87.217.2024.11.28.01.01.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2024 01:01:54 -0800 (PST) Date: Thu, 28 Nov 2024 11:01:48 +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 v3 1/7] iio: accel: kx022a: Use cleanup.h helpers Message-ID: <4785f841ad5f131356ba78b4f3c76f676d86a2e8.1732783834.git.mazziesaccount@gmail.com> 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 --- Revision history: v2 => v3: - patch number changed because patches were dropped. v1 => v2: - patch number changed because a change was added to the series. - rebased on iio/testing to avoid conflicts with queued fixes. --- 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 b6664299e0d5..98953178a580 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 = {