From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.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 ABC813839B2 for ; Sat, 11 Jul 2026 09:33:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783762412; cv=none; b=hLqWxoC2SDde5GZfBsD67QC5doykKPkogP70lVRMDKgauTFdmeqsh9pRXU2ryl6mD5+BB1pD3pSZS6WGVHa5pAOpBDqukkh7h8UekjTuxbS9Rg5P+fqNS4SFeptd2Uvis0vBBOLPIXCnFUF1x6hRZmN1/ddUcIkn+vypZVuBEDQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783762412; c=relaxed/simple; bh=/slVsF3COjGltdPeIj5o6DGpjlLWFU4qAGhkX0U+oMs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GsvU2kR0kyBSBLUj0uAPW6kIwsR0l9ClUFUmclN+WCoYybBW/NwASyEuy73mhsfDYyv6QPDwOacsHYwpuxBMRJQYoyue7OyKxbvDXSy1smlgts4CGwGr1LRXdqoXr0TTPxNd2EFZJQOO4TRKeTZTOnWvGbxSJV+X6rsIpk6v258= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-2cc73e322dbso17344245ad.1 for ; Sat, 11 Jul 2026 02:33:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783762410; x=1784367210; 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=WwWhKrHO548A3jBr2qhokXm7Ae5vd+VYqqVsY5WxyRU=; b=W5nPdRVjWbA5TrJQ4LqArwBXuJobeTNHMkvbNK7SJpaS3iOYaP5/9gk3VFccl8d6xK 2vKTnKLN6sYkA6Yt/hYEqSBhS8NM6qWDKxbptaJEzxhYSxrrzWhZFU/Nxi+ahCWWc063 uaZEcXYL/ZmocwEhLvLrOfoXbMaLBleN7Sje92o4uPcYfEwllD3f0yoAjJjdWTM81zkD JKZTp6ag2FL6RzilclkLY2J58UbZ+hhdrr2bOVG1Hylot8uZgB4U8vvZ/ypR/F+jWxf6 Qx0zv0tD07kjte3vFGMpzv5D+EVKoQednhff74nPWBNa791n+R5unnugnLW73hIC/0cp HEBA== X-Forwarded-Encrypted: i=1; AHgh+RqSqaMa7N/RpzAVkzArzh2wM9r68l4EyvRBjVK5AORfyx3Phh+KSlxhEq3es0Da0Rvc3plysAzsj0ZwiJ4=@vger.kernel.org X-Gm-Message-State: AOJu0Yw41EzrIT3QMdvq4ivJc6mjDa+fWvrhRFCIPVYW07rF6gm5ydRX qFVE0S0roZcNWx66pHilR2Oz9394t39DeDuwyLWtOxi8huO+SqHYGmGfGghm0IPabEqu X-Gm-Gg: AfdE7clbCVf46NAaiUaUhcZlZVn0WY8kQ/Scy+p6Gm1HZMCKWOOQxAeGozMd3c8MlAW noxZKLwPs/BCjckFNcI72Rvk5BXLztBTvgkRS5ADsA9EP8+32ENM1MnGq1P0v+M+06UYpwBYL1k L/ww+u/J0GzXroOspDo8Wf3SKouhRBYTBIf0UAlNVHGDa5bXrgFLKUt13nIc1hbxwRTjtT+hX3f fl4COZTQoVwheBsV5cRwCuADS3gnH7g+DICPAPN0kDKeH/l8rA95CZB1ypZhiZG8Sr92fPkihMX cE+EWS2PnFTpsRIp5Cl/VCgp3VGbA7GcXuywQ3pgbUtW7ChRiri/Iy3GFSWb3qxx7OeTa7ykvaz /EDn+UhWFAvMkRWKp/rVherJvvUURclMUawFeeDNb4Q9v+4NyOE0vFy+e/REi2AFgNJ/Mx7XjnX dOBMT78b4ljENfkv7aCdHh+m+39lXOKUvgX09O+IREKicnG86u7X1Voi/R1BOzQ1+fRXIK9eULG iVDfhHnI0ak7QhPgyxcsGxsaA== X-Received: by 2002:a17:903:19ec:b0:2ca:cbfd:7311 with SMTP id d9443c01a7336-2ce9f281721mr25439035ad.46.1783762410006; Sat, 11 Jul 2026 02:33:30 -0700 (PDT) Received: from penguin.tail0a1999.ts.net (61-228-52-13.dynamic-ip.hinet.net. [61.228.52.13]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ccc9d3d451sm71389135ad.65.2026.07.11.02.33.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Jul 2026 02:33:29 -0700 (PDT) From: Shih-Yuan Lee To: Henrik Rydberg , Guenter Roeck Cc: Armin Wolf , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, Shih-Yuan Lee Subject: [PATCH v6 0/3] hwmon: (applesmc) Convert to hwmon_device_register_with_info Date: Sat, 11 Jul 2026 17:33:20 +0800 Message-Id: <20260711093323.14529-1-fourdollars@debian.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260710123236.10508-1-fourdollars@debian.org> References: <20260710123236.10508-1-fourdollars@debian.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Hi Guenter, Armin, and Henrik, This is v6 of the patch series converting the applesmc driver from using the deprecated hwmon_device_register() function to the modern hwmon_device_register_with_info() API. Changes in v6: - Fix HWMON ABI violation for pwmX_enable by mapping manual mode to 1 and automatic mode to 2 (instead of 1 and 0), and rejecting invalid values. Changes in v5: - Split the refactoring into a 3-patch logical series: - Patch 1: Cache fan positions during register initialization (preparatory). - Patch 2: Fix a pre-existing concurrency bug in lockless cache validation by introducing proper memory barriers (smp_load_acquire and smp_store_release) with checkpatch-compliant comments. - Patch 3: Convert the driver to the modern HWMON API. - Address Sashiko AI's findings regarding the lifetime mismatch and teardown race condition: - Revert the driver from using devm allocations and managed hwmon registration. - Manually register with unmanaged hwmon_device_register_with_info() and manually free structures via applesmc_free_hwmon(). - Ensure unregistration order is safe: call hwmon_device_unregister() at the very beginning of applesmc_exit() to close the sysfs nodes prior to freeing the register structures and dynamic memory. Changes in v4: - Convert to devres-managed devm_hwmon_device_register_with_info() to fix a lifetime Use-After-Free mismatch when the driver is unbound via sysfs (releasing devres-managed attributes memory while keeping the hwmon sysfs files active). - Declare hwmon_dev locally in applesmc_init() and remove it from the global static variables, and clean up the redundant manual hwmon_device_unregister() call in applesmc_exit(). Changes in v3: - Fix a recursive mutex deadlock in applesmc_hwmon_write() when writing to pwmX_enable by using applesmc_get_entry_by_key() to resolve the entry locklessly and then calling the underlying raw SMC read/write calls. - Fix a fallback fan label truncation bug by pre-padding the generated fallback string with four spaces so that the "+ 4" pointer arithmetic offset yields the correct label "Fan %d". Changes in v2: - Abandon the minimal dummy registration approach in v1. - Fully convert the driver to modern HWMON ABI standards by dynamically allocating temp and fan channels at initialization. - Rename legacy non-standard attributes to comply with the standard HWMON ABI: - fanX_output -> fanX_target (HWMON_F_TARGET) - fanX_manual -> pwmX_enable (HWMON_PWM_ENABLE) - Dynamically register the remaining non-standard fanX_safe attributes under HWMON class directory via extra_groups. - Load and cache fan positions in smcreg.fan_positions to support returning labels by reference in .read_string. - Clean up unused static attribute groups and show/store callback functions to avoid unused symbol compiler warnings. - Verified compilation and successfully tested on real MacBook hardware. We appreciate your review and comments on this refactoring. Shih-Yuan Lee (3): hwmon: (applesmc) Cache fan positions during register initialization hwmon: (applesmc) Fix lockless cache validation data race hwmon: (applesmc) Convert to hwmon_device_register_with_info drivers/hwmon/applesmc.c | 490 +++++++++++++++++++++++++++------------ 1 file changed, 338 insertions(+), 152 deletions(-) -- 2.39.5