From nobody Mon Sep 28 21:52:20 2026 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 C2339396B9D for ; Sun, 16 Aug 2026 23:42:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786923764; cv=none; b=oxN6ei2ffpT4LgMTQVPxDYvBF3UTChzY8mfxLSDNq4U/5G2TSNP7b1Qkmxx3odqf0GKonCrB5K2R7ZitSXKvctLRRmgPoAFM2bTzqY62MMLrsuNari4rz1SBYvL2YsjA7volrzZRLWyiDkn7gUnrFfHvBerm22x6ZK0HJstku6M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786923764; c=relaxed/simple; bh=QK9K2KX+Sw8Z+PCUzt+d/R1Ay6ZHrvBZ2m5t9/NT3Hc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nrQ90I/qBMbFbL3FCOGVr2ELBLdYEyVq0qY7U/PcanNKfCiNpK1CmP0zFs32f3qEn5+pA/bEo+I9tRfelL/IC6GdcxcAiM603Ype4wDe+bXoSi1Yyo/G1IiwZLWlkLgR/urqz1zTOOSEo0W8dw0swsTvqRvez3/wYzRTKq0k7h4= 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=IUzGxm1q; arc=none smtp.client-ip=209.85.128.41 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="IUzGxm1q" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-498028b3d5eso35661255e9.1 for ; Sun, 16 Aug 2026 16:42:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786923761; x=1787528561; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=OB7vT6dn6m6phjSQeDb4kS8h3H6TRw2MJFOf2QVEbek=; b=IUzGxm1q5EGvx7mU3f44osv1j/JOA+MhXXFVeK40IbWrnzt7Z0aFUqiWmL8p5dqsAM pRSwXcMZAE8TT3OhAhtLOmKaOzm/9EUq0RMl84QfkRw/2WyLjeH8BOTQT8a9JopVKu4w 5rXSrMNUeOCyugEbG8Uz+TkDv23PuGLTt7qf51DEW6PQAUXjxoMcAe1bik5SuqkVxxQm MI0Jk4oHzlAdOT0pKTPEXwB2WLYAsCWMMP5MWc7UBCgVGnBTqGDc6wX2T0W8M/qFHltH ubo17JyLq9OzgPx3kHLUXMwdhFWLBFSpdRYUEMz3vrP3qKKPDALT/tDUFImtDZBZdpip IggA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786923761; x=1787528561; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=OB7vT6dn6m6phjSQeDb4kS8h3H6TRw2MJFOf2QVEbek=; b=eJEP9hzNT/Mg5rNEODBJirDiYnX0Iwlo/qC78ec7bJ8HCWU/p8TA0vmBq1AKJCF+97 9KCfx2+pJyorC+SeShA/T9ct2rUPDL2pDGwFvXlOVB9j55hsMbDRGffibT+zt98K5GDJ VeJPHkKq40iL4bICSGbS6GnQQEsSbRjI7T/3lsLGqhjzVejEFnfpOlHQ+QxOyMDxeXrc U6ak6fK06SLgY5R6imGC+8TjiZKFPGlNIESk95b3Iq4W4Dq38pqV+u7287T9N1dxrI29 zZTDFAEAqdolSXsBQN2pRubU1UQZefsJcd+ntbkZPEJrUtWL93zy0mvkRuawmPJJu7Um z2Jw== X-Forwarded-Encrypted: i=1; AHgh+Rr0iqCUQETwHTx6yOJ8ly8Vs6kQYM4F95yuJSCL9SNCiJ8tAjZQAPbr+k0VDf/jwR9uY8vaakTyVhf/nuI=@vger.kernel.org X-Gm-Message-State: AOJu0YyZT1hS7I2KBdXlmD+hCItSSnBv7CmUXwR1z3sh0qIXjhCtvD// b6/f5L+PoTO6TSEAVKxlR8avq7OehqC0PQGs3tSNDxvyqiZlvE9zY+cg X-Gm-Gg: AR+sD12xnkqQUb3xwHlE37iilaCQU1u5IRBanpJ/inp59HwEmx4Ea6hmo0bACnHdRn3 ixZjrqfrvj06NnRwtSrc9pB7IM0TRAfiEbUfS8kjt+lPee2diWuQxHgrYT3z+tRuUK+6vEfQFDm hdm/TngI70JfShSlWsL1HyrxThdFRuxuZe4dYpZYPeD6is+t0lD9KkPWa5H24lVDxCCK8Kwt5af Odh92wkUe+WMQf/z0xYFnMbpl8k3G7s/rC2eU3XSQDAT+fLAp3Gzu7UzR7VOfkpW0L/sfHWjDEO Q/hxPC9f6e1coiO2AxycdnU5y+nDzAXs0wXdRZEWXrwq+9i4LbXf1DUr1Zm4+xY+T987FxLv6qd enWxWIfexJ2+y100CYFQLP3pDr9Oqs3QbylZIkdTdxTBAFLdKDeE404nEZ0AFjXj61+bnObcG5Y U9sN+FrJsQ9MZaOrYCPQOGbPylotnE6THusIfgBFltTieG8QAm7yaShRDvTJAIjjbXZDXXje232 9ZYrGeJqDjTboTOcbON4601Bqy5f6tfte8= X-Received: by 2002:a05:600c:3e15:b0:498:ee7:e407 with SMTP id 5b1f17b1804b1-49987999622mr333020525e9.17.1786923760824; Sun, 16 Aug 2026 16:42:40 -0700 (PDT) Received: from MacBookPro ([2001:8a0:6c97:6700:ac71:8b16:e755:35c9]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-499960ff072sm112915555e9.3.2026.08.16.16.42.39 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 16 Aug 2026 16:42:40 -0700 (PDT) From: Gabriel Rondon To: Jonathan Cameron Cc: Andy Shevchenko , David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , Stepan Ionichev , Maxwell Doose , Yash Suthar , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 1/3] iio: accel: bmc150: sort header inclusions alphabetically Date: Mon, 17 Aug 2026 00:42:29 +0100 Message-ID: <20260816234231.14168-2-grondon@gmail.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260816234231.14168-1-grondon@gmail.com> References: <20260816234231.14168-1-grondon@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Sort the header inclusions alphabetically. This eases maintenance and prepares the file for adding a new include in a follow-up patch without introducing an out-of-order entry. No functional change. Suggested-by: Andy Shevchenko Signed-off-by: Gabriel Rondon Reviewed-by: Andy Shevchenko --- drivers/iio/accel/bmc150-accel-core.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc1= 50-accel-core.c index 10c67f47b5a0..d067da9b5ce4 100644 --- a/drivers/iio/accel/bmc150-accel-core.c +++ b/drivers/iio/accel/bmc150-accel-core.c @@ -4,24 +4,24 @@ * Copyright (c) 2014, Intel Corporation. */ =20 -#include -#include -#include -#include -#include #include -#include -#include -#include -#include -#include +#include +#include #include #include +#include +#include #include #include #include +#include +#include +#include +#include +#include #include #include +#include =20 #include "bmc150-accel.h" =20 --=20 2.50.1 (Apple Git-155) From nobody Mon Sep 28 21:52:20 2026 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (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 E1E5B3B5DE9 for ; Sun, 16 Aug 2026 23:42:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786923766; cv=none; b=GjQ/cjrP7XC7V4VanLsnwhuw8dIum2Yd8fl060xMNKYeabTRAQf4ItkXem5TPHXYJV8hYJ7d8EdQKOZzGkJlBwsvTluHMGpQsbvWL5opqt8YznJowXp6BgXyA9e9hHrX12RKqurbNzgbrEmoZ429AJkp611M2rm/n775G3sFZfM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786923766; c=relaxed/simple; bh=VrOjBtDyZdaPKMTzH33OYXvmL8G+wknlOLtphJjQl1c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F4OS45zbJq37/wwXrqRFdDY0dJWbFjN6Hy+plW+8c5rFLx//6Q3iBsCUDIJAPi6dx6+a0pr6fgVCnn7vDpHbL768WJjgrR955UeeLZDz9IfaNGm6Vj9C2+xsvRLfMieS2YsJBqG2njnArloQ4GxJVJg3cVGV5699M4jj5iQUi48= 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=JtMmysjv; arc=none smtp.client-ip=209.85.128.52 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="JtMmysjv" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-4998e0916faso11552655e9.2 for ; Sun, 16 Aug 2026 16:42:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786923763; x=1787528563; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=G8Fz286ccYp2u449U94NCIPiv/rPOIyX29xqISQ0+fg=; b=JtMmysjvUjYxClZ2FBrTP3CTcp/Pjy76tr0imHX0XRpBqXQZFaFEnenhpPZIj77Agv WQZ3QfTlRLsmIG1IU+KdZrXSDkOi7kgHDMIAIAp0TxYRos8I1LDDiP8/gGw61OyyQxgU J1kOobyWSorhYmY30F1pmQiB/uJibhgRTEB6BSCYeiuC1Af5qBbw+PEpdNVFnq6sGp0i JiWSL40TvBKFlxLaMpPzAdVHxn0iOPSxVs7k8rTP0UrDXJUsz7jS7fy+8+Zvd6OEcQWU e9xfVLEAMNGASctbKXXNJNYmZVB1RliUzKhPwmbDJwyVrzrqJa5hlM9vvAlQX7oNjL/M fv+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786923763; x=1787528563; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=G8Fz286ccYp2u449U94NCIPiv/rPOIyX29xqISQ0+fg=; b=I78pvbUHXTj9EeOyF7l4KQ30PymkUpdxOJ6qlsr4jPD7GwWVSu5sM/MDM1/x44Ewi5 J8j6vIqVqgbPq9ajIufCMjd728qbIYEiLufWhuOAv/go8NFJ5DomGGz29WDVP3wkBEFs jTEcC8BSvIIUusX0l73mLh+TRbj634hIfx5EE7SC52fXsvwS2t4hXA7bERiNwmkmf68s d8QUe++aE72g49516YUlxKnswLprXC6s0xU8WYM5xivLWemDMmo9ERMnb2/wNXyZjNho Vt9VPyHSFmNS9uw78n1TuQQUqs5sLyzOr5FK+gXa33iVQeZIKgWRCv99tfJjJnGBl5IP JJbg== X-Forwarded-Encrypted: i=1; AHgh+RrWmdz2bymc58V68jJ6lOxXBnJvNNi3wFXu76cHAYGgfX4yJmXpGW/GkZbpGiswPn5DKfgokUI2f9l9oX0=@vger.kernel.org X-Gm-Message-State: AOJu0Yx22zTN6/r8ZVWuDzsRRYi1vBWgr5mUHQ+dIVZJfJj6DEBD59v0 nFyQfaZT9G8noVPET2bD5VWRlpR9pOo+9SVBZWzIoj40efg6oeKwJvXD X-Gm-Gg: AR+sD13pdFTRuGsA2TzpZaDkXWijFJE2FcKOLHXU1F9AZ1bS08K+ngkQeL92TZmv9eB qOtyM9UPcZNpyYeh6eCArfI01tdaevbb2DOBPeLlA3SxOij7FExt3f8MNfNg6SV1ao4NRmDPbjC U6wo2pdIt7KVu6rGCH1uTDPQVyQroXBGJPNb7KGm1V2u/zfsHd3mSh2f5s++ph2ffxYuLPntWL3 Zo+aBk1EfLLHeQZ1n/kUMX4pxxHZK9Lywx15TyUROOlKgRIuNZtVaJBlOfrvvGX7JT3Jua0508j FBInNyfmlKaQP2z4tRfnm85vgdsHgva9PEv6hAGGkaJ080o2C8zerk4NG0AgtbT6+meFFCRS3Wt E3sjeY89ADAIrcow/8jyaVvqxCKvMEcwNMfULkAxBuMhYON0+az9vMvidNahisJvArN5/2pWcVa CsdFULGSIDSQnoQEbg8dWawSyd15z3k76whIRDZOnUJywf4RizuvQj7pk7b6wmaaV5WBSNYchBe N1aNXNFQiDpVrpuQ4Ij0zufxUv22IRlzf8= X-Received: by 2002:a05:600c:3485:b0:499:726a:a017 with SMTP id 5b1f17b1804b1-49987938e19mr343714265e9.1.1786923762984; Sun, 16 Aug 2026 16:42:42 -0700 (PDT) Received: from MacBookPro ([2001:8a0:6c97:6700:ac71:8b16:e755:35c9]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-499960ff072sm112915555e9.3.2026.08.16.16.42.40 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 16 Aug 2026 16:42:41 -0700 (PDT) From: Gabriel Rondon To: Jonathan Cameron Cc: Andy Shevchenko , David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , Stepan Ionichev , Maxwell Doose , Yash Suthar , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v4 2/3] iio: accel: bmc150: take the lock before checking ev_enable_state Date: Mon, 17 Aug 2026 00:42:30 +0100 Message-ID: <20260816234231.14168-3-grondon@gmail.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260816234231.14168-1-grondon@gmail.com> References: <20260816234231.14168-1-grondon@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" bmc150_accel_write_event_config() compared the requested state against data->ev_enable_state before acquiring data->mutex. Two threads racing to enable and disable the same event can both pass the check and then both call bmc150_accel_set_interrupt(), which tracks enables with an atomic users count. The inc/dec can become unbalanced, leaving the interrupt enabled or disabled against the callers' intent. Move the check inside the locked region so the test of ev_enable_state and its update are atomic with respect to the interrupt accounting. Fixes: 14ee64f438b8 ("iio: bmc150: exit early if event / trigger state is n= ot changed") Cc: stable@vger.kernel.org Signed-off-by: Gabriel Rondon --- drivers/iio/accel/bmc150-accel-core.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc1= 50-accel-core.c index d067da9b5ce4..bcbb9f0c830a 100644 --- a/drivers/iio/accel/bmc150-accel-core.c +++ b/drivers/iio/accel/bmc150-accel-core.c @@ -805,11 +805,13 @@ static int bmc150_accel_write_event_config(struct iio= _dev *indio_dev, struct bmc150_accel_data *data =3D iio_priv(indio_dev); int ret; =20 - if (state =3D=3D data->ev_enable_state) - return 0; - mutex_lock(&data->mutex); =20 + if (state =3D=3D data->ev_enable_state) { + mutex_unlock(&data->mutex); + return 0; + } + ret =3D bmc150_accel_set_interrupt(data, BMC150_ACCEL_INT_ANY_MOTION, state); if (ret < 0) { --=20 2.50.1 (Apple Git-155) From nobody Mon Sep 28 21:52:20 2026 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 36BFF4B049B for ; Sun, 16 Aug 2026 23:42:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786923771; cv=none; b=YuLM5GweLz/BaYTUGqYCBwQcB5XFvhWvVUC0bLtUM/LOzV+XD1bF1CAlmzHTyMECjif+KAdkA0Cm2bRLA+spdjfeH37zQPRiIvBBN9fK58Ax1om7Q2DUOPOvrg9KRKA1nMGyxshmdICl+9XcM7FDg5ggJ5w9FioR+yBCnqVBZaE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786923771; c=relaxed/simple; bh=FzzMrGUv6w6DQVY61mapg3obHLo8PGdztAwD/MP6F0M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EclfcJ5f6HbVcn/W3iWTCZosMewhm3peLAu8YEsC/YAfGM2UzRK6yPwFzwSuyYzoH537sYWfCbMKq+iI92Za9DupvJg4urKbRuN06mzKjgCyiQd3VhhkAZJi3MoHkCe8TSZbxxKsSTPU40VqwyTqYocIfIMiuH4Dim1GPONtVNg= 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=AvbuUJza; arc=none smtp.client-ip=209.85.128.53 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="AvbuUJza" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-49558ce01afso21088125e9.1 for ; Sun, 16 Aug 2026 16:42:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786923764; x=1787528564; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=e2fYgLPl/81/yBOdhfRHVtzi9qfVdQFcT9Xqjqn7iFg=; b=AvbuUJzaBNu6x+xo2uw86sWoyu6fhAH2mAjAhXcy113TyxtOMD9iwo3v1A2QhP24a1 ZGnXg5y6ycm7kRQv5vwedFqrXifd1Ks5Zk9DvdSakQGPG2hU+DinzZjN37LTSG6CIi2y iiSI+2m57U0XSD1MmKTk1HxJnGX+3NxzXeaK6TUcpt8bPRRD48TwNOMU217FasBcVQFh 2x/fCtmfc3Q1J5V/L7QlU2UlEk9DlEC1HzsDwKfBZgpstWSZDXZV7PYXIAN6nSmzKMex UxaiwctXP7NScnv6EruDL+5e7YNNe0RAGZvDIUu6hvXYac8sFZOYUO9AARQzu1z2hwTD aX/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786923764; x=1787528564; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=e2fYgLPl/81/yBOdhfRHVtzi9qfVdQFcT9Xqjqn7iFg=; b=AQN0lN0ACHFCE/HOsHFYZNKr7eqtp9lrnJiplNs1JtGlMgRco+Z2+58GDzIKB6ANhG 30kzhbvpioRE8hi9CpHK3olCUNj4p3dJ0d1zYFAuh45KckAQaTuqwNt/V9Xkg9MO+Frq j8up+2r9nfpGJT0eF3FY3qXKOJ1Rz3F5ohZkpT9rE5MmMriOLqmzrDqFDKsIInuHlSyl DBCVuxR5sYdmrwqGgpqfx4v8AbjtJFDWsv27k6fQAd6B+S+7XxlqsOs9TutQjyrxOX9a gd/534AqKjuuSZHc/b3HEt/rGVTSUUQ2eDtUzhL5fT4YDDrYtDMwqRClGHZjOOCW39sx emPw== X-Forwarded-Encrypted: i=1; AHgh+Ro1Gq4fc6eyBOpi2hCQzotZgwWJGbuQOhCn1JA41eOuDpN4dvBksTYtTl8fTsqyXdQEtnwNV1aziPnmeBw=@vger.kernel.org X-Gm-Message-State: AOJu0YzvuGbO74XATfODptSQgL0ulhrrBl7/g+Ic2D/tnCFfAxetJazz 19X2RMQBZTPNziGnEQJTODDKDa8E051m1t2l3eCxjCWLgM1/H+lcjxu+ytMMf3UJOjA= X-Gm-Gg: AR+sD12M3OP9ygDZU5GT/CySOe9NawunuThmfmKk6sv/MvtHtGKqN/1itiE3rEt8QlK FUCK9qe5xm+03wmLJE0ZpaVIF1MdO0Fwl9sooS8JjC8p3K/cQjXBR9rUXRcXz5UuVjz1Zjvttfu Wj3rnOFJhpMmRHivHqATY1n8Sza8J6+U6HYg3KF7F4rEf802zeU5j60CUQiOs7PvYyozRkHDgDV VMTdJqy6oeUEGd3L4xJQgyCEPLj/WtCxQIxuZRMr9olSyRfY4GaD8yXYJLMUoTNHs9EfZJOPp8L oRJ8poetBpIkAhQ8XBio4hVHKNoaVilMCRvY54UrKyISu2T6JkRV2JP/udcdXj9m+CQYwRvQOnf fNdbU89Qc5qjP91C1nzea45HcPMRvzID7owPzCrGkOhLZ3zJZbyfluT6ayHa6b2999JHfXTQ3Jr ICsD7McnUduKnqNwSLbBvsTE1LVuaeeJtq9pTLnvmhckC4zIbizcX6MrVy9KmrGCeqnCnOZJRCU bNexgjQq3x0FCB9mIXctbrHG9BDxHMc8kRM5H8N6zV5qwE= X-Received: by 2002:a05:600c:1c07:b0:495:4d5c:903e with SMTP id 5b1f17b1804b1-49987950d78mr298410475e9.7.1786923764200; Sun, 16 Aug 2026 16:42:44 -0700 (PDT) Received: from MacBookPro ([2001:8a0:6c97:6700:ac71:8b16:e755:35c9]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-499960ff072sm112915555e9.3.2026.08.16.16.42.43 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 16 Aug 2026 16:42:43 -0700 (PDT) From: Gabriel Rondon To: Jonathan Cameron Cc: Andy Shevchenko , David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , Stepan Ionichev , Maxwell Doose , Yash Suthar , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 3/3] iio: accel: bmc150: use guard(mutex) for mutex handling Date: Mon, 17 Aug 2026 00:42:31 +0100 Message-ID: <20260816234231.14168-4-grondon@gmail.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260816234231.14168-1-grondon@gmail.com> References: <20260816234231.14168-1-grondon@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Replace manual mutex_lock()/mutex_unlock() pairs with guard(mutex) and scoped_guard() from cleanup.h in the functions where the critical section covers the whole function body or a single statement. This simplifies the error paths by removing the explicit unlock calls before returning. bmc150_accel_trigger_handler() only holds the lock around a single register read, so scoped_guard() is used there to keep the lock scope unchanged. Call sites that take and drop the mutex several times per function (read_raw, write_raw) or unlock through a goto label (buffer_postenable/predisable) are left untouched and can be converted separately. Reviewed-by: Stepan Ionichev Signed-off-by: Gabriel Rondon --- drivers/iio/accel/bmc150-accel-core.c | 74 +++++++++------------------ 1 file changed, 23 insertions(+), 51 deletions(-) diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc1= 50-accel-core.c index bcbb9f0c830a..470f5da267ea 100644 --- a/drivers/iio/accel/bmc150-accel-core.c +++ b/drivers/iio/accel/bmc150-accel-core.c @@ -5,6 +5,7 @@ */ =20 #include +#include #include #include #include @@ -599,18 +600,15 @@ static int bmc150_accel_get_temp(struct bmc150_accel_= data *data, int *val) int ret; unsigned int value; =20 - mutex_lock(&data->mutex); + guard(mutex)(&data->mutex); =20 ret =3D regmap_read(data->regmap, BMC150_ACCEL_REG_TEMP, &value); if (ret < 0) { dev_err(dev, "Error reading reg_temp\n"); - mutex_unlock(&data->mutex); return ret; } *val =3D sign_extend32(value, 7); =20 - mutex_unlock(&data->mutex); - return IIO_VAL_INT; } =20 @@ -622,25 +620,22 @@ static int bmc150_accel_get_axis(struct bmc150_accel_= data *data, int ret; int axis =3D chan->scan_index; =20 - mutex_lock(&data->mutex); + guard(mutex)(&data->mutex); + ret =3D bmc150_accel_set_power_state(data, true); - if (ret < 0) { - mutex_unlock(&data->mutex); + if (ret < 0) return ret; - } =20 ret =3D regmap_bulk_read(data->regmap, BMC150_ACCEL_AXIS_TO_REG(axis), &data->regval, sizeof(data->regval)); if (ret < 0) { dev_err(dev, "Error reading axis %d\n", axis); bmc150_accel_set_power_state(data, false); - mutex_unlock(&data->mutex); return ret; } *val =3D sign_extend32(le16_to_cpu(data->regval) >> chan->scan_type.shift, chan->scan_type.realbits - 1); ret =3D bmc150_accel_set_power_state(data, false); - mutex_unlock(&data->mutex); if (ret < 0) return ret; =20 @@ -805,22 +800,17 @@ static int bmc150_accel_write_event_config(struct iio= _dev *indio_dev, struct bmc150_accel_data *data =3D iio_priv(indio_dev); int ret; =20 - mutex_lock(&data->mutex); + guard(mutex)(&data->mutex); =20 - if (state =3D=3D data->ev_enable_state) { - mutex_unlock(&data->mutex); + if (state =3D=3D data->ev_enable_state) return 0; - } =20 ret =3D bmc150_accel_set_interrupt(data, BMC150_ACCEL_INT_ANY_MOTION, state); - if (ret < 0) { - mutex_unlock(&data->mutex); + if (ret < 0) return ret; - } =20 data->ev_enable_state =3D state; - mutex_unlock(&data->mutex); =20 return 0; } @@ -845,13 +835,10 @@ static ssize_t bmc150_accel_get_fifo_watermark(struct= device *dev, { struct iio_dev *indio_dev =3D dev_to_iio_dev(dev); struct bmc150_accel_data *data =3D iio_priv(indio_dev); - int wm; =20 - mutex_lock(&data->mutex); - wm =3D data->watermark; - mutex_unlock(&data->mutex); + guard(mutex)(&data->mutex); =20 - return sysfs_emit(buf, "%d\n", wm); + return sysfs_emit(buf, "%d\n", data->watermark); } =20 static ssize_t bmc150_accel_get_fifo_state(struct device *dev, @@ -860,13 +847,10 @@ static ssize_t bmc150_accel_get_fifo_state(struct dev= ice *dev, { struct iio_dev *indio_dev =3D dev_to_iio_dev(dev); struct bmc150_accel_data *data =3D iio_priv(indio_dev); - bool state; =20 - mutex_lock(&data->mutex); - state =3D data->fifo_mode; - mutex_unlock(&data->mutex); + guard(mutex)(&data->mutex); =20 - return sysfs_emit(buf, "%d\n", state); + return sysfs_emit(buf, "%d\n", data->fifo_mode ? 1 : 0); } =20 static const struct iio_mount_matrix * @@ -906,9 +890,9 @@ static int bmc150_accel_set_watermark(struct iio_dev *i= ndio_dev, unsigned val) if (val > BMC150_ACCEL_FIFO_LENGTH) val =3D BMC150_ACCEL_FIFO_LENGTH; =20 - mutex_lock(&data->mutex); + guard(mutex)(&data->mutex); + data->watermark =3D val; - mutex_unlock(&data->mutex); =20 return 0; } @@ -1023,13 +1007,10 @@ static int __bmc150_accel_fifo_flush(struct iio_dev= *indio_dev, static int bmc150_accel_fifo_flush(struct iio_dev *indio_dev, unsigned sam= ples) { struct bmc150_accel_data *data =3D iio_priv(indio_dev); - int ret; =20 - mutex_lock(&data->mutex); - ret =3D __bmc150_accel_fifo_flush(indio_dev, samples, false); - mutex_unlock(&data->mutex); + guard(mutex)(&data->mutex); =20 - return ret; + return __bmc150_accel_fifo_flush(indio_dev, samples, false); } =20 static IIO_CONST_ATTR_SAMP_FREQ_AVAIL( @@ -1189,10 +1170,9 @@ static irqreturn_t bmc150_accel_trigger_handler(int = irq, void *p) struct bmc150_accel_data *data =3D iio_priv(indio_dev); int ret; =20 - mutex_lock(&data->mutex); - ret =3D regmap_bulk_read(data->regmap, BMC150_ACCEL_REG_XOUT_L, - data->scan.channels, AXIS_MAX * 2); - mutex_unlock(&data->mutex); + scoped_guard(mutex, &data->mutex) + ret =3D regmap_bulk_read(data->regmap, BMC150_ACCEL_REG_XOUT_L, + data->scan.channels, AXIS_MAX * 2); if (ret < 0) goto err_read; =20 @@ -1232,31 +1212,23 @@ static int bmc150_accel_trigger_set_state(struct ii= o_trigger *trig, struct bmc150_accel_data *data =3D t->data; int ret; =20 - mutex_lock(&data->mutex); + guard(mutex)(&data->mutex); =20 - if (t->enabled =3D=3D state) { - mutex_unlock(&data->mutex); + if (t->enabled =3D=3D state) return 0; - } =20 if (t->setup) { ret =3D t->setup(t, state); - if (ret < 0) { - mutex_unlock(&data->mutex); + if (ret < 0) return ret; - } } =20 ret =3D bmc150_accel_set_interrupt(data, t->intr, state); - if (ret < 0) { - mutex_unlock(&data->mutex); + if (ret < 0) return ret; - } =20 t->enabled =3D state; =20 - mutex_unlock(&data->mutex); - return ret; } =20 --=20 2.50.1 (Apple Git-155)