From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) (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 85B252F25F0 for ; Mon, 30 Mar 2026 16:17:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774887478; cv=none; b=qOX2OCf4W0gl9uLuA6MTsx6Nl8AlSBX7njG71nOdGqLD+y/Byt0BjwpGtb+2QqdjhiSwliU5hX73iESqW1Gpja60Ns+K9PpDbingZB41Lk+wbjNR00CAlAkK1KP4aLt8KaaP+etT53sIXvXk+IUJN/rH6bFh0Ou2sqrQs/oClgA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774887478; c=relaxed/simple; bh=55Fpi3YNRzveKBEZXjkbJEpoQx1wD5kZYI8GBMZimyM=; h=Date:From:To:CC:Subject:In-Reply-To:References:Message-ID: MIME-Version:Content-Type; b=m6xhqiAmmtFSMcfKGlMoydw3x+7aDxE9JUG/wm5b1K8xQ3LzcKY3uN+g9VafpVr2jVSPEY8vXiyGg813tSYGlZC36FYeUt2s/ZLyjlr9VjH1JbsvIxHu7RcBNN+HsNaPRA83ZF7LnsL13FcUGMzZC7OX48aY9hyRDsFq/3vYqVY= 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=LfgyTz8L; arc=none smtp.client-ip=209.85.215.176 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="LfgyTz8L" Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-c76864f4e58so1345599a12.1 for ; Mon, 30 Mar 2026 09:17:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774887477; x=1775492277; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:references :in-reply-to:user-agent:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to; bh=MjSk1KnGXpIUBj4+4g/qAzrW90+WoFTFqElwxB+FxB4=; b=LfgyTz8LnGHu9MYI77A+dA4YC0SSaQ6dhOUWIe+tfQY13Te4WTiHeyuwQhgEUmd9x+ ZTU+k9svLBAPEGZy3yrCBdTcQQAEEJiPtiOlxoFKGNceDzEftf/tLerxfZDMl+G532nq 94b+vdLLu0zTi5JJTEJk0+kkYJWxMISBAH+eLCqMUPDFtTv8Wk3f9Mui+y9cOIotxHCB CBlQWoqDelAgnHTh/9f5qJC+VLbC1+qKfw9ZbsQw0dKR4/YE6dnRvt7vhYxBEaLDBvYn oPdcZvyfb7mRhKaRFwELyOy3TJfZTOLgYhXao2dFVgYDcZIDS0O7M8IA6/WTq79t8af9 Yg7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774887477; x=1775492277; h=content-transfer-encoding:mime-version:message-id:references :in-reply-to:user-agent:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=MjSk1KnGXpIUBj4+4g/qAzrW90+WoFTFqElwxB+FxB4=; b=MMMNKI0/cwyvV+pLsltUCBRZVulrxcXud0UEcxdzda7WxlYBnZ30e8M80baXnrR9X9 V6XXZXkmyc8O8zg62OzqXXmvvYTZbAFTECy9xB/lHyFkcusKFcdSL2OBy0pXOGMgUd8A Qtxl3IzNW4wxdOg8B8QcJw2bM0RHNmd34NrAh3sTU4fRXJW68RuOF/EBbACqDA5eCHUo QfRMADEZWAjMS1/OZYC1F91Pz4ll/XLSknabxWWAVOWwPSJl+QUed3xR/wX9HDOT5rsX rQwSEXryKJehfvPFrk46MBVcA37/hj61RCKFZWJXNL0bnjLxtRVNpywRZFgnmEb3toYY 8cPw== X-Forwarded-Encrypted: i=1; AJvYcCUBDz9N1AeMyM/PScFDFP5Gu7QYq5pWlm1B1YHByAGOBzvgS2h2GAznP93ntW9AncBBQP+mAAczynpw8tc=@vger.kernel.org X-Gm-Message-State: AOJu0YyeY79BEl1Cyk73X9zUmeHRy/86dKSYV/En0ilIkXQa0T00aDGt 0XjPhcO7/nlOUaKnnMow4lsz7NgiuXLz2iLiLWr6OH6F5kEEyvvv+DuI X-Gm-Gg: ATEYQzyx1tVZ+bfbwMhWBr730eN0pKHibsQFGCep0yCsTWSiD0948t4iO16mN+tsyCc i4bGpqJocY08RBYS75Uga1UIfv6B8phplgEuwN36epQCIkquM2OrZZLKZwsusG5ZEuSj1xPmNP7 lwPZIxivCrnhVhNPuR6sKHjtEZxvtufd+0eaSPj5twrfzj4upQ3XZrh1FX4KYvvBlzk/D32DgIf y6H/loShsazfzyQ9rM7YlGdux1q6tpJTprdA6LNlA9IdUWDFAnE2kircR/mevqTJ/QS4HLkHDLP MqwlLvCwz8MlkhUM0nRWAASyDFnZuBbmQXpsnzlsS4PdOwbhk1dK5CNAcH1g+12/Rn5rqB38JJk +81jIMD9M6kghLMYGz/KWwcSi6rviBc/p4F+XCw52ELBy5HLMV1mimafz64kb0Vy0KfWJyhXoz6 xEkM+TFOTE4G8xEPdkUWKRl1m4qk6abrNAVeg= X-Received: by 2002:a05:6a20:a126:b0:39c:c07:144a with SMTP id adf61e73a8af0-39c87a3c3a9mr13271334637.36.1774887476689; Mon, 30 Mar 2026 09:17:56 -0700 (PDT) Received: from ehlo.thunderbird.net ([2401:4900:ab01:67b0::55cf:3611]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82ca843bd8bsm7694484b3a.10.2026.03.30.09.17.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 30 Mar 2026 09:17:56 -0700 (PDT) Date: Mon, 30 Mar 2026 21:47:52 +0530 From: Sanjay Chitroda To: Andy Shevchenko CC: jic23@kernel.org, dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org, kees@kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: =?US-ASCII?Q?Re=3A_=5BPATCH_v4_3/4=5D_iio=3A_ssp=5Fsensors=3A_s?= =?US-ASCII?Q?sp=5Fspi=3A_use_guard=28=29_to_release_mutexes?= User-Agent: Thunderbird for Android In-Reply-To: References: <20260326081815.925373-1-sanjayembedded@gmail.com> <20260326081815.925373-4-sanjayembedded@gmail.com> <4017E54C-B25B-41AC-B4E1-F28576C2D64C@gmail.com> Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 29 March 2026 5:14:38=E2=80=AFpm IST, Andy Shevchenko wrote: >On Sat, Mar 28, 2026 at 12:24:11PM +0530, Sanjay Chitroda wrote: >> On 26 March 2026 2:52:06=E2=80=AFpm IST, Andy Shevchenko wrote: >> >On Thu, Mar 26, 2026 at 01:48:14PM +0530, Sanjay Chitroda wrote: > >> >> Replace explicit mutex_lock() and mutex_unlock() with the guard() ma= cro >> >> for cleaner and safer mutex handling=2E >> > >> >NAK=2E Please, be very careful when do such changes=2E > >=2E=2E=2E > >> >> - mutex_unlock(&data->comm_lock); >> >> - >> > >> >Pzzz! See what you are doing here=2E=2E=2E >>=20 >> Thank Andy for pointing this out =E2=80=94 you=E2=80=99re right, using = "guard(mutex)" here >> unintentionally extends the lifetime of "comm_lock" and can hold it acr= oss >> the completion wait, which is not safe=2E >>=20 >> I=E2=80=99ve reworked the change to keep the original locking semantics= intact: >>=20 >> - "comm_lock" is still explicitly unlocked before "wait_for_completion_= timeout()" >> - No sleeping paths are executed while holding "comm_lock" >> - Introduced small helpers to simplify the flow: >> - "ssp_send_and_enqueue()" for SPI write + pending list add >> - "ssp_dequeue_msg()" for safe removal from the pending list >>=20 >> Updated flow looks like this: > >If you are going to mix mutex_lock() with guard()(), it's even more NAKis= h >solution (id est worse than no change)=2E > Thanks =E2=80=94 agreed on not mixing "mutex_lock()"/"mutex_unlock()" with= "guard()"=2E This patch is intended as a cleanup to switch to "guard()", not to change = locking semantics=2E I=E2=80=99ll rework this so that it=E2=80=99s a consistent conversion: - convert it fully to "guard()" without changing the lock scope (e=2Eg=2E,= by restructuring the critical section appropriately or limiting scope with= {} )=2E Will update the patch accordingly=2E >> This keeps the synchronization boundary unchanged while reducing duplic= ation >> around pending list handling=2E I=E2=80=99ve also limited "guard()" usa= ge to short, >> local critical sections only=2E >>=20 >> Please let me know if you=E2=80=99d prefer keeping the list operations = inline instead >> of helpers=2E >