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 D5CAA372B57 for ; Sat, 11 Jul 2026 07:58:00 +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=1783756682; cv=none; b=t96L3Biw0Le3sVaS3iqqySxnZSd4WRwVhsjBNBMd8XUUr1MQ9ASGcgAwn5PEi3LbDZM1ePHO8yKbKIfOVJm90QDPnqWZB7CuIDaSe0SYruqy+4yHc6YI4zueyeyH2LQCVSpsD8iwrpDI3mrWEf1ItZdzQ3P+/84nk0DYh2PruRk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783756682; c=relaxed/simple; bh=HbsyOvpG92EK5bZ+vbO6oreezg8KTKKLDJofKBiFN7M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fr0x87WHn5fI+jlltl+mU5s+A/vkiuItTgNLXfdnJHHIrDrFaQHpDqPt72lGUxH/Rm+7m8OKThTeMewV1nxycZsuUsZK9ePVUYriUgwp3iAVTpmzgYcKwFEsbo5wYZXfKFn7x+FmsPbzJMh2F/hDFy9KYycAA4Rj1Baqq37ipRk= 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-2cad4170e8eso18540215ad.3 for ; Sat, 11 Jul 2026 00:58:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783756680; x=1784361480; 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=I+FyZ60sn7H+J79M0uoDYHt7yjLqL155wVgQonsMAKc=; b=XAJHrHg4Z960XCi5jxltnyBh/AU9EKvaQ3pJvmYTfA19cM9suJn4jhCu54ZV99QBD6 IVZEA/S8n8jGU20PjuyVUtVWI1byBXNVIbJkKJqc7UcbGU8R2/pHlbczNHhDuugHrpNh hmCqPxJo45Lhnn+qHFfE9jkfn85aBrDuewgyCcG3ZbYAY153R47cQ1vDEqLk702cZ4Ww rx5TdP80TnKeNTgoXJkFKUkONnb5k/18EFUsWKSEdYLrXyIAqb8elGs6bWW4S7qgf+Bl U88l9zGaZ2qNgLP8eLkti7i36ZhZ6G9Oa+njZ4Vnr9kYz4Kh+qvudrRDxX6I75NIwtD4 UoXA== X-Forwarded-Encrypted: i=1; AHgh+RoSLY9UGfNdmWxy90q68vbmF1fpDwhHBQxvU1NVZgNQrsC2SvmNvH9NWV2P6UqrO+SElKGm+49VmqWe2Vs=@vger.kernel.org X-Gm-Message-State: AOJu0YyK44727gaWhHLubBa/ZudDT8EHGcWWU1IVj9TSuOnHHLTHrKor oy1bnum5VBEUPFYMz69vv1j7safVFCZJAC4WKZFoiDWLthokTqF54Ys= X-Gm-Gg: AfdE7cm8/YnUD2XSly1AE2AJXu0HDNIJPt99+mnUZeQxABEmm4VDNtD/uj9Lg+HOIe0 FkQXLsWHlVU/EFw3fckWDGfj6e4wD3fzjyTIwP09Fp4JbQvrBCPL/TI36Pdz2lTmIhacEUBAUII P3Kd2q5K79LPAYTzIeT0X1xczutp3eUZbEq9fTauDXwh5iM5TBnO889X3OcXbUCAhOqpUgaLDwX m0pTXfieVCziVajNZrYc0JI4P+VcQEpZwj7vghKzk2JSDb+WV2jnQO9gndT2CHeBsEj21PYhlru ot2ZN6OxNgnlhU0LmXaVDD4Z1vpWOklBE8kXWfaUnqRcfQjcDUBtqAH/8uXqtH+9MapqzgjZxQ4 79ZCkH1D7wSdCePdouI37+XPmJI/APr3k+J82rl9efx5LKii84UqUyeOhW7B//mA5mg8N8Ks40F 8JGpHtZri9JBpwlKurIxMwslArve0mmBVfaz3Qr8c0okUAhyMaPochi+eNemaODw5y5vtiseI1t uc46kOMx02pGlKDwPui6IxTIQ== X-Received: by 2002:a17:903:32c2:b0:2cc:9179:32e with SMTP id d9443c01a7336-2ce9e79fda6mr25363975ad.10.1783756680239; Sat, 11 Jul 2026 00:58:00 -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-2ccc9d1e279sm71130285ad.45.2026.07.11.00.57.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Jul 2026 00:57:59 -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 v5 0/3] hwmon: (applesmc) Convert to hwmon_device_register_with_info Date: Sat, 11 Jul 2026 15:57:51 +0800 Message-Id: <20260711075754.11358-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 v5 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 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