Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1186534rwb; Wed, 28 Sep 2022 14:38:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7eqbfJPvNRLvGJh4Enepn7lYI95JBIFzfUm+yjYf6otNNfBykvqtOi7QSvGmeZW7cs7yWe X-Received: by 2002:a17:902:cec1:b0:178:cdb:8458 with SMTP id d1-20020a170902cec100b001780cdb8458mr2922plg.161.1664401093365; Wed, 28 Sep 2022 14:38:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664401093; cv=none; d=google.com; s=arc-20160816; b=WxipX3mq07GAGn36RKaXPENdO8GTHntWLz1tQm4h0lTDwLQWO4mN2cvXGA1NA+o/nA IuwhLUahHz9j+RK9qwz0wIVmT+hhSESnOeMvzPELZFpPUGI9OeSPXCHmOHclICGs7Hgn O+7TcmIG7jzzCZ1JCCfpirPOW0/AHMZik/WASvAR5CSDX/y5NTZJQgvG+K6FIuPni0Da KA1sEvWX26r7kkjbSZkff9x1bH886O17uO9Wr6elNB8vrJiZoJkvyMeMcOcgZqtZsvq6 MPoiLYMI4RnxbEzihfPF0a4NnyDukpJe+w8gkXFadgROYdBDDS8p2e35x7CkvbIPCqas GH4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=p6VnoEFyMhNWJOt/Kz0x4QfEzvgk8GdGw5+b/MWAJNI=; b=jUDWBoQ6tvHUSsmFFbb+vm8gM7yxoTfdkBkVTrb7F2lH/cunwRAoPvOKYyAEnB550F A4HhIxojA9H2bTgHZikbAiBucIIjjXny57FXSh3xDzzdw774sRXEIQ4SRhsBHDbJAv4O Ed5c3G4rLbupdj6VXxfF5qZG55XVJwjknFJ+e1Lk9g4QD+5KqjGHq0W/iSXzyWSnExcy P29hqGHjn/JNtUVqn+9/+cOJwW7CTv8h+4vjj1oU7fLNy2UXWxf0WJb9XuoRoLkDDlHB f5T8+ppynf1oWtQ4wRyfIhE0JEM8c98XqiC0aiCzXfVT59NJFdIEp8HXkUxy+rEeGiT6 mnuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.net header.s=badeba3b8450 header.b=JHSkelQ4; 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=fail (p=NONE sp=NONE dis=NONE) header.from=gmx.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e10-20020a170903240a00b0017a0f71990dsi720416plo.141.2022.09.28.14.38.01; Wed, 28 Sep 2022 14:38:13 -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=@gmx.net header.s=badeba3b8450 header.b=JHSkelQ4; 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=fail (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233186AbiI1U5s (ORCPT + 99 others); Wed, 28 Sep 2022 16:57:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232380AbiI1U5n (ORCPT ); Wed, 28 Sep 2022 16:57:43 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7E0E5F20A; Wed, 28 Sep 2022 13:57:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1664398638; bh=CFph/fnZBnA8ilu2HLIUiJ/GqqCUZHdkKGi61xNZqsI=; h=X-UI-Sender-Class:Subject:To:Cc:References:From:Date:In-Reply-To; b=JHSkelQ4tL/Rr6l0HG4iLUUB93THsxkY13mrjURA25L0ZjRisUgEwwzEUEpXctHCH 41ZhChan10bC6rT7kmaKKMyO0KKdJvYZLOWKVcut8Z3ZmYMJ5TDNk9iWrrroRG3oai Ex382T0K3yR0t+1JfM8cvNkgty1VR9FbQuwk2sU4= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [141.30.226.129] ([141.30.226.129]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1N8GMk-1pH7kL3fcm-014BjN; Wed, 28 Sep 2022 22:57:18 +0200 Subject: Re: [PATCH v2 2/2] platform/x86: dell: Add new dell-wmi-ddv driver To: Andy Shevchenko Cc: hdegoede@redhat.com, markgross@kernel.org, rafael@kernel.org, lenb@kernel.org, hmh@hmh.eng.br, matan@svgalib.org, corentin.chary@gmail.com, jeremy@system76.com, productdev@system76.com, mario.limonciello@amd.com, pobrn@protonmail.com, coproscefalo@gmail.com, platform-driver-x86@vger.kernel.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org References: <20220927204521.601887-1-W_Armin@gmx.de> <20220927204521.601887-3-W_Armin@gmx.de> From: Armin Wolf Message-ID: <34774c9d-1210-0015-f78e-97fdf717480c@gmx.de> Date: Wed, 28 Sep 2022 22:57:16 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Provags-ID: V03:K1:5EN9kv8yQUVWjzFY1V9LZveD8YCFxumwS5eYHwGrVDGhA31aeoJ XhczMGYhrq+opU8rtD5tcLCaih461gTvCsf4ZR+3e5hCuFDAmAXAbac/ojX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wljQAKp5NAOH2K6hb9LBzQ8AT5kxqlquGtQ9ccdNzuYHM2l7xtR0GN fj2AIoRUBZVlqjUIwCcEpmpHxJbZ1YwUsafbe0M1Q6WuANDkMjpY2NydUNRzb4uJSmOo8Am/s uHUMaV5KYBZhQMSHB0DV/Ng2/b5tr0jG+Kszx0b86JFEyy+EOb5a46Fxq8iFDU9eSON3jmBYI KEHriN9Xc29+chMM3/qRYrEWwnLjskFyRvc1u/ArjNMP8Va2HdDPlcGH0+DwxNZybbn0evPcV ydvlgt8RGyh+L53nj36auyaXev X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FROM,NICE_REPLY_A,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS 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 Am 28.09.22 um 12:47 schrieb Andy Shevchenko: > On Tue, Sep 27, 2022 at 10:45:21PM +0200, Armin Wolf wrote: >> The dell-wmi-ddv driver adds support for reading >> the current temperature and ePPID of ACPI batteries >> on supported Dell machines. >> >> Since the WMI interface used by this driver does not >> do any input validation and thus cannot be used for probing, >> the driver depends on the ACPI battery extension machanism >> to discover batteries. >> >> The driver also supports a debugfs interface for retrieving >> buffers containing fan and thermal sensor information. >> Since the meaing of the content of those buffers is currently >> unknown, the interface is meant for reverse-engineering and >> will likely be replaced with an hwmon interface once the >> meaning has been understood. >> >> The driver was tested on a Dell Inspiron 3505. > ... > >> +config DELL_WMI_DDV >> + tristate "Dell WMI sensors Support" >> + default m > Why? (Imagine I have Dell, but old machine) > > (And yes, I see that other Kconfig options are using it, but we shall avoid > cargo cult and each default choice like this has to be explained at least.) > > ... > >> + * dell-wmi-ddv.c -- Linux driver for WMI sensor information on Dell notebooks. > Please, remove file name from the file. This will be an additional burden in > the future in case it will be renamed. > > ... > >> +#include > Is it required to be the first? Otherwise it seems ACPI specific to me and the > general rule is to put inclusions from generic towards custom. I.o.w. can you > move it after linux/wmi.h with a blank line in between? > >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include > ... > >> +struct dell_wmi_ddv_data { >> + struct acpi_battery_hook hook; >> + struct device_attribute temp_attr, eppid_attr; > It's hard to read and easy to miss that the data type has two members here. > Please, put one member per one line. > >> + struct wmi_device *wdev; >> +}; > ... > >> + if (obj->type != type) { >> + kfree(obj); >> + return -EIO; > EINVAL? In my opinion, EINVAL should be returned if the parameters are invalid. In this case however, the error comes from the wmi device returning invalid data, which would be represented better with EIO. >> + } > ... > >> + kfree(obj); > I'm wondering what is the best to use in the drivers: > 1) kfree() > 2) acpi_os_free() > 3) ACPI_FREE() > > ? > > ... > >> +static int dell_wmi_ddv_battery_index(struct acpi_device *acpi_dev, u32 *index) >> +{ >> + const char *uid_str = acpi_device_uid(acpi_dev); >> + >> + if (!uid_str) >> + return -ENODEV; > It will be better for maintaining to have > > const char *uid_str...; > > uid_str = ... > if (!uid_str) > ... > >> + return kstrtou32(uid_str, 10, index); >> +} > ... > >> + /* Return 0 instead of error to avoid being unloaded */ >> + ret = dell_wmi_ddv_battery_index(to_acpi_device(battery->dev.parent), &index); >> + if (ret < 0) >> + return 0; > How index is used? > > ... > >> + ret = device_create_file(&battery->dev, &data->temp_attr); >> + if (ret < 0) >> + return ret; >> + >> + ret = device_create_file(&battery->dev, &data->eppid_attr); >> + if (ret < 0) { >> + device_remove_file(&battery->dev, &data->temp_attr); >> + >> + return ret; >> + } > Why dev_groups member can't be utilized? > > ... > >> +static void dell_wmi_ddv_debugfs_init(struct wmi_device *wdev) > Strictly speaking this should return int (see below). > >> +{ >> + struct dentry *entry; >> + char name[64]; >> + >> + scnprintf(name, ARRAY_SIZE(name), "%s-%s", DRIVER_NAME, dev_name(&wdev->dev)); >> + entry = debugfs_create_dir(name, NULL); >> + >> + debugfs_create_devm_seqfile(&wdev->dev, "fan_sensor_information", entry, >> + dell_wmi_ddv_fan_read); >> + debugfs_create_devm_seqfile(&wdev->dev, "thermal_sensor_information", entry, >> + dell_wmi_ddv_temp_read); >> + >> + devm_add_action_or_reset(&wdev->dev, dell_wmi_ddv_debugfs_remove, entry); > return devm... > > This is not related to debugfs and there is no rule to avoid checking error > codes from devm_add_action_or_reset(). > According to the documentation of debugfs_create_dir(), drivers should work fine if debugfs initialization fails. Thus the the return value of dell_wmi_ddv_debugfs_init() would be ignored when called, which means that returning an error would serve no purpose. Additionally, devm_add_action_or_reset() automatically executes the cleanup function if devres registration fails, so we do not have to care about that. >> +} > ... > >> +static struct wmi_driver dell_wmi_ddv_driver = { >> + .driver = { >> + .name = DRIVER_NAME, > I would use explicit literal since this is a (semi-) ABI, and having it as > a define feels not fully right. The driver name is used in two places (init and debugfs), so having a define for it avoids problems in case someone forgets to change both. Armin Wolf >> + }, >> + .id_table = dell_wmi_ddv_id_table, >> + .probe = dell_wmi_ddv_probe, >> +};