From patchwork Tue Jul 4 13:17:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 13301254 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87EEBEB64D9 for ; Tue, 4 Jul 2023 13:19:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230516AbjGDNS7 (ORCPT ); Tue, 4 Jul 2023 09:18:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231375AbjGDNSd (ORCPT ); Tue, 4 Jul 2023 09:18:33 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B218510F5; Tue, 4 Jul 2023 06:18:05 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8DEB861259; Tue, 4 Jul 2023 13:17:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A639AC433C7; Tue, 4 Jul 2023 13:17:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1688476662; bh=9vUu33erJrLKcQGqMGFnvE8WQvh13xozOrZ4w+HY/xI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MMkozYtK84+lmlgpbelApGQ2e9158q3VW5g6YbjU2H9bkeVi2unsT+vKksWV6gGRs qwY+HAnOz8ysLFA2ykcZl4sUO41XWUKujKVZBaQ6Kkj8DjnTaBmw3zgi/w6nNxiVZM YhSms/ySgKUNcglef9czFRC0Y2oAz7Q8zdhmb14Q= From: Greg Kroah-Hartman To: linux-hwmon@vger.kernel.org Cc: linux@roeck-us.net, samsagax@gmail.com, linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH 1/3] hwmon: (oxp-sensors): remove static board variable Date: Tue, 4 Jul 2023 14:17:17 +0100 Message-ID: <20230704131715.44454-6-gregkh@linuxfoundation.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230704131715.44454-5-gregkh@linuxfoundation.org> References: <20230704131715.44454-5-gregkh@linuxfoundation.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4033; i=gregkh@linuxfoundation.org; h=from:subject; bh=9vUu33erJrLKcQGqMGFnvE8WQvh13xozOrZ4w+HY/xI=; b=owGbwMvMwCRo6H6F97bub03G02pJDClLpO9JLeFbElY84UbQEw37ayfvfYs/X1Htn/5WVXMNa 3MBz/1LHbEsDIJMDLJiiixftvEc3V9xSNHL0PY0zBxWJpAhDFycAjCRv+kM80xt5s5yC9svxt5S /tzk1cX04sLPDxnmqT1Re+wmMlfw54nCxVMOK0jsWJCoBgA= X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Drivers should not have a single static variable for the type of device they are bound to. While this driver is really going to only have one device at a time in the system, remove the static variable and instead, look up the device type when needed. Cc: Joaquín Ignacio Aramendía Cc: Guenter Roeck Cc: linux-hwmon@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/hwmon/oxp-sensors.c | 47 ++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/drivers/hwmon/oxp-sensors.c b/drivers/hwmon/oxp-sensors.c index e1a907cae820..3bcba0c476c4 100644 --- a/drivers/hwmon/oxp-sensors.c +++ b/drivers/hwmon/oxp-sensors.c @@ -48,10 +48,9 @@ enum oxp_board { oxp_mini_amd, oxp_mini_amd_a07, oxp_mini_amd_pro, + UNKNOWN, }; -static enum oxp_board board; - /* Fan reading and PWM */ #define OXP_SENSOR_FAN_REG 0x76 /* Fan reading is 2 registers long */ #define OXP_SENSOR_PWM_ENABLE_REG 0x4A /* PWM enable is 1 register long */ @@ -136,6 +135,24 @@ static const struct dmi_system_id dmi_table[] = { {}, }; +static enum oxp_board get_board_type(void) +{ + const struct dmi_system_id *dmi_entry; + + /* + * Have to check for AMD processor here because DMI strings are the + * same between Intel and AMD boards, the only way to tell them apart + * is the CPU. + * Intel boards seem to have different EC registers and values to + * read/write. + */ + dmi_entry = dmi_first_match(dmi_table); + if (!dmi_entry || boot_cpu_data.x86_vendor != X86_VENDOR_AMD) + return UNKNOWN; + + return (enum oxp_board)(unsigned long)dmi_entry->driver_data; +} + /* Helper functions to handle EC read/write */ static int read_from_ec(u8 reg, int size, long *val) { @@ -182,7 +199,7 @@ static int tt_toggle_enable(void) u8 reg; u8 val; - switch (board) { + switch (get_board_type()) { case oxp_mini_amd_a07: reg = OXP_OLD_TURBO_SWITCH_REG; val = OXP_OLD_TURBO_TAKE_VAL; @@ -203,7 +220,7 @@ static int tt_toggle_disable(void) u8 reg; u8 val; - switch (board) { + switch (get_board_type()) { case oxp_mini_amd_a07: reg = OXP_OLD_TURBO_SWITCH_REG; val = OXP_OLD_TURBO_RETURN_VAL; @@ -249,7 +266,7 @@ static ssize_t tt_toggle_show(struct device *dev, u8 reg; long val; - switch (board) { + switch (get_board_type()) { case oxp_mini_amd_a07: reg = OXP_OLD_TURBO_SWITCH_REG; break; @@ -315,7 +332,7 @@ static int oxp_platform_read(struct device *dev, enum hwmon_sensor_types type, ret = read_from_ec(OXP_SENSOR_PWM_REG, 1, val); if (ret) return ret; - switch (board) { + switch (get_board_type()) { case aya_neo_2: case aya_neo_air: case aya_neo_air_pro: @@ -357,7 +374,7 @@ static int oxp_platform_write(struct device *dev, enum hwmon_sensor_types type, case hwmon_pwm_input: if (val < 0 || val > 255) return -EINVAL; - switch (board) { + switch (get_board_type()) { case aya_neo_2: case aya_neo_air: case aya_neo_air_pro: @@ -412,25 +429,11 @@ static const struct hwmon_chip_info oxp_ec_chip_info = { /* Initialization logic */ static int oxp_platform_probe(struct platform_device *pdev) { - const struct dmi_system_id *dmi_entry; struct device *dev = &pdev->dev; struct device *hwdev; int ret; - /* - * Have to check for AMD processor here because DMI strings are the - * same between Intel and AMD boards, the only way to tell them apart - * is the CPU. - * Intel boards seem to have different EC registers and values to - * read/write. - */ - dmi_entry = dmi_first_match(dmi_table); - if (!dmi_entry || boot_cpu_data.x86_vendor != X86_VENDOR_AMD) - return -ENODEV; - - board = (enum oxp_board)(unsigned long)dmi_entry->driver_data; - - switch (board) { + switch (get_board_type()) { case aok_zoe_a1: case oxp_mini_amd_a07: case oxp_mini_amd_pro: From patchwork Tue Jul 4 13:17:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 13301253 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFB38EB64DA for ; Tue, 4 Jul 2023 13:18:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231174AbjGDNSZ (ORCPT ); Tue, 4 Jul 2023 09:18:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229441AbjGDNSX (ORCPT ); Tue, 4 Jul 2023 09:18:23 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 395E21727; Tue, 4 Jul 2023 06:17:51 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 72B9261261; Tue, 4 Jul 2023 13:17:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E24CC433C7; Tue, 4 Jul 2023 13:17:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1688476669; bh=oE4RQqmUGY45i8W34rZXtMiLxR88iomAGlfzs9Qo+uE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dyRF5n39RMpeVXrd/SkpRtifqXWamCc2n5HL5pJgSuVEAXiCf275TeAdj12L2Q7ZX L4EURs9/spJk4gkI9jttM3vApNu9km6ou9slVa7Lul1cXreUIF9lVDC5WbrseAc262 bxKNuSCvHPtIwrCFK5Sp63oWSOYcyXzyykCh9Z2A= From: Greg Kroah-Hartman To: linux-hwmon@vger.kernel.org Cc: linux@roeck-us.net, samsagax@gmail.com, linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH 2/3] hwmon: (oxp-sensors): move to use dev_groups from platform device Date: Tue, 4 Jul 2023 14:17:18 +0100 Message-ID: <20230704131715.44454-7-gregkh@linuxfoundation.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230704131715.44454-5-gregkh@linuxfoundation.org> References: <20230704131715.44454-5-gregkh@linuxfoundation.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2423; i=gregkh@linuxfoundation.org; h=from:subject; bh=oE4RQqmUGY45i8W34rZXtMiLxR88iomAGlfzs9Qo+uE=; b=owGbwMvMwCRo6H6F97bub03G02pJDClLpO9Fr31+uEZO6Xabxkr9JI6XPT9O+LyXcjr0fcusD V7205eLdcSyMAgyMciKKbJ82cZzdH/FIUUvQ9vTMHNYmUCGMHBxCsBEpgsxzFPqEN9+ufSF0ran Ym/fXxVy/fRNuZBhnnVL+Ebn2b3uU0PaRVp/lG6p0v50EQA= X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org A driver should not be manually adding groups in its probe function (it will race with userspace), so replace the call to devm_device_add_groups() to use the platform dev_groups callback instead. This is the last in-kernel user of devm_device_add_groups(), so it can be successfully removed at this point in time. Cc: Joaquín Ignacio Aramendía Cc: Guenter Roeck Cc: linux-hwmon@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/hwmon/oxp-sensors.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/drivers/hwmon/oxp-sensors.c b/drivers/hwmon/oxp-sensors.c index 3bcba0c476c4..34e561ba9e8b 100644 --- a/drivers/hwmon/oxp-sensors.c +++ b/drivers/hwmon/oxp-sensors.c @@ -408,12 +408,33 @@ static const struct hwmon_channel_info * const oxp_platform_sensors[] = { NULL, }; +static umode_t oxp_ec_is_visible(struct kobject *kobj, struct attribute *attr, int n) +{ + switch (get_board_type()) { + case aok_zoe_a1: + case oxp_mini_amd_a07: + case oxp_mini_amd_pro: + return attr->mode; + default: + break; + } + return 0; +} + static struct attribute *oxp_ec_attrs[] = { &dev_attr_tt_toggle.attr, NULL }; -ATTRIBUTE_GROUPS(oxp_ec); +static struct attribute_group oxp_ec_attribute_group = { + .is_visible = oxp_ec_is_visible, + .attrs = oxp_ec_attrs, +}; + +static const struct attribute_group *oxp_ec_groups[] = { + &oxp_ec_attribute_group, + NULL +}; static const struct hwmon_ops oxp_ec_hwmon_ops = { .is_visible = oxp_ec_hwmon_is_visible, @@ -431,19 +452,6 @@ static int oxp_platform_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct device *hwdev; - int ret; - - switch (get_board_type()) { - case aok_zoe_a1: - case oxp_mini_amd_a07: - case oxp_mini_amd_pro: - ret = devm_device_add_groups(dev, oxp_ec_groups); - if (ret) - return ret; - break; - default: - break; - } hwdev = devm_hwmon_device_register_with_info(dev, "oxpec", NULL, &oxp_ec_chip_info, NULL); @@ -454,6 +462,7 @@ static int oxp_platform_probe(struct platform_device *pdev) static struct platform_driver oxp_platform_driver = { .driver = { .name = "oxp-platform", + .dev_groups = oxp_ec_groups, }, .probe = oxp_platform_probe, }; From patchwork Tue Jul 4 13:17:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 13301255 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7C37EB64DA for ; Tue, 4 Jul 2023 13:19:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231316AbjGDNS7 (ORCPT ); Tue, 4 Jul 2023 09:18:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231435AbjGDNSf (ORCPT ); Tue, 4 Jul 2023 09:18:35 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE55810C6; Tue, 4 Jul 2023 06:18:09 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id F400161269; Tue, 4 Jul 2023 13:17:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 13044C433C7; Tue, 4 Jul 2023 13:17:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1688476672; bh=wO5FjuwmvYWrR+WFEVbVC4lIXFhi2kqR5IRQhH/0/A4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Iq5v1U/A2O9AQwBlFBY0H6kc1MaeDU1jBnb5sW5wIcnSiLMS5+933yYGj5huZrGah +3u2LubTVct81x6Xo1ywpXtfj4p4BRZ0kRPHJ/W8UjgqGuAPmiao1x3ukfRRxuMERj oQu6BtzBRLvsWyfcJzLUbfDbsSDgyribMb9Lmrvo= From: Greg Kroah-Hartman To: linux-hwmon@vger.kernel.org Cc: linux@roeck-us.net, samsagax@gmail.com, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Dmitry Torokhov , "Rafael J. Wysocki" Subject: [PATCH 3/3] driver core: remove devm_device_add_groups() Date: Tue, 4 Jul 2023 14:17:19 +0100 Message-ID: <20230704131715.44454-8-gregkh@linuxfoundation.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230704131715.44454-5-gregkh@linuxfoundation.org> References: <20230704131715.44454-5-gregkh@linuxfoundation.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3089; i=gregkh@linuxfoundation.org; h=from:subject; bh=wO5FjuwmvYWrR+WFEVbVC4lIXFhi2kqR5IRQhH/0/A4=; b=owGbwMvMwCRo6H6F97bub03G02pJDClLpO8V1LnWrTv7s+nDzDtiF1xv/9k+5ThLvMDC2devL 3Lcp3aLryOWhUGQiUFWTJHlyzaeo/srDil6GdqehpnDygQyhIGLUwAm4rWTYa7Uy323bR8/572c Y71oxjpLie0//3gzzM+2j7T3s45Ja6mZtrexoKlvwfPFRwA= X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org There is no more in-kernel users of this function, and no driver should ever be using it, so remove it from the kernel. Cc: Dmitry Torokhov Cc: "Rafael J. Wysocki" Signed-off-by: Greg Kroah-Hartman Acked-by: Rafael J. Wysocki Acked-by: Dmitry Torokhov --- drivers/base/core.c | 45 ------------------------------------------ include/linux/device.h | 2 -- 2 files changed, 47 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 3dff5037943e..94187c0b577d 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -2748,15 +2748,6 @@ static void devm_attr_group_remove(struct device *dev, void *res) sysfs_remove_group(&dev->kobj, group); } -static void devm_attr_groups_remove(struct device *dev, void *res) -{ - union device_attr_group_devres *devres = res; - const struct attribute_group **groups = devres->groups; - - dev_dbg(dev, "%s: removing groups %p\n", __func__, groups); - sysfs_remove_groups(&dev->kobj, groups); -} - /** * devm_device_add_group - given a device, create a managed attribute group * @dev: The device to create the group for @@ -2789,42 +2780,6 @@ int devm_device_add_group(struct device *dev, const struct attribute_group *grp) } EXPORT_SYMBOL_GPL(devm_device_add_group); -/** - * devm_device_add_groups - create a bunch of managed attribute groups - * @dev: The device to create the group for - * @groups: The attribute groups to create, NULL terminated - * - * This function creates a bunch of managed attribute groups. If an error - * occurs when creating a group, all previously created groups will be - * removed, unwinding everything back to the original state when this - * function was called. It will explicitly warn and error if any of the - * attribute files being created already exist. - * - * Returns 0 on success or error code from sysfs_create_group on failure. - */ -int devm_device_add_groups(struct device *dev, - const struct attribute_group **groups) -{ - union device_attr_group_devres *devres; - int error; - - devres = devres_alloc(devm_attr_groups_remove, - sizeof(*devres), GFP_KERNEL); - if (!devres) - return -ENOMEM; - - error = sysfs_create_groups(&dev->kobj, groups); - if (error) { - devres_free(devres); - return error; - } - - devres->groups = groups; - devres_add(dev, devres); - return 0; -} -EXPORT_SYMBOL_GPL(devm_device_add_groups); - static int device_add_attrs(struct device *dev) { const struct class *class = dev->class; diff --git a/include/linux/device.h b/include/linux/device.h index 66c13965153d..6dd087e4223d 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -1164,8 +1164,6 @@ static inline void device_remove_group(struct device *dev, return device_remove_groups(dev, groups); } -int __must_check devm_device_add_groups(struct device *dev, - const struct attribute_group **groups); int __must_check devm_device_add_group(struct device *dev, const struct attribute_group *grp);