Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp491682rwe; Wed, 19 Apr 2023 01:36:01 -0700 (PDT) X-Google-Smtp-Source: AKy350awFKbXbvACI9SE6Pu+smHhve8/gN2UwBe8Uo8FG78/fVqy+Q7kVROkDB6PTGMdfKa/5fo5 X-Received: by 2002:a17:902:d40c:b0:1a5:253f:ace0 with SMTP id b12-20020a170902d40c00b001a5253face0mr4261097ple.37.1681893361349; Wed, 19 Apr 2023 01:36:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681893361; cv=none; d=google.com; s=arc-20160816; b=kg++FYSwYuWfahghp9Gma756l9O+24ZHnogZpiVceL8KSXLGyI0Q4tCFl1ky/kzCEx V7ABd40wJg1m3xHv9pVLAKmTSzd2U6rZ/PkK4tlCaRSSLA8KWmKgTfp2j7FfkG2Z5qqU k3BnHXHdrDJ4qy8seJqJVNxLxjpje8ge1vXodp2/rWBh/qQsL1oJJ3huyIe0MIIOqCuR cGdkgF1hAXQLt0/sBxpjUpr9+AUqvgidEykQB+/udFV2XCIjX1r8+HsN8bRouuUHdjTF bDOHaw/LVJEYaFNyIwCKPxkmcg/mJhcB49om+iphsKtHZt1rUieBP+2lKKOwrVciVgue UQ5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ZFr0nNH7gKvfGd1xmrDdwsbO4A4hFnitswKb+PdA3E8=; b=HxdbwAQN5Jn16HjHIS7uNmYTaDaDtzB0fuJx9i943jqEzVHS/SILprEF1+glHX30ho KFtvEDKA7wTR9EKq0Mri5gDorAtTdYx8La2oFU5MOySxzVlwRngzlfPV6sH2x6sM/9cz qJGvgkERnRgKjh313tXh078Fo764RSZIC8+U8xg6plw0nY5b9CNMxbMqpYH3376zefP7 P8EShj03M71yXaaDoo6OpvkjWH1Ju4KfBgXSYl7x9ftrz4bu+ptUsTFUzTrNjTovE2uQ 3uyATXbpPxzrho95bMeTMNUHXwvs9T4FqdZuFb2PRS4MCbERhkUx4R6utr34BpojKJbj hB6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="W/Tqw/dM"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c4-20020a170902d48400b001a66ff9542fsi3173766plg.616.2023.04.19.01.35.50; Wed, 19 Apr 2023 01:36:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="W/Tqw/dM"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232752AbjDSIeY (ORCPT + 99 others); Wed, 19 Apr 2023 04:34:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232692AbjDSIeJ (ORCPT ); Wed, 19 Apr 2023 04:34:09 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B2A01026E for ; Wed, 19 Apr 2023 01:33:54 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id o29-20020a05600c511d00b003f1739de43cso1007579wms.4 for ; Wed, 19 Apr 2023 01:33:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681893232; x=1684485232; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZFr0nNH7gKvfGd1xmrDdwsbO4A4hFnitswKb+PdA3E8=; b=W/Tqw/dMvtEe3FajEF9yCwGnfzmUZEjH+Tif9EgeaHJIdCUZf++mkSpx6eNr2zFb3B ev+9mSAGmiJOJ/xVRku+fLPsaOHjzLH2vkIUvhFYMXg7qd0Fk1N8vHRCL4CXq+60iHAG KpfoO799aCEpb1snZiiflY8lj4Yo2MXdArjEAeSUWr98PgdJ6U8mRomWqj566wQR1ZhZ LhHNRCim/aJ0ubva7AbwrKjtojJ2zcS0hQABDMbqunXxyXfaEQcEd12Y4zJsuyqNN9B3 iUAWLfYe3gGZ+lxE+JU/R7HFQWChRETiFZ0meFXZBsdJZdALiwBMGzcLOM7cIEOkwhvT QgQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681893232; x=1684485232; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZFr0nNH7gKvfGd1xmrDdwsbO4A4hFnitswKb+PdA3E8=; b=HSuBe23xdfCfhDr53Bt/0ureB943I6BeXHy+U3vLG0umkEa8TnT9OVRb3kb1Qphxli winQ5opO8Fqm6qKblIGh0FJepefVxvHwLvgKpgBUcaO3Xj5KaCg8NYzdhDw98/UA4YJZ FXxVriGhI77wzUojHmc/F/nR+8Ychws3LiPy6C0i26WXEMrdH2D/Vz0ybSX/Psmf97h1 IvjZwGQl6J1yd2CZRTYkJQZhI2hCzdqy6XSotQ10GhvBHu9TPTYQzMl9U9l6MkbcMn3T IYDMWus10G3pxu6bfvmnOP452YOSj5tnNJI1r1L+w3Bf7q4TYQDzceCUsgDIi6KzgYMO xLrg== X-Gm-Message-State: AAQBX9dksAnXTiaBBMOC9si23fZ0bDeyNjE3/6yv5dzpD9iyBF8STJLR 12qB36H87VlNTT5GQO3KdM+Y7Q== X-Received: by 2002:a1c:cc05:0:b0:3ef:d8c6:4bc0 with SMTP id h5-20020a1ccc05000000b003efd8c64bc0mr14793730wmb.40.1681893232730; Wed, 19 Apr 2023 01:33:52 -0700 (PDT) Received: from mai.box.freepro.com ([2a05:6e02:1041:c10:a794:9fb2:29fb:606d]) by smtp.gmail.com with ESMTPSA id s5-20020a1cf205000000b003ed1ff06faasm1442033wmc.19.2023.04.19.01.33.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 01:33:52 -0700 (PDT) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rafael@kernel.org Cc: rui.zhang@intel.com, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Len Brown , linux-acpi@vger.kernel.org (open list:ACPI THERMAL DRIVER) Subject: [PATCH v4 5/6] thermal/drivers/acpi: Move to dedicated function sysfs extra attr creation Date: Wed, 19 Apr 2023 10:33:42 +0200 Message-Id: <20230419083343.505780-6-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230419083343.505780-1-daniel.lezcano@linaro.org> References: <20230419083343.505780-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The ACPI thermal driver creates extra sysfs attributes in its own directory pointing to the thermal zone it is related to and add a pointer to the sysfs ACPI thermal device from the thermal zone sysfs entry. This is very specific to this ACPI thermal driver, let's encapsulate the related creation/deletion code to group it inside a function we can identify later for removal if needed. Signed-off-by: Daniel Lezcano --- drivers/acpi/thermal.c | 52 ++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 5763db4528b8..9a90b1a117cd 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -787,9 +787,34 @@ static struct thermal_zone_device_ops acpi_thermal_zone_ops = { .critical = acpi_thermal_zone_device_critical, }; +static int acpi_thermal_zone_sysfs_add(struct acpi_thermal *tz) +{ + struct device *tzdev = thermal_zone_device(tz->thermal_zone); + int ret; + + ret = sysfs_create_link(&tz->device->dev.kobj, + &tzdev->kobj, "thermal_zone"); + if (ret) + return ret; + + ret = sysfs_create_link(&tzdev->kobj, + &tz->device->dev.kobj, "device"); + if (ret) + sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone"); + + return ret; +} + +static void acpi_thermal_zone_sysfs_remove(struct acpi_thermal *tz) +{ + struct device *tzdev = thermal_zone_device(tz->thermal_zone); + + sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone"); + sysfs_remove_link(&tzdev->kobj, "device"); +} + static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) { - struct device *tzdev; int trips = 0; int result; acpi_status status; @@ -821,23 +846,15 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) if (IS_ERR(tz->thermal_zone)) return -ENODEV; - tzdev = thermal_zone_device(tz->thermal_zone); - - result = sysfs_create_link(&tz->device->dev.kobj, - &tzdev->kobj, "thermal_zone"); + result = acpi_thermal_zone_sysfs_add(tz); if (result) goto unregister_tzd; - - result = sysfs_create_link(&tzdev->kobj, - &tz->device->dev.kobj, "device"); - if (result) - goto remove_tz_link; - + status = acpi_bus_attach_private_data(tz->device->handle, tz->thermal_zone); if (ACPI_FAILURE(status)) { result = -ENODEV; - goto remove_dev_link; + goto remove_links; } result = thermal_zone_device_enable(tz->thermal_zone); @@ -851,10 +868,8 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) acpi_bus_detach: acpi_bus_detach_private_data(tz->device->handle); -remove_dev_link: - sysfs_remove_link(&tzdev->kobj, "device"); -remove_tz_link: - sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone"); +remove_links: + acpi_thermal_zone_sysfs_remove(tz); unregister_tzd: thermal_zone_device_unregister(tz->thermal_zone); @@ -863,10 +878,7 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal *tz) { - struct device *tzdev = thermal_zone_device(tz->thermal_zone); - - sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone"); - sysfs_remove_link(&tzdev->kobj, "device"); + acpi_thermal_zone_sysfs_remove(tz); thermal_zone_device_unregister(tz->thermal_zone); tz->thermal_zone = NULL; acpi_bus_detach_private_data(tz->device->handle); -- 2.34.1