Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp27965528rwd; Tue, 4 Jul 2023 10:24:54 -0700 (PDT) X-Google-Smtp-Source: APBJJlFPPJ3hVqeKENX7ziuDafFutQaENkwwHfLuf/DAAY2RqzwP37iSgFHWr4t01Itv33Dj8Ocl X-Received: by 2002:a05:6a00:24d3:b0:675:8f71:28f1 with SMTP id d19-20020a056a0024d300b006758f7128f1mr14871460pfv.30.1688491493686; Tue, 04 Jul 2023 10:24:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688491493; cv=none; d=google.com; s=arc-20160816; b=Ydg7dP1HMJarFSx6xTdnGe5FKlBEpyXr69gZMFpb2KdORSoDZQvgTyDWOElopA+loX 4QQF4DZ4C4RKa1Dy2WtfHhZyV6NL3wD7lpVSFtKsdmLvG7SP6OUwUDWVGBRiUyTXGh8q TzF4wZ2NuF1BuoqgB8co6d1ilNkAjfIdGi+nEF0NyKhSsml2b//WnvALi6QIsEqrmZzH GgcQgGhuZKKVbvv6J3OOLER9qmjudriBEiCu52u5NZi/6FCeedwZv1FgtaJ1eVgRwb96 Pu9ZkAfxvFXPkVV2eEN4W5wpKtK2+wPU82d9sNxqj657M8VAvWxHdDU9GBFKbLI4oWBD bbqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:sender:dkim-signature; bh=QL2M3Cz818dqNrKSbTrYj6OW1NR2RpmjCHPMkuvFkQo=; fh=W0IMRfE1Je1IOV79j1mlTlGBPh/asgMVMk+cm86Dl+A=; b=ghmlLbYzdpkeb+8WfV0++Vl6m/8mYAfW8DMMYcyTEyC8jTZnP12JaCSeDxrGxSmsLW xP03htlW51Ge+FKG3xn98Sx2DklNVeEb3W/N9T21e/bd2djXxtHo40mL9mp1h6AvLuXp nsOxBUInOcJtXXmqhfHcdC53ZNkrli+R0QYrWq3BifH3aSeuoysv82u+Fw8Yosli+5mZ VVQz9TuJuL0o/6b5HxAhlkgo/IKx6vDpCkmn/ZrP+iaOa74DR4fQcTjTuBw2LqXEpVvU 9/mpTcgyGvj2Hy0JdgWkkUtqGH9bId68Fqbfg9l9KLNiPkcpufcsm6keXPZaFHNpaE5q RcRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="i/gVflRd"; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b13-20020a056a000ccd00b00666b95e38efsi8119055pfv.34.2023.07.04.10.24.41; Tue, 04 Jul 2023 10:24:53 -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=@gmail.com header.s=20221208 header.b="i/gVflRd"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230259AbjGDQoN (ORCPT + 99 others); Tue, 4 Jul 2023 12:44:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230472AbjGDQoL (ORCPT ); Tue, 4 Jul 2023 12:44:11 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2C8B19B0; Tue, 4 Jul 2023 09:43:45 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1b8ad356fe4so444175ad.2; Tue, 04 Jul 2023 09:43:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688489021; x=1691081021; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :sender:from:to:cc:subject:date:message-id:reply-to; bh=QL2M3Cz818dqNrKSbTrYj6OW1NR2RpmjCHPMkuvFkQo=; b=i/gVflRd97a00KEqaLzysrTszK4h5XmJLwrdCSoj2wmmDaMz2EGVzcKKFO+BwRxNAY 004uTe3XYEZvQEgvBwnek52d5H7ki8wY+iKCYR2MeD+8rRXUJg6VnnwmTiEcoUe4UIAd Kq4/fJPy/9fjMfCCthMMqzo24rgL4Tu6o+SxswqqNMxyzUkYk4Jshpr1n7B998NOQnXk YlxoWaJAVPgrCaAWUGqdU/kEnkOUJSvzK/DkvMWdgvVqKyjsBLdq3htHrPpCINJEO+12 LhO0ZrXn/zn7/VrKwZTHEWt3SsD39QyGUWet47cVKhWxdw1e2263V4whHazjvJDvk90a d27Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688489021; x=1691081021; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :sender:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=QL2M3Cz818dqNrKSbTrYj6OW1NR2RpmjCHPMkuvFkQo=; b=akKt9BCGHJ8kDMqID1u3M1eKzskU260WAtmQ4WitP0HsIElZUsSnNdauhOoZla79ng iHGfR6gbjE0DQJJeof8qWhTYiYiNMwNQQxfTAPMWCw4K6Y2ds+rEXtJcUJ1q90rHVRJG 600cgbFVgb3UpFBoEyr2jbvzkBeZcbl9EIN9lAmd8muKeffRm8nI8M3dvBeADEzuGFqs bmCf3cajRJBbOaTn6q8YX07ocHvo8gFDDtqY1GXWD1ExlJkVRHnjTiEBHoPGwVTC6XE6 rL0GrNwk7MDy29qpSRSEdfU9L2UVsi3cfgQj18GIHjlrKrmJ3BK+IUWZlimZjkySICqu Vjeg== X-Gm-Message-State: AC+VfDzfMP5gwcdSgfeZ+dvMf2RbANeWP+4ELt+i6Tfq7i7WhyAIn3wa e6sH4pd6LRKO7K2Lm9J8Jck= X-Received: by 2002:a05:6a20:101a:b0:126:eed0:f55e with SMTP id gs26-20020a056a20101a00b00126eed0f55emr11516223pzc.11.1688489021396; Tue, 04 Jul 2023 09:43:41 -0700 (PDT) Received: from ?IPV6:2600:1700:e321:62f0:329c:23ff:fee3:9d7c? ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id iw21-20020a170903045500b001b8a4a9622dsm1806611plb.113.2023.07.04.09.43.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 04 Jul 2023 09:43:40 -0700 (PDT) Sender: Guenter Roeck Message-ID: Date: Tue, 4 Jul 2023 09:43:39 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [PATCH 1/3] hwmon: (oxp-sensors): remove static board variable Content-Language: en-US To: Greg Kroah-Hartman Cc: linux-hwmon@vger.kernel.org, samsagax@gmail.com, linux-kernel@vger.kernel.org References: <20230704131715.44454-5-gregkh@linuxfoundation.org> <20230704131715.44454-6-gregkh@linuxfoundation.org> <2023070402-festive-rind-9274@gregkh> <2023070425-jujitsu-ladder-195e@gregkh> From: Guenter Roeck In-Reply-To: <2023070425-jujitsu-ladder-195e@gregkh> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no 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 On 7/4/23 09:14, Greg Kroah-Hartman wrote: > On Tue, Jul 04, 2023 at 07:14:54AM -0700, Guenter Roeck wrote: >> On 7/4/23 06:44, Greg Kroah-Hartman wrote: >>> On Tue, Jul 04, 2023 at 06:39:07AM -0700, Guenter Roeck wrote: >>>> On 7/4/23 06:17, Greg Kroah-Hartman wrote: >>>>> 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. >>>>> >>>> >>>> This is expensive. I think it would be much better to just move >>>> the board type detection into the init code and not instantiate >>>> the driver in the fist place if the board type is unknown. >>> >>> The board type detection is all over the place in the driver, it's not >>> just for "unknown" types, so how about just saving the board type at >>> probe time and using it then for all other places? >>> >> >> I must be missing something. The current code detects the board type >> only once, in the probe function. Otherwise the static variable is used. >> You are replacing it with repeated calls to get_board_type(). >> The whole point of the static variable is to avoid the cost of repeated >> calls to dmi_first_match(). > > Ah, ok, yes, I was refering to the fact that the driver relies on the > detection of the device type in lots of different places (and doesn't > ever error out from the detection call.) > I am lost again. Current code: dmi_entry = dmi_first_match(dmi_table); if (!dmi_entry || boot_cpu_data.x86_vendor != X86_VENDOR_AMD) return -ENODEV; >>>> We can handle the static variable separately if it really bothers >>>> you that much. >>> >>> I did this change to make patch 2/3 more "obvious" what is happening >>> when the in_visible() callback happens, so that you don't have to worry >>> about the saved value or not. But this whole patch isn't really needed >>> if you don't mind the lookup just happening in the in_visible() callback >>> for the first time. >>> >> >> That would at least be a minimal change, and just add one extra lookup >> which is only called once (or zero, if it is used to save the board type). > > Ok, I'll switch it up, but really, it's just a simple table lookup loop, > and none of the detection calls are on a "hot path" that I can > determine. Or am I missing something? > >> As I said, my solution would be to move the board type detection >> into the init function and not instantiate the driver in the first >> place if the probe function would bail out anyway. > > That's not the case today, the only way the probe function would fail > today is if the registering of the sysfs files fail. It does not matter > if the board detection call passes or not. > Again, dmi_entry = dmi_first_match(dmi_table); if (!dmi_entry || boot_cpu_data.x86_vendor != X86_VENDOR_AMD) return -ENODEV; ^^^^^^^^^^^^^^^ What am I missing ? Guenter