From nobody Tue Apr 7 19:20:27 2026 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 EA25F40DFDC for ; Thu, 12 Mar 2026 08:20:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773303618; cv=none; b=laN6t1iy/h3LmlarRPXDhYoa7aYdoFGJbq7ijAww64vQelCek4ZBbGr6Fs8OYTDmpSOR1MhYj4LiioBymPvlN6XcuF/nORX8DgNjnkXTYfD/zhxgmWVyy0iRCZJcZhUACplAS9HORGcj56cftSwrPnQjRTUhz2btaekSBCtGJi0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773303618; c=relaxed/simple; bh=Edaye/3CrVze15FJxoamDG+w6ueaUaBhBylJlmgV0tY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WF75vxE1gjTmHHzNQ8/6YPeYR1wlhyya8DGG7Qtv4pD4Na8FUopPnfjO3UAqgOBNLv4FAF6mgEerMIObndBNgYnYv6z9egpzDDPvaKhc2hUJjekYHQRtNNi8IcHFt9Anf0009vedHFspym5B/+038R1Bw6IvGnjvAvlqyMQ20j4= 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=m5/gHJOH; arc=none smtp.client-ip=209.85.214.171 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="m5/gHJOH" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2ae5636ab04so8450775ad.3 for ; Thu, 12 Mar 2026 01:20:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773303616; x=1773908416; 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; bh=6Da6CmLvCiNOlwy1v5QAVRL0Kuj4W/ug/xDjVba+jfw=; b=m5/gHJOHfmffvTAOog2oXqR7DOCuOw6VqWukAoe0kbKIMAGi78S8p95D6S9Z/68mhH +vWSN7lI3n4lgYFjqD1STMGxfjoRSpPHvrDZguv2+2nPKDMCCmXdUfls4EJFfA6uCxw/ +3L4jeMOToQwEu7HvLXOpgRgAEDjggAQMNb/EaKlaCx9iXlvy2fb6dFwg5etP+zSwE3/ xBKgM/j3+GKW7i8MXoxxkqM5IS7Pk8Jgl1ZzhqcO00gX50soytZjM0ZVUXD+Trrj7IRx yodJgxTo4QdJOT1V5+NitQ5LOpSKu2B5aOI6ie9qzENEWAu6QJzND7HlgJRl7MXJmj4b A39g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773303616; x=1773908416; 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; bh=6Da6CmLvCiNOlwy1v5QAVRL0Kuj4W/ug/xDjVba+jfw=; b=rITBu5grjDv0BklcCvWi5n9ThHwThIsxP8uYk61gNKqIiEjPvpLaudb12cxEAIWlWB /mFTkf2QqCZs7xdIfQ3xHS7cr9KEuEBTJQ/faxRkK4ZilAin1djA5IVvih6XLAfUriCd Tkx49GD3gXPdkN9pVzCyanN1OV4wipuYV3r1ENhlsDjMiJimYCM9OozXzHOgvCvY05Ie ZLoKLZ5ybpIg+78fRtrpCBRuYHFtpqcGkpbtb5JXit0UFL3AibwpwIOo5Lae8ot9Ghb0 O7ppJVLW1qHlveiutwZEiXaPU0teu27LpLoW9eFWj7VnHuMKRFrsY++pZVqovVvZaPtv BZIg== X-Forwarded-Encrypted: i=1; AJvYcCW2U927liJuRnIGRS5k1cvSERrJdroavygBHbOxuAdQuwD7TB2Dr2vRMKF/Y4cZExWSd/afFzK+eLkPzjw=@vger.kernel.org X-Gm-Message-State: AOJu0YzBBOYC/xX3DyvAzBGTKtz+jyNe00Bi632Nnh/0ZL7su2YISFMc 6EPE8lNwRUcWjy6S7JYqTSzCXveiWW1f5xCGFOEJwybQi27T0ATCA0sx X-Gm-Gg: ATEYQzwqWu4xRR+3bsG0LtXbzT03i3gE7LP1QIZ5IpoSkM16pPe7972uRlTtLIo5HXG Vy91qBcAwnx6JWGPD5gpoQotAnQSIv0XPpKXrc7UO+6DtHRJMuB745MzMbSyWFhILagsWFVql6q 4uYZraEWA6xN3wKV/r1kUDJ3dSqhdaGS7J0PoFU33I6X50NqC3vwaBJczyPPoOUleKADQ6lM61V Bz5FYHVlULknoIai7VBmoyLUTYsdqXh2/76VS1ZahkW7qvumI4r51eH2woyFQyZM3vC8cL4Zy+a 0wAP9SCXDC7DjRegvS8uvNg9ByvF76CF5wTNMRw3mQujj/svLSZdlQ1ZR0dUY6Lu9dKz9mmn1lM uOe41ARF/bcfuHY6kT7GVgag1QnAC+cdo0Bl092+r2Zx5jSobb8xBE2SZHBIfI5X+OfNFRO3WF8 4NSfM+Bt7cd7fLpsRDTMgxCJagvwI6wW/XMy97JT8WY+ZLZ5DfbsCACDEX7XBxhpnj2p+mbGXo2 SmmASGcje9liv9f91LjNQE= X-Received: by 2002:a17:903:2451:b0:2ae:4fdb:d596 with SMTP id d9443c01a7336-2aeae769ac1mr61672975ad.11.1773303616233; Thu, 12 Mar 2026 01:20:16 -0700 (PDT) Received: from fedora ([103.92.106.30]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2aeae24a91dsm64388905ad.31.2026.03.12.01.20.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2026 01:20:15 -0700 (PDT) From: Rajveer Chaudhari To: jic23@kernel.org, dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org, waqar.hameed@axis.com, linusw@kernel.org, sakari.ailus@linux.intel.com, harshit.m.mogalapalli@oracle.com, antoniu.miclaus@analog.com, andrew.ijano@gmail.com Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Rajveer Chaudhari Subject: [PATCH v3 1/4] iio: accel: bmc150: convert to guard(mutex) Date: Thu, 12 Mar 2026 13:49:39 +0530 Message-ID: <20260312081942.23858-2-rajveer.chaudhari.linux@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260312081942.23858-1-rajveer.chaudhari.linux@gmail.com> References: <20260312081942.23858-1-rajveer.chaudhari.linux@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 pair with guard(mutex) in bmc150_accel_buffer_predisable() and bmc150_accel_buffer_postenable(). This ensures the mutex is released on all return paths and allows returning directly without a goto label. Signed-off-by: Rajveer Chaudhari --- v3: stop initialising ret=3D0 at start, making clear about good path. moved return ret up into the if (ret) {} block in bmc150_accel_buffer_postenable(). v2: Cleaned mutex_unlock and goto in bmc150_accel_buffer_postenable(), Dropped Header alignment change. --- drivers/iio/accel/bmc150-accel-core.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc1= 50-accel-core.c index 42ccf0316ce5..4772dc6fcee9 100644 --- a/drivers/iio/accel/bmc150-accel-core.c +++ b/drivers/iio/accel/bmc150-accel-core.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -1480,20 +1481,20 @@ static int bmc150_accel_buffer_preenable(struct iio= _dev *indio_dev) static int bmc150_accel_buffer_postenable(struct iio_dev *indio_dev) { struct bmc150_accel_data *data =3D iio_priv(indio_dev); - int ret =3D 0; + int ret; =20 if (iio_device_get_current_mode(indio_dev) =3D=3D INDIO_BUFFER_TRIGGERED) return 0; =20 - mutex_lock(&data->mutex); + guard(mutex)(&data->mutex); =20 if (!data->watermark) - goto out; + return 0; =20 ret =3D bmc150_accel_set_interrupt(data, BMC150_ACCEL_INT_WATERMARK, true); if (ret) - goto out; + return ret; =20 data->fifo_mode =3D BMC150_ACCEL_FIFO_MODE_FIFO; =20 @@ -1502,12 +1503,10 @@ static int bmc150_accel_buffer_postenable(struct ii= o_dev *indio_dev) data->fifo_mode =3D 0; bmc150_accel_set_interrupt(data, BMC150_ACCEL_INT_WATERMARK, false); + return ret; } =20 -out: - mutex_unlock(&data->mutex); - - return ret; + return 0; } =20 static int bmc150_accel_buffer_predisable(struct iio_dev *indio_dev) @@ -1517,19 +1516,16 @@ static int bmc150_accel_buffer_predisable(struct ii= o_dev *indio_dev) if (iio_device_get_current_mode(indio_dev) =3D=3D INDIO_BUFFER_TRIGGERED) return 0; =20 - mutex_lock(&data->mutex); + guard(mutex)(&data->mutex); =20 if (!data->fifo_mode) - goto out; + return 0; =20 bmc150_accel_set_interrupt(data, BMC150_ACCEL_INT_WATERMARK, false); __bmc150_accel_fifo_flush(indio_dev, BMC150_ACCEL_FIFO_LENGTH, false); data->fifo_mode =3D 0; bmc150_accel_fifo_set_mode(data); =20 -out: - mutex_unlock(&data->mutex); - return 0; } =20 --=20 2.53.0