From patchwork Fri Jun 1 11:07:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bastian Germann X-Patchwork-Id: 10443007 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 589F8601D3 for ; Fri, 1 Jun 2018 11:08:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F3E4E28842 for ; Fri, 1 Jun 2018 11:08:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E8B2A28870; Fri, 1 Jun 2018 11:08:16 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=unavailable 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 7C0F928842 for ; Fri, 1 Jun 2018 11:08:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750790AbeFALIQ (ORCPT ); Fri, 1 Jun 2018 07:08:16 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:39994 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750852AbeFALHu (ORCPT ); Fri, 1 Jun 2018 07:07:50 -0400 Received: by mail-wr0-f194.google.com with SMTP id l41-v6so35992321wre.7 for ; Fri, 01 Jun 2018 04:07:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fishpost-de.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=gS41vg4LILCdw2zNylQ3I1juMJ4Jq9n8MPnAJ8e4G1k=; b=iAgjVgFsvPMWPK6pSkAwiMrV4Z5aBNmL9yjBWZ4scK8PT6utosPPQZPB0mHkNfgg8/ 8UrpVWe/gaR+Vt0jGG3Yug35JS+WmJrUo1xw6jGaItprF81xFce0dNLgLCKgdQMUyvx4 adObBaNrmlzxd4P/3Kl/K1XeYsTeetLEO6BKl4PsUyYM9rKsiEzxxPDeA20CMy7wA8LW WvMVQuQ6Q6nPbcKmkTPuvxJ/lNbTxxm42QBPiIPi9eL5dO5gSDuWdU60lafZE2NYGzPX 9spKbp7ZSQ4nsHzhoxFIipy9x2+TLELIcbfvPeawPkmvQzQxTynMzU85Rtx8IFK5fyc/ +D9w== 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; bh=gS41vg4LILCdw2zNylQ3I1juMJ4Jq9n8MPnAJ8e4G1k=; b=Szq3rKZ1TOi6WXKyIflktAZiluaCCyKDyUzSDNGs5WwMdDgik3YEXj3obAvwPsH/hm 38M0XL9XlkHJIRaVao6WjTH7Vocz02g7fr7KzMK7J3C+XIm4k2C3R85O05KzyTqce7H+ wVftnh9fzWxbCsVRMQefmjyYpPuTER9Hcbx1+HiVa4K8curQ/aIuS1Fk8xey+Jdk0l0T QDnSCBF5JRKoCVpBO1H6Qw4FcoNscKO3osVbO6yeF+ZzZSxMVXLmh92g50sHzWw1+OPy 7K07/xXpDAn4rDGsYl5KLvMH8Twv0GXow78EkM9rpHBAvzHQAdLw5JL6Y+9zRUtTVgS3 WG3g== X-Gm-Message-State: ALKqPwe6STKgI6JFJ7ChjThLrduu5a7xagUH3Ra2Ka1rDSSJIzptYSdk EXD8mtz0anA8KWWVGTYiyHkoxw== X-Google-Smtp-Source: ADUXVKI+e0QqonmxKucnEJxyW6JryuOQXZGDhotQ8iYPRWsf09IsqxWB48AtWf9LkkAhMrEFfDvcTw== X-Received: by 2002:adf:f045:: with SMTP id t5-v6mr7878064wro.260.1527851268937; Fri, 01 Jun 2018 04:07:48 -0700 (PDT) Received: from pc-bage.fritz.box (x590dfe35.dyn.telefonica.de. [89.13.254.53]) by smtp.gmail.com with ESMTPSA id y3-v6sm6119788wro.21.2018.06.01.04.07.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Jun 2018 04:07:48 -0700 (PDT) From: Bastian Germann To: Andy Shevchenko Cc: Bastian Germann , Luca Tettamanti , Jean Delvare , Guenter Roeck , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] hwmon: (asus_atk0110) Make use of device managed memory Date: Fri, 1 Jun 2018 13:07:18 +0200 Message-Id: <20180601110719.3281-2-bastiangermann@fishpost.de> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180601110719.3281-1-bastiangermann@fishpost.de> References: <20180601110719.3281-1-bastiangermann@fishpost.de> Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use devm_* variants of kstrdup and kzalloc. Get rid of kfree cleanups. Signed-off-by: Bastian Germann --- drivers/hwmon/asus_atk0110.c | 44 +++++++----------------------------- 1 file changed, 8 insertions(+), 36 deletions(-) diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c index 33748cc07acc..91af065d0e4d 100644 --- a/drivers/hwmon/asus_atk0110.c +++ b/drivers/hwmon/asus_atk0110.c @@ -190,7 +190,6 @@ static int atk_add(struct acpi_device *device); static int atk_remove(struct acpi_device *device); static void atk_print_sensor(struct atk_data *data, union acpi_object *obj); static int atk_read_value(struct atk_sensor_data *sensor, u64 *value); -static void atk_free_sensors(struct atk_data *data); static struct acpi_driver atk_driver = { .name = ATK_HID, @@ -906,15 +905,13 @@ static int atk_add_sensor(struct atk_data *data, union acpi_object *obj) limit1 = atk_get_pack_member(data, obj, HWMON_PACK_LIMIT1); limit2 = atk_get_pack_member(data, obj, HWMON_PACK_LIMIT2); - sensor = kzalloc(sizeof(*sensor), GFP_KERNEL); + sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL); if (!sensor) return -ENOMEM; - sensor->acpi_name = kstrdup(name->string.pointer, GFP_KERNEL); - if (!sensor->acpi_name) { - err = -ENOMEM; - goto out; - } + sensor->acpi_name = devm_kstrdup(dev, name->string.pointer, GFP_KERNEL); + if (!sensor->acpi_name) + return -ENOMEM; INIT_LIST_HEAD(&sensor->list); sensor->type = type; @@ -955,9 +952,6 @@ static int atk_add_sensor(struct atk_data *data, union acpi_object *obj) (*num)++; return 1; -out: - kfree(sensor); - return err; } static int atk_enumerate_old_hwmon(struct atk_data *data) @@ -998,8 +992,7 @@ static int atk_enumerate_old_hwmon(struct atk_data *data) dev_warn(dev, METHOD_OLD_ENUM_TMP ": ACPI exception: %s\n", acpi_format_exception(status)); - ret = -ENODEV; - goto cleanup; + return -ENODEV; } pack = buf.pointer; @@ -1020,8 +1013,7 @@ static int atk_enumerate_old_hwmon(struct atk_data *data) dev_warn(dev, METHOD_OLD_ENUM_FAN ": ACPI exception: %s\n", acpi_format_exception(status)); - ret = -ENODEV; - goto cleanup; + return -ENODEV; } pack = buf.pointer; @@ -1035,9 +1027,6 @@ static int atk_enumerate_old_hwmon(struct atk_data *data) ACPI_FREE(buf.pointer); return count; -cleanup: - atk_free_sensors(data); - return ret; } static int atk_ec_present(struct atk_data *data) @@ -1213,17 +1202,6 @@ static int atk_init_attribute_groups(struct atk_data *data) return 0; } -static void atk_free_sensors(struct atk_data *data) -{ - struct list_head *head = &data->sensor_list; - struct atk_sensor_data *s, *tmp; - - list_for_each_entry_safe(s, tmp, head, list) { - kfree(s->acpi_name); - kfree(s); - } -} - static int atk_register_hwmon(struct atk_data *data) { struct device *dev = &data->acpi_dev->dev; @@ -1323,7 +1301,7 @@ static int atk_add(struct acpi_device *device) dev_dbg(&device->dev, "adding...\n"); - data = kzalloc(sizeof(*data), GFP_KERNEL); + data = devm_kzalloc(&device->dev, sizeof(*data), GFP_KERNEL); if (!data) return -ENOMEM; @@ -1375,18 +1353,15 @@ static int atk_add(struct acpi_device *device) goto out; err = atk_register_hwmon(data); if (err) - goto cleanup; + goto out; atk_debugfs_init(data); device->driver_data = data; return 0; -cleanup: - atk_free_sensors(data); out: if (data->disable_ec) atk_ec_ctl(data, 0); - kfree(data); return err; } @@ -1399,7 +1374,6 @@ static int atk_remove(struct acpi_device *device) atk_debugfs_cleanup(data); - atk_free_sensors(data); hwmon_device_unregister(data->hwmon_dev); if (data->disable_ec) { @@ -1407,8 +1381,6 @@ static int atk_remove(struct acpi_device *device) dev_err(&device->dev, "Failed to disable EC\n"); } - kfree(data); - return 0; }