Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5612487ybl; Tue, 10 Dec 2019 08:43:36 -0800 (PST) X-Google-Smtp-Source: APXvYqyT9HyFbMg3T59bLro1P6P5fBLr5eBUs34Pu6rCnrn6FoJNlFiXL/bHz+/cI/7oxBzQHVbN X-Received: by 2002:a05:6830:18ce:: with SMTP id v14mr24494128ote.254.1575996216205; Tue, 10 Dec 2019 08:43:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575996216; cv=none; d=google.com; s=arc-20160816; b=npQDUMWcrt/NIf0lstaKK1e0fWVwvTV3gAzIrBbq+Ka4/KWEPPD817GdiAtcTgIw7p FbcSJoQvLEWw/gi3ddxpY9Gofmn9irFgJL4cwki7ZPzavnOX/0krX51yRPmeMvbe14uT qZtfmBw5UA3wzF0RI4QWBKJUP9+BIk2ZGpQYWMhKPqXZR9xYAqk1rVd4kX/aDUjBd6h9 57kvy3zvvEcjGWg1U5k/MbfqYm8/Y8gkaCVy0gOVGjoJJx5MOOSO6Zu07SW4/eXl9wKF ykhYPpNPi3VCSlG9PSYftFwgTe8/uZBVj1NLy6s45XTSsQ7xwzdMb6xnJ+zo5JH6p7oK xtsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=e0lwGN+LUXDKi5KuFbcc2RGuv/5GribWzP248c589m4=; b=I/kOiqG5q8SRbVzUui9LqEnN9PZXArGTb0362Bgns8wNUxirttnXiD76EMAq4H8iGu Ytr1gwHthakL7U3UDyOgfZ7D3R0uL1yJj6w9o7FWhVTyVNu3A57QiR0BnxKUDAce54iO 66qWjUqFZm1M1IeA4Ue/4KzU9mVAnhFF9cAVs9ekSVTlcXmBWDyXbJ4In8Q+hVF1edYs gHwUnOIYpDMAH1osiyurLoewExRfT8ED6QGVBqyoDgUbB4xv2WkefoORA3nosNuYJWFt ON6a6uGgMy6ID5hVotUwXUTToGdJ7vE2BKRiKXIv1CHxZXDwrQvq0i9GXYiF6WPxavH9 aziA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VZSJzE9v; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u18si2193495oia.80.2019.12.10.08.43.23; Tue, 10 Dec 2019 08:43:36 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VZSJzE9v; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727879AbfLJQmd (ORCPT + 99 others); Tue, 10 Dec 2019 11:42:33 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:36338 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727846AbfLJQm0 (ORCPT ); Tue, 10 Dec 2019 11:42:26 -0500 Received: by mail-pl1-f196.google.com with SMTP id d15so98332pll.3; Tue, 10 Dec 2019 08:42:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=e0lwGN+LUXDKi5KuFbcc2RGuv/5GribWzP248c589m4=; b=VZSJzE9vD8fY8ler14aQN+zwXNhOpwWdw7wwDyGHH0PP48U06fRdhDtZNJBoz4rLy0 IvzGsmB7KAv+EM7NiV35TniZ9SYrvOqeHa+aKAlhoRlHo/G+LpVpdaBL4wjUCG9Lb4vl Yl1M/wh+HU1bmsKKc/dfTkFioiTBQiG0uVVGF6v4WWa/92ymS4RdX/YLqAKm1UDdSx4K 9ShPmgYrYT9mWayqRlt/WF4Ao5PcMzfH7N8qWCmuokoBmqggQlyDdvbK5vbeHRpM2JD+ YHl9gFTJK/YoMEbZijuuGE7qOeNehsm5NE62gRE75Dl4gxE+ZM7j0yoMUoeaGGJzq/yb w1Vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=e0lwGN+LUXDKi5KuFbcc2RGuv/5GribWzP248c589m4=; b=H4VXUAuBR46ppmVHaBm0hI/U3MS2gUSmiI441ZyqGR+l5+NMteyPOMKgmWWGqiXojB /vGAukRF7v69oqJO38TX4z+dCudK0TdMz14+YN2lqDOL4q+3oYlTeHKDtj6I5aTWRM2q nMEV4JKdHha/vx0BiM3F/GPucXs4kkBTgKB81PvAhPZpJzNcPEoEoJFmFZBEAGn5Vt+p a7tLNk6Yr3Uuwqu6qsUw8k9W2vgH4lE4I890BgMZt5dI2/xdP3AmK+uysKaJAh6rbgsI lIb6DDo/elN+ZWS9NsG8yx3oe9yC5WSnskK+Gzyo3b22Hd0vA5+HFwPm91UkIGwrwPdc Ra4g== X-Gm-Message-State: APjAAAX7pFj48LslBSaVTg8ougTEYuqntIMXiZW3wkwmkklmcHpWyLIr YP1tp7xtPEeYQ1qWt0PhRAo= X-Received: by 2002:a17:90a:d78f:: with SMTP id z15mr6481689pju.36.1575996146180; Tue, 10 Dec 2019 08:42:26 -0800 (PST) Received: from localhost.localdomain (c-67-165-113-11.hsd1.wa.comcast.net. [67.165.113.11]) by smtp.gmail.com with ESMTPSA id j38sm4034634pgj.27.2019.12.10.08.42.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 08:42:25 -0800 (PST) From: Andrey Smirnov To: Daniel Lezcano Cc: Andrey Smirnov , Lucas Stach , Chris Healy , Eduardo Valentin , Angus Ainslie , linux-imx@nxp.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 11/12] thermal_hwmon: Add devres wrapper for thermal_add_hwmon_sysfs() Date: Tue, 10 Dec 2019 08:41:52 -0800 Message-Id: <20191210164153.10463-12-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191210164153.10463-1-andrew.smirnov@gmail.com> References: <20191210164153.10463-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add devres wrapper for thermal_add_hwmon_sysfs() to simplify driver code. Signed-off-by: Andrey Smirnov Reviewed-by: Daniel Lezcano Tested-by: Lucas Stach Cc: Chris Healy Cc: Lucas Stach Cc: Eduardo Valentin Cc: Daniel Lezcano Cc: Angus Ainslie (Purism) Cc: linux-imx@nxp.com Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/thermal/thermal_hwmon.c | 28 ++++++++++++++++++++++++++++ drivers/thermal/thermal_hwmon.h | 7 +++++++ 2 files changed, 35 insertions(+) diff --git a/drivers/thermal/thermal_hwmon.c b/drivers/thermal/thermal_hwmon.c index dd5d8ee37928..c8d2620f2e42 100644 --- a/drivers/thermal/thermal_hwmon.c +++ b/drivers/thermal/thermal_hwmon.c @@ -248,3 +248,31 @@ void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz) kfree(hwmon); } EXPORT_SYMBOL_GPL(thermal_remove_hwmon_sysfs); + +static void devm_thermal_hwmon_release(struct device *dev, void *res) +{ + thermal_remove_hwmon_sysfs(*(struct thermal_zone_device **)res); +} + +int devm_thermal_add_hwmon_sysfs(struct thermal_zone_device *tz) +{ + struct thermal_zone_device **ptr; + int ret; + + ptr = devres_alloc(devm_thermal_hwmon_release, sizeof(*ptr), + GFP_KERNEL); + if (!ptr) + return -ENOMEM; + + ret = thermal_add_hwmon_sysfs(tz); + if (ret) { + devres_free(ptr); + return ret; + } + + *ptr = tz; + devres_add(&tz->device, ptr); + + return ret; +} +EXPORT_SYMBOL_GPL(devm_thermal_add_hwmon_sysfs); diff --git a/drivers/thermal/thermal_hwmon.h b/drivers/thermal/thermal_hwmon.h index a160b9d62dd0..1a9d65f6a6a8 100644 --- a/drivers/thermal/thermal_hwmon.h +++ b/drivers/thermal/thermal_hwmon.h @@ -17,6 +17,7 @@ #ifdef CONFIG_THERMAL_HWMON int thermal_add_hwmon_sysfs(struct thermal_zone_device *tz); +int devm_thermal_add_hwmon_sysfs(struct thermal_zone_device *tz); void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz); #else static inline int @@ -25,6 +26,12 @@ thermal_add_hwmon_sysfs(struct thermal_zone_device *tz) return 0; } +static inline int +devm_thermal_add_hwmon_sysfs(struct thermal_zone_device *tz) +{ + return 0; +} + static inline void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz) { -- 2.21.0