Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2385723lqt; Mon, 22 Apr 2024 09:15:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWUSms6//C+H9uuD9XEpYPIFvv1xwLpg346jNntEHExyQ/5o3Y/13eZSUBsrBsOr+lWHxMFskv0XSTnuEZiNuEaYoGGZvSkBw85Kaa9LA== X-Google-Smtp-Source: AGHT+IGpIJoAy+M6oxZv70friezPf87IweJBU7YeTsNdE1jkvBJ/udgf5y5XbnmhBmmMkcqa836Z X-Received: by 2002:a05:6a00:1822:b0:6ec:f282:f4ea with SMTP id y34-20020a056a00182200b006ecf282f4eamr11326274pfa.34.1713802540249; Mon, 22 Apr 2024 09:15:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713802540; cv=pass; d=google.com; s=arc-20160816; b=yw0j1PqegBtzenRPaPneuM9rq/B/34qxgCQktAd3RFKd/+I4YFHSnTvXAfK7BzwWW+ DDJEas2u75M6Zo1QaCiDJwoaedj03/xIi815WPiG+qThePvL5Iz/YigmcTcEqs5g3uTf UN+xTjCG5iR43ccQGvPGYhgUSFtj2NDn1eOTbjaQ2WLNCdOrrAn+Ij+ygvcX1LGEbO8U Aev9l4CGVQ5tmqj9faNe2fHnzaCvQncbN7M0CwmYRSHFZjzaftGXAzLLPezav/kSfbLF 4XnFIbJNnKNi98Uv/NpZPqQBrYiWSWAJtmmZOHUIs98sYk4msZJ5Af9jWGxkPmUtqUep kT2Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=lgdp6h0ntNPf8Sj2ifrIcOWD5T8JTNPYdgl39twOm/w=; fh=7eqBo8bBqyhg/DxC1JG83KiRs7U4AFzXak7dXfGbCTI=; b=z1FWRqk5L012w6RlvBOTSBwBOD5F/01oqyQAZ/rRUf6YQHobxY4Q5TYS/sLaWSb8T4 oXChOvEL95ORUi3+u6OeP4wgsfHZOGlYu4yrlQa1pClTk8lRKAR1q4wcLASo8feOnb5e VUILkWSFpAxunvBYN6bsa6DWcg0eJfnqwZUp7cKWiIAOjDardYVar7FlPaizOVOHJBw4 JQnpl45t2o6PCDxOq2bbFW12JUaQeKg0Q2wGnoO3hOopE9aSEDQZdprZnrSRXhsxuUQj bFctYFk8+lGA1LxoxIic88q3cwvbBOMeis0yhS3N7WOSskzENyDyBnv5cOtTRjoSdbUF vwlA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SFfbKYoA; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-153684-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-153684-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id fh23-20020a056a00391700b006ed41e29bffsi8154419pfb.224.2024.04.22.09.15.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 09:15:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-153684-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SFfbKYoA; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-153684-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-153684-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 0DBCA28158D for ; Mon, 22 Apr 2024 16:15:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A969315380F; Mon, 22 Apr 2024 16:15:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SFfbKYoA" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A87CF1474BA; Mon, 22 Apr 2024 16:15:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713802529; cv=none; b=VbXojXcs+e3efv6e/6ML9I0t3lwuaJ3fpPeUkzYrpYRMsmRZh7F7nzlO/2IgqH+4PBOxZxVlAU6wkn9pTPlnqOTix//E9mD6KhtooyyqVv0oF1UGyOSQxEBPHwFRyfsnt9YUBJ6iM0zqKEHiS9g/JIcNgY92qjOr7LxkthveBX0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713802529; c=relaxed/simple; bh=+T7qGoJM5CptwNtRlbFQYHPrnonOpqhbu/z+ZqbwDxk=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=shWMQBWlPyWrjN0wdec/lr82W8xvCVM52kSQQ83K42oufuN6Wve0PoF91YZ0SQ5+SjxD0L6uvWymkfS/WI5GPhK7NbLIOiPX/3ZEo6cW6BKTS1XCEpj1++Cx0HEoEPhVTQNJktIDjy7zHXhMq6sdHMZw+vX0u6qfjsreSOJywn0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SFfbKYoA; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C0BEC32783; Mon, 22 Apr 2024 16:15:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713802529; bh=+T7qGoJM5CptwNtRlbFQYHPrnonOpqhbu/z+ZqbwDxk=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=SFfbKYoALeaHJ0fDwzw0lg1SCTCKx3hn0tFWM3d/QyrFQLf7233i9lfrySHzfQjxj 2U60qOufIXMn+70hs6Uw2GYvdz0C0wGp72OWXgSZclopmLgufHn+XJ/U8RZ3SD7d/m 0TKMoG0OY2vtO48ZlPPCm1tMLwswG1Vag/7gxDXYhMObsB0OQQex9zorRVA9+dXeBV qg1WtVZYFO1kKnMDBxcp8OfJXxVZTcexDXFWQwblj2d8DBIRAmKCB0PrEWJsF9hBOT 0PNFoRKrLj7YdLbipK7TJ4c9MId58O8IMMSkS7US/xlr7nLbC5JXazTRLsPmKZbm0Y YHrkVYfahXsHg== Received: by mail-oi1-f175.google.com with SMTP id 5614622812f47-3c75145c6c4so39874b6e.0; Mon, 22 Apr 2024 09:15:29 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCVXRs2xKuChmGSyeczlOAtjbDo1VELDN8OHMeSFjkD3T69SzZO4ICyJdI9stJbaWsJZzHag9VbkS/NVdiDlM9WqwiQqbGPxYPeohHp+RfzaIbJM2q2xWLfLDuPyrqH7hVAsJQgBCcrJ0bhOJnNThcZNoDz2xLtV9BPZh51kjYPJe4gnacpSzBEjJ6vUfiIGGAqI9WbszI94UWFrAjb3cGawEoxiGHwAhWiYqw== X-Gm-Message-State: AOJu0Yy8TSTx6ypRU7TEBkEHXvg4C5rcefTMhik85C9582Qo+9WAG78O P/VBPK6vd7r/uRDK4JzxRcogxDnBR7evC+bjfoBYrlWObynRxlUVOef/ohShZT3tKbZkx3Nw0v7 Y2aOqjf/F3+BcNllN/MWN84Cd1wg= X-Received: by 2002:a05:6870:b28c:b0:22e:7cc0:ebd5 with SMTP id c12-20020a056870b28c00b0022e7cc0ebd5mr12811422oao.5.1713802528328; Mon, 22 Apr 2024 09:15:28 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240422060835.71708-1-W_Armin@gmx.de> In-Reply-To: From: "Rafael J. Wysocki" Date: Mon, 22 Apr 2024 18:15:13 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH RESEND v5] ACPI: fan: Add hwmon support To: Andy Shevchenko , Armin Wolf Cc: mlj@danelec.com, rafael.j.wysocki@intel.com, lenb@kernel.org, jdelvare@suse.com, linux@roeck-us.net, linux@weissschuh.net, ilpo.jarvinen@linux.intel.com, linux-acpi@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Apr 22, 2024 at 9:36=E2=80=AFAM Andy Shevchenko wrote: > > Mon, Apr 22, 2024 at 08:08:35AM +0200, Armin Wolf kirjoitti: > > Currently, the driver does only support a custom sysfs > > interface to allow userspace to read the fan speed. > > Add support for the standard hwmon interface so users > > can read the fan speed with standard tools like "sensors". > > > > Tested with a custom ACPI SSDT. > > ... > > > +/* > > + * fan_hwmon.c - hwmon interface for the ACPI Fan driver > > No file name in the file, it makes an unneeded burden if file is going to= be > renamed. > > > + * > > + * Copyright (C) 2024 Armin Wolf > > + */ > > ... > > > +#include > > +#include > > Please, follow IWYU pronciple, e.g., missing err.h here. > > > +#include > > +#include > > ... > > > +/* Returned when the ACPI fan does not support speed reporting */ > > +#define FAN_SPEED_UNAVAILABLE 0xffffffff > > +#define FAN_POWER_UNAVAILABLE 0xffffffff > > Shouldn't these be rather as ~0 of the respective types or _MAX (from lim= its.h) > or something like that? > > ... > > > +static struct acpi_fan_fps *acpi_fan_get_current_fps(struct acpi_fan *= fan, u64 control) > > +{ > > + int i; > > unsigned > > > + for (i =3D 0; i < fan->fps_count; i++) { > > + if (fan->fps[i].control =3D=3D control) > > + return &fan->fps[i]; > > + } > > + > > + return NULL; > > +} > > ... > > > +static umode_t acpi_fan_is_visible(const void *drvdata, enum hwmon_sen= sor_types type, u32 attr, > > + int channel) > > +{ > > + const struct acpi_fan *fan =3D drvdata; > > + int i; > > unsigned > > > + switch (type) { > > + case hwmon_fan: > > + switch (attr) { > > + case hwmon_fan_input: > > + return 0444; > > + case hwmon_fan_target: > > + /* When in fine grain control mode, not every fan= control value > > + * has an associated fan performance state. > > + */ > > + if (fan->fif.fine_grain_ctrl) > > + return 0; > > + > > + return 0444; > > + default: > > > + break; > > + } > > + break; > > Instead of two breaks, just return 0 from 'default' case. I agree here, but for a different reason. If all of the other cases return from the function, the default one should return either unless there is a specific reason not to. IIUC, there's no such reason in this case. > > + case hwmon_power: > > + switch (attr) { > > + case hwmon_power_input: > > + /* When in fine grain control mode, not every fan= control value > > + * has an associated fan performance state. > > + */ > > /* > * Use correct style for multi-line > * comment blocks. As in this example. > */ Yes, please. Thanks!