From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.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 0A5A919D07E for ; Fri, 3 Apr 2026 08:06:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775203588; cv=none; b=Bq+CIsNYAsUQRZQ39VWdA89yIc5G5QUgo1RG0yfMWb4IAfNF88waUrjGxxVkj+Y6bFcHAaVrvbDR0rxiVlXcnZNpNpuVPt1KPpkvgLp3jC2XZGEb2nC3TwjF10/1xZxBPwM+5Hm+JWntfsuB5LUGSVHhyEETCBSnnTjSR+aGcE8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775203588; c=relaxed/simple; bh=zwN0pITfJ3lXWhub6l+a/FFuVTrdHCz3d2uLlnjEChI=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=QufgggRwR9Q3V4SrIz/GX5LVbBCP4KJr3aMPP27qfrc7pslyxQ63hNNXSDu0yfxWuQYvgWx0MtyTLn4Vz9HxPiF0mSHLOTHSCWDz6mj3gXCXOAebLCpSCc+Ul6WSb0APeG32OSlNdMCI0zj1pUgN0oDOy4DEhngV8FClXk0CT1U= 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=MaT4WWdg; arc=none smtp.client-ip=209.85.215.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="MaT4WWdg" Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-c76c067bc51so639518a12.0 for ; Fri, 03 Apr 2026 01:06:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775203586; x=1775808386; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=hzTUcR1aoj1iRziUThqWuq2YXuaZb/N4OL64yRf40Lg=; b=MaT4WWdgMbwHiy+XPH4qxv3PxlK2ZFAvZ/mKB1HclZNEdmW1U5BuBtVKMRGauh+ARV YurUPinzPmcMuWhOcKNk6W7HMGnJix20nsB8xWmKbsrpX3ovMuLepTzLmjqjGsgHL9ka 2iFQMO+5s9iobDJflNEB5p/1+bki3xNyHyXx2XVmOuyc0kt8fSv/fhPOFzvwpOIA7KBD 3YsPvdy2Ufvmvefd7d2ju4B9xZ9A/pCAgNyAlyZ9agbg/C5QVZAaVkDJx647sMHTdoLG 0Vs/3gnSVmaIcGPctRAWBE6wRurCzpJnaCbHGfUIuTbuV9uYVSMZGOXTS9gYrcgavwqW 5/WA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775203586; x=1775808386; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=hzTUcR1aoj1iRziUThqWuq2YXuaZb/N4OL64yRf40Lg=; b=kJGOBYpahQe+ZCeo4d5OIhfwaenWfxi3aplX8ynkuSBjPhW5WJ4p0lw2g/oLNgx6xT 9jMAcdyGhi1ushvpL6Vn4+VlDG2mztF8fyhP0WnDtqqOtk/q3TYDvapjXouP9QvlLIcJ A6TG9sdsUxkDbrGbcN6vw/pKaqFwppVgZTNfpYfbTI0ZFTAYf6sU0tbrWBTa/FxnCnBs GDhH19bR58r1wlsZK0Imqsxl63VhC0h4zoXeVTzE/NaBsARf07EAafBKvZC6AU+fOO90 aXUOLVk1Isw+1OK+eZl2fnES66cJ0zQmKWhzm6pEmSlvL5cjAWvDU1piKpUYeGI42Wjy lS5w== X-Forwarded-Encrypted: i=1; AJvYcCU5G8cL9OmWacpHWPOi5a0EhK/s+6tqZSH4G9ygJL0+pxIYbm+Zd6sroqw1O+VEZgxVsswfCIytBF9laeY=@vger.kernel.org X-Gm-Message-State: AOJu0YxQTuHdRx3zUEGVKWLMvpUo0pcUm18XpsUCPnpeXJHaHmIjgtdT eEJx+KAbmAt6jVoL61awln8PCdLVCtydrYmTxNH+7wOGo/96T4syGgeG435PZTDiORM= X-Gm-Gg: ATEYQzxnAUPPV0i25RCn/cO0VLQus166EUEAREZIwFidUxCyirc3FGYFDIFSlGq7fKs QafWqTjwlzAJKu94dZHPaZ5tm9sceXY9d7XxjgR0RYfmRZz4myM/+R/URwluVd4rDIYG3L34F92 neyiwWGeloxlxmDLlCmhqBQeGyqj5jcNQKo0cWvf6JGhNcHEOPTj4WotW58Hioqsm1eb7msW9p/ 4PMPCF0ozHp9G3kTRl/iw5+EVsOcm6drEawI1XpfmJ3AfxdATCVQBHEbp3ahKJyHN4upjTfDgeH MxPSsKgGkkAdv79Tol7w7KJk9JbL+rfzBbgYiOKej0scfNHVxRCOhep+JgIK19DRu2ZnV82fX5b fgxhap5TcInM2G9xCbQSbrf/xVUtsZXyzvP/aYa6knCRVDA3CLGlrwEHbw9HZ6NvhxEqPbGwePa r6lsimQlrgP0Ep/2SfC24oEE6GMqcjvt6o4OKumReIDjngrskWU7kQ6oyD7mN+VehE84bcypWxd A== X-Received: by 2002:a05:6a21:6d9f:b0:39b:e837:5565 with SMTP id adf61e73a8af0-39f2f139280mr2236533637.28.1775203586235; Fri, 03 Apr 2026 01:06:26 -0700 (PDT) Received: from debian.ari ([152.58.181.253]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82cf9c6ad8asm5481093b3a.40.2026.04.03.01.06.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Apr 2026 01:06:25 -0700 (PDT) From: Archit Anant To: jic23@kernel.org, dlechner@baylibre.com Cc: lars@metafoo.de, Michael.Hennerich@analog.com, nuno.sa@analog.com, andy@kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Archit Anant Subject: [PATCH v7 0/5] iio: adc: ad799x: modernize resource management Date: Fri, 3 Apr 2026 13:36:09 +0530 Message-Id: <20260403080614.14213-1-architanant5@gmail.com> X-Mailer: git-send-email 2.39.5 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This series modernizes the ad799x driver by converting resource management to the devm_ infrastructure. This results in cleaner probe error handling, the removal of the ad799x_remove() function, and improved overall code maintainability and safety. Key changes in this series include: - A prerequisite cleanup to sort headers alphabetically. - Static allocation of the rx_buf using IIO_DECLARE_BUFFER_WITH_TS() to avoid dynamic memory leaks during scan mode updates. - Caching of VCC and VREF regulator voltages during probe() to optimize read_raw() performance and simplify power management logic. - Migration of regulators and mutex initialization to device-managed resources (devm). - Fixing a potential race condition by moving mutex initialization before IRQ registration. - Removal of the manual ad799x_remove() function and all goto-based error cleanup labels in ad799x_probe(). These changes ensure the teardown sequence is always correct, following the reverse order of allocation, and remove unnecessary boilerplate code from the driver. Changes in v7: - Added a prerequisite patch (Patch 1/5) to sort the header includes alphabetically as requested by Andy Shevchenko. - Moved devm_mutex_init() to the very beginning of probe() (before IRQ request) to prevent a race condition where an interrupt could fire and attempt to take an uninitialized lock. Changes in v6: - Addressed style feedback from Andy Shevchenko: used '(MICRO / MILLI)' for clearer unit conversion and refactored the optional VREF error path for better readability. - Removed the phrase "Reading the regulator voltage via regulator_get_voltage() can be a slow operation" from the commit message of patch 3/4 as requested by Jonathan Cameron. - Confirmed with maintainers that the devm_add_action_or_reset() pattern must remain to preserve PM functionality. Changes in v5: - Used devm_add_action_or_reset() for regulator disabling instead of devm_regulator_get_enable_read_voltage() as suggested by Jonathan Cameron. This was necessary to preserve the regulator pointers (st->reg and st->vref) required by the driver's suspend/resume power management callbacks. - Simplified voltage caching to use a single 'vref_uV' variable. - Converted mutex_init() to devm_mutex_init(). - Resolved error path ordering issues by using devm_* exclusively, allowing for the complete removal of the ad799x_remove() function. Changes in v4: - Simplified voltage caching to use a single 'vref_uV' variable as suggested by David Lechner. - Capitalized 'uV' in variable names as suggested by Andy Shevchenko. - Removed redundant 'if (ret < 0)' check in read_raw() (dead check). - Used devm_mutex_init() to replace manual mutex handling. - Introduced a local 'dev' pointer in probe() to simplify function calls. - Switched to IIO_DECLARE_BUFFER_WITH_TS() for the buffer declaration. - Moved goto removals into the respective patches where devm conversion occurs. Changes in v3: - Split the monolithic v2 patch into 4 logical commits as requested by Andy Shevchenko. Changes in v2: - Eliminated dynamic buffer allocation (feedback from David Lechner). - Cached voltages to prevent devm/manual ordering hazards (feedback from Jonathan Cameron). Archit Anant (5): iio: adc: ad799x: sort headers alphabetically iio: adc: ad799x: use local device pointer in probe iio: adc: ad799x: use a static buffer for scan data iio: adc: ad799x: cache regulator voltages during probe iio: adc: ad799x: convert to fully managed resources and drop remove() drivers/iio/adc/ad799x.c | 132 ++++++++++++++++++--------------------- 1 file changed, 62 insertions(+), 70 deletions(-) -- 2.39.5