From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.9 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A425FC282CE for ; Wed, 24 Apr 2019 06:49:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6572220656 for ; Wed, 24 Apr 2019 06:49:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dIXj8bx4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726844AbfDXGta (ORCPT ); Wed, 24 Apr 2019 02:49:30 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:41835 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730005AbfDXGtZ (ORCPT ); Wed, 24 Apr 2019 02:49:25 -0400 Received: by mail-pl1-f194.google.com with SMTP id d9so2854366pls.8; Tue, 23 Apr 2019 23:49:24 -0700 (PDT) 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=oaVflYKWbfFgk46fxum4ETLGOipk0J+WaOOtituvfiI=; b=dIXj8bx4l0VYf5f/9sUNiWDAokUZnaxcxPSRJC6sYCUKNC/JD/yRvhv72F9I3LV0Rv Yky57CKKkj/7VeL7SagzX9Gpwtmpm+BDwpWkhMa5B7Ql0eX+bROJ38/UtZ6N95e7m58b FMyYy0vEUmt7P9hQCH63xSWkY9oV6ew6OG8TYTasNDOuGV7dAFx9AGoJ1ZvnjWuptPnj 9Dba2We0nG9Kvuf0dhZilI5iWqQJPPCXXtMZu07v5i2CZorcGrtfyJu1roFQTlrXLT8h 7lMSBLU5jZ1/vBTYyAL9EmJUm2F2cErdwhy52gfiGCDMsF1aNBEG+JE4p7xMwRD7b8T/ qCQQ== 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=oaVflYKWbfFgk46fxum4ETLGOipk0J+WaOOtituvfiI=; b=nnQ7Fy/Kc3TGPcz24C4ffOZSh+aNQXmZK9/4zUfRqeWUhWqRgNPug5eiRfa3axURfN YzSdKBL5uUUwxglvoqRnotCiuFKvC5eevb15sOnYOQPpv6Visuk1VDyipwRuZI0LktUZ 4n6xixKGar4QLmcmQNoIMTp4XLmOMDBaR3j/eYk8W1foJGvr0rtEqZo2JOz/V4gWHkHc ziJ7CoN/CD41hxNN0ni4rqE2E6JR2l8RnOEPj22eNcXjsorxbXESSCWXuDL68JHTI+qd kazIgdF8rBTGcZ5KHqvcOWbvz+MJeyoDUTNgaa0iDzbqPWzbHUSRjbuZ5B/uNxXnriQn NT+w== X-Gm-Message-State: APjAAAVjr+ZwUO3MrG7V2mCFp3CPdtgu2i9DAuO4quvG9P6s3qcAwIvd 7vWj63xr2zlQ1Cknx2G1rv5xP8OYjU0= X-Google-Smtp-Source: APXvYqz1CPZ4TJH3E3L33/8Kt/u53PMFxlhhRwwnE2AcH5LOP5OgWQdbiajOov3NQlD+3QAw5kKAzw== X-Received: by 2002:a17:902:a01:: with SMTP id 1mr30581797plo.36.1556088563892; Tue, 23 Apr 2019 23:49:23 -0700 (PDT) Received: from squirtle.lan (c-24-22-235-96.hsd1.wa.comcast.net. [24.22.235.96]) by smtp.gmail.com with ESMTPSA id e13sm26332457pgb.37.2019.04.23.23.49.22 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Apr 2019 23:49:22 -0700 (PDT) From: Andrey Smirnov To: linux-pm@vger.kernel.org Cc: Andrey Smirnov , Daniel Lezcano , Lucas Stach , Chris Healy , Eduardo Valentin , Angus Ainslie , linux-imx@nxp.com, linux-kernel@vger.kernel.org Subject: [PATCH v5 11/12] thermal_hwmon: Add devres wrapper for thermal_add_hwmon_sysfs() Date: Tue, 23 Apr 2019 23:48:29 -0700 Message-Id: <20190424064830.18179-12-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190424064830.18179-1-andrew.smirnov@gmail.com> References: <20190424064830.18179-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 40c69a533b24..4e79524182e1 100644 --- a/drivers/thermal/thermal_hwmon.c +++ b/drivers/thermal/thermal_hwmon.c @@ -244,3 +244,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.20.1