From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (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 BEF991991D4 for ; Sun, 12 Apr 2026 09:38:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775986687; cv=none; b=jVkk/d2QNegPR3J04p/m0fjgFV8+OB+mgvmPBGNUHhFJk0bihvg8MnDzA+0eakcTOPuk9jQyHrf/XxIifIrn5ii7FIfEQ3nM87BM9FrqN3gJpxPPE0YLtkI1N02gz7VQPKxx1qGo2sNagi1+PdT1Lg9e4GRrxHPi5HadfMDcNKY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775986687; c=relaxed/simple; bh=NfppAcx4h7mFpBVBGvpC3TbT8jbBt8+mLrq17bPTb50=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=jhDLJ8V/cuR0CWHPdfLVLF0y8pzOc8JWoa08VuRNW8GN0TuvmSta4XmXHJKR+jHocwZJXbU9CH89cPDrdiqrKkXrp6UzDrmbpd3RAJHRorZcxpYDy5HTytniNHQsfG38C1tGdZ8RBkVQ/W4kbI4LAAUQqI3ORgRPeFGVXj6Qn8w= 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=oH+OnZfm; arc=none smtp.client-ip=209.85.210.177 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="oH+OnZfm" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-82f22f6b0feso356475b3a.0 for ; Sun, 12 Apr 2026 02:38:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775986685; x=1776591485; 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=Iivg2YP+C1CTGh9qXKnltagD0RTxEYWwojJWATan3Y0=; b=oH+OnZfmR/cvNRJcx6mrakWeDtBX11mPEHLPFDmFK7aB6MFddjOm6xBz3EG3gwHBd6 7cSY8llG13jieaXElbybIcKm/9KPhkZJG51ryDO7ODG5K1V16NNCi6wugUAdCgkF1QQc MplMwIkpuOWUp1xRHNNg2WWt2to8a0NRzEbvgsyRWxEUCXs10hh8fDWe9KhzkJq2U0zD 8isL64wfNSekM/IBl7X1UkKpsnAwH0D8EWCjY2Ts3tDGTWDaVAVlYmGYtt75xmqGlhtY tlALnPSrnv5kN5+jINn4q5ivCcUrXlWAtpKEyPCzsGJ40O79MIlfYUb2dhPzVZXOtpdk ULKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775986685; x=1776591485; 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=Iivg2YP+C1CTGh9qXKnltagD0RTxEYWwojJWATan3Y0=; b=IIbufSUPAVhPQeMuqY3E40j/d9Dvt1tICrWvfwaXYCCPamuB1mEMrzuuqo9UoeYMIk rD3SlMRzSOph8NTyPW32PZBJlVPwDunzO1fp/HD+1u4robg1rCkPRAImTM07WZksirL9 B5Z+Gf2MuTabbe4q9zl+NVTmhJ/fOCkhNCQdiuwln7TdkbIPdPXh0wNkoufmUUCwuXuU 5J6aFN45n5VWp5yMcTtAUJB/ohC//aoydaMVjnc5sH3LbTGo+asiPSdygTHf0KuLHZ3+ Hx4qy531G7voxBTopk8SmiSn4fltB/wMMlO3yBPil4qr+yqL5HWzxjer9eRDxmSb4Wja 60CA== X-Forwarded-Encrypted: i=1; AFNElJ/myjOsh0WcOND5Do+12kPT+HHnRVCh8XMKTlgqpkqRpRUySoGeyshBWvfB9JfSq6DAKOE/uEvxARk05vM=@vger.kernel.org X-Gm-Message-State: AOJu0Yw80qF/SHhLypD9rG25AAjcZhmdmJDuVrODhgmOYNtBnxpWmh7J 4sBzYc27ffNBQazEOLaG4eTIwz0yjlHFZkE5qUhqbCMMmJ8hq1qIFsK5 X-Gm-Gg: AeBDievLsH+maVo1pu/KBDRV9LryPbZ4x6E4WJ3AkB78RAMa0OVdrsNve8qUJH5B4mX /2wMu0mSasqn9gvMP9nuX0OEk4r3uvI+z783UQLO3n0ZpxdsTON4ZksrvxJkrjyLA0pFnhJshVG CZEtdGxrEu3teXM1Dhurm+O4rY0Ahc+gkZu21U3H4lA935BcbiWvoEaJh8ho8HTyjfNJGIHHt70 zrFBfun54Kw2ube3YXpH3jlty10dXZ37GRiNkTOnSwyoMetSs1zYjour6zPbY4Rwr81i/hDiOQC BVA0Th8SNzCgX+P2R88qHFCIwYH5RWvOKsdAuxzLhx9H0nIM9gOfW/LsA2wY/kyFbOjAMocmYZV c5ycB8tqFAX7EAdRyQ0l/o6sdNOe4mNazP2G39toh6kGg2yloi6Bf6Y4w1Ky5zALST8V0UmEvC/ iFCQvhaobvAJd3whossbrKOusL0YVgpsEmtInHjCvGhXYeOFcabudw8uatABWqriGBbz7dtUJp X-Received: by 2002:a05:6a00:10b:b0:82f:1d38:f68f with SMTP id d2e1a72fcca58-82f1d38fc7bmr4444350b3a.31.1775986684965; Sun, 12 Apr 2026 02:38:04 -0700 (PDT) Received: from debian.ari ([152.56.156.42]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82f0c36130csm7885038b3a.24.2026.04.12.02.38.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Apr 2026 02:38:04 -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 v8 0/5] iio: adc: ad799x: modernize resource management Date: Sun, 12 Apr 2026 15:07:34 +0530 Message-Id: <20260412093739.17116-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 v8: - No logical changes. - Dropped unverified performance claims from the commit message of Patch 4/5. - Added a blank line for readability before devm_mutex_init() in Patch 5/5. - Added Reviewed-by tags from David Lechner to all patches. 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 | 133 +++++++++++++++++++-------------------- 1 file changed, 63 insertions(+), 70 deletions(-) -- 2.39.5