public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Guenter Roeck <linux@roeck-us.net>
Cc: linux-hwmon@vger.kernel.org, samsagax@gmail.com,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] hwmon: (oxp-sensors): remove static board variable
Date: Tue, 4 Jul 2023 17:52:43 +0100	[thread overview]
Message-ID: <2023070424-strangely-whiff-7d97@gregkh> (raw)
In-Reply-To: <fd1cab46-0a51-6aab-8fda-f603fd4e0058@roeck-us.net>

On Tue, Jul 04, 2023 at 09:43:39AM -0700, Guenter Roeck wrote:
> 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 ?

Nothing, I'm missing it, sorry.  Been a long day, let me redo this...

greg k-h

  reply	other threads:[~2023-07-04 16:54 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-04 13:17 [PATCH 0/3] driver core: remove final user of devm_device_add_groups() Greg Kroah-Hartman
2023-07-04 13:17 ` [PATCH 1/3] hwmon: (oxp-sensors): remove static board variable Greg Kroah-Hartman
2023-07-04 13:39   ` Guenter Roeck
2023-07-04 13:44     ` Greg Kroah-Hartman
2023-07-04 14:14       ` Guenter Roeck
2023-07-04 16:14         ` Greg Kroah-Hartman
2023-07-04 16:43           ` Guenter Roeck
2023-07-04 16:52             ` Greg Kroah-Hartman [this message]
2023-07-04 19:44     ` Joaquin Aramendia
2023-07-04 13:17 ` [PATCH 2/3] hwmon: (oxp-sensors): move to use dev_groups from platform device Greg Kroah-Hartman
2023-07-04 13:17 ` [PATCH 3/3] driver core: remove devm_device_add_groups() Greg Kroah-Hartman
2023-07-04 16:05   ` Rafael J. Wysocki
2023-07-05 18:50   ` Dmitry Torokhov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2023070424-strangely-whiff-7d97@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=samsagax@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox