From patchwork Sat Apr 13 08:27:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 10899371 X-Patchwork-Delegate: eduardo.valentin@ti.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BDFFD1708 for ; Sat, 13 Apr 2019 08:28:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A7E0328E85 for ; Sat, 13 Apr 2019 08:28:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9AA6128E87; Sat, 13 Apr 2019 08:28:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E586D28E85 for ; Sat, 13 Apr 2019 08:28:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727440AbfDMI2V (ORCPT ); Sat, 13 Apr 2019 04:28:21 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:41300 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727408AbfDMI2U (ORCPT ); Sat, 13 Apr 2019 04:28:20 -0400 Received: by mail-pg1-f194.google.com with SMTP id f6so6280044pgs.8; Sat, 13 Apr 2019 01:28:19 -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=ioF0cKR12rI6esgkEu/uGcNVeKMcEFlcMNhoifYw7yg=; b=bFSFmZSJk3ZIyC0DhLCpFf0UxxbQW6TIF/zLUDNiou0sDoos0AtMdtvOeXVFjCVo+j mrVx68aNc9vA7oVkZkI4cT8U6ibg4KJ19DM1kgEFRrqHpBujJqNZ1M6aTxpejLpiL7od iHhAP+voymDBvHIGipdR8IR7bKULH4ixzrC93i2trDyFTaxz1moAbUVpSyJJl24saOQD GhzyZbRauTF2Ganlx3wO0Fh6ZyzQ9wUwCiDz0h9UGPERqT3h2+IjqSm+oY54FwCwK8Gd NfkQSuPIMDFRvOWYZaOMAI5oIDyShx8dCXF+JgQl1ulzWOTaAszE4HgKqY3WJPjhVf4h 7vmg== 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=ioF0cKR12rI6esgkEu/uGcNVeKMcEFlcMNhoifYw7yg=; b=scUrGJIiBaaRhkvUgmw3rdlWXiMbtqj+5VNIP2S2H/G0z5FaomM6rzWQoKFQya/sB3 ftWq2VL2bjcvrvTaQRkviAlG7bgVIk/IBj/M/u6w30V54h131Mg27CejkdxWzQCYep5b 6gaKt64DFsMnyVeoJtOcGlhQpTGIYPgUmdJKLvolGkPPl5cqT+3bqjlOinE73pILQTIg 7dvpMYAPZtdU4jpeKAJTA4yoiDPrWbRX/nGbuC/cQpYG+G4/o334Q7Qv2IQkJNmAH+Ow 8LxLOcLzqIHLwDOv79iL0KCkJtPdNY+TKPXH6zYjAitN/rI+86RzNrK9umyTaZS/440z MBbw== X-Gm-Message-State: APjAAAXxFCAyh8cUxJIvAWj0VCVAof8GjfzcMkLoqpfx0yg6YJf2YTC7 WYh1e5sXtjDiNUS/pFaINHlOjLHw X-Google-Smtp-Source: APXvYqzUG3V6eE9t3J3TivTCeehch77k03rKnqUHnXlEXeeAl9+huIRiEGknUEHlK5GtMC37IQ/HLw== X-Received: by 2002:a63:2983:: with SMTP id p125mr59194840pgp.262.1555144099049; Sat, 13 Apr 2019 01:28:19 -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 z20sm58261328pgf.70.2019.04.13.01.28.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 13 Apr 2019 01:28:18 -0700 (PDT) From: Andrey Smirnov To: linux-pm@vger.kernel.org Cc: Andrey Smirnov , Chris Healy , Lucas Stach , Eduardo Valentin , Daniel Lezcano , Angus Ainslie , linux-imx@nxp.com, linux-kernel@vger.kernel.org Subject: [PATCH v4 11/12] thermal_hwmon: Add devres wrapper for thermal_add_hwmon_sysfs() Date: Sat, 13 Apr 2019 01:27:47 -0700 Message-Id: <20190413082748.29990-12-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190413082748.29990-1-andrew.smirnov@gmail.com> References: <20190413082748.29990-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add devres wrapper for thermal_add_hwmon_sysfs() to simplify driver code. Signed-off-by: Andrey Smirnov 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 Reviewed-by: Daniel Lezcano --- 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) {