mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: "Enrico Weigelt, metux IT consult" <info@metux.net>
Cc: linux-kernel@vger.kernel.org, jdelvare@suse.com,
	linux-hwmon@vger.kernel.org
Subject: Re: [PATCH] drivers: hwmon: i5k_amb: simplify probing / device identification
Date: Thu, 6 Jun 2019 09:33:08 -0700	[thread overview]
Message-ID: <20190606163308.GA29829@roeck-us.net> (raw)
In-Reply-To: <1559833233-25723-2-git-send-email-info@metux.net>

On Thu, Jun 06, 2019 at 05:00:33PM +0200, Enrico Weigelt, metux IT consult wrote:
> From: Enrico Weigelt <info@metux.net>
> 
> Simpilify the probing by putting all chip-specific data directly
> into the pci match table, removing the redundant chipset_ids table.
> 
> Signed-off-by: Enrico Weigelt <info@metux.net>
> ---

You don't need the introductory e-mail for a single patch.
Just add the extra comments here.

>  drivers/hwmon/i5k_amb.c | 45 +++++++++++++++++++++++----------------------
>  1 file changed, 23 insertions(+), 22 deletions(-)
> 
> diff --git a/drivers/hwmon/i5k_amb.c b/drivers/hwmon/i5k_amb.c
> index b09c39a..f06c40f 100644
> --- a/drivers/hwmon/i5k_amb.c
> +++ b/drivers/hwmon/i5k_amb.c
> @@ -414,15 +414,15 @@ static int i5k_amb_add(void)
>  }
>  
>  static int i5k_find_amb_registers(struct i5k_amb_data *data,
> -					    unsigned long devid)
> +				  const struct pci_device_id *devid)
>  {
>  	struct pci_dev *pcidev;
>  	u32 val32;
>  	int res = -ENODEV;
>  
>  	/* Find AMB register memory space */
> -	pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
> -				devid,
> +	pcidev = pci_get_device(devid->vendor,
> +				devid->device,
>  				NULL);
>  	if (!pcidev)
>  		return -ENODEV;
> @@ -447,14 +447,18 @@ static int i5k_find_amb_registers(struct i5k_amb_data *data,
>  	return res;
>  }
>  
> -static int i5k_channel_probe(u16 *amb_present, unsigned long dev_id)
> +static int i5k_channel_probe(u16 *amb_present,
> +			     const struct pci_device_id *devid,
> +			     int next)

'next' is a bit misleading. Something like "offset" or "id_offset" might be
better. A better option would be to not change the function parameters and
generate dev_id when the function is called. After all, the change in this
function is not really necessary and can be handled in calling code.

>  {
>  	struct pci_dev *pcidev;
>  	u16 val16;
>  	int res = -ENODEV;
>  
>  	/* Copy the DIMM presence map for these two channels */
> -	pcidev = pci_get_device(PCI_VENDOR_ID_INTEL, dev_id, NULL);
> +	pcidev = pci_get_device(devid->vendor,
> +				(unsigned long)devid->driver_data + next,
> +				NULL);
>  	if (!pcidev)
>  		return -ENODEV;
>  
> @@ -473,23 +477,20 @@ static int i5k_channel_probe(u16 *amb_present, unsigned long dev_id)
>  	return res;
>  }
>  
> -static struct {
> -	unsigned long err;
> -	unsigned long fbd0;
> -} chipset_ids[]  = {
> -	{ PCI_DEVICE_ID_INTEL_5000_ERR, PCI_DEVICE_ID_INTEL_5000_FBD0 },
> -	{ PCI_DEVICE_ID_INTEL_5400_ERR, PCI_DEVICE_ID_INTEL_5400_FBD0 },
> -	{ 0, 0 }
> -};
> -
> -#ifdef MODULE
>  static const struct pci_device_id i5k_amb_ids[] = {
> -	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5000_ERR) },
> -	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_ERR) },
> +	{
> +		.vendor		= PCI_VENDOR_ID_INTEL,
> +		.device		= PCI_DEVICE_ID_INTEL_5000_ERR,
> +		.driver_data	= PCI_DEVICE_ID_INTEL_5000_FBD0,
> +	},
> +	{
> +		.vendor		= PCI_VENDOR_ID_INTEL,
> +		.device		= PCI_DEVICE_ID_INTEL_5400_ERR,
> +		.driver_data	= PCI_DEVICE_ID_INTEL_5400_FBD0,

Why not use PCI_DEVICE_DATA() ?

> +	},
>  	{ 0, }
>  };
>  MODULE_DEVICE_TABLE(pci, i5k_amb_ids);
> -#endif
>  
>  static int i5k_amb_probe(struct platform_device *pdev)
>  {
> @@ -504,22 +505,22 @@ static int i5k_amb_probe(struct platform_device *pdev)
>  	/* Figure out where the AMB registers live */
>  	i = 0;
>  	do {
> -		res = i5k_find_amb_registers(data, chipset_ids[i].err);
> +		res = i5k_find_amb_registers(data, &i5k_amb_ids[i]);
>  		if (res == 0)
>  			break;
>  		i++;
> -	} while (chipset_ids[i].err);
> +	} while (i5k_amb_ids[i].device);
>  
>  	if (res)
>  		goto err;
>  
>  	/* Copy the DIMM presence map for the first two channels */
> -	res = i5k_channel_probe(&data->amb_present[0], chipset_ids[i].fbd0);
> +	res = i5k_channel_probe(&data->amb_present[0], &i5k_amb_ids[i], 0);
>  	if (res)
>  		goto err;
>  
>  	/* Copy the DIMM presence map for the optional second two channels */
> -	i5k_channel_probe(&data->amb_present[2], chipset_ids[i].fbd0 + 1);
> +	i5k_channel_probe(&data->amb_present[2], &i5k_amb_ids[i], 1);
>  
>  	/* Set up resource regions */
>  	reso = request_mem_region(data->amb_base, data->amb_len, DRVNAME);
> -- 
> 1.9.1
> 

      reply	other threads:[~2019-06-06 16:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-06 15:00 drivers: hwmon: i5k_amb: simplify probing / device Enrico Weigelt, metux IT consult
2019-06-06 15:00 ` [PATCH] drivers: hwmon: i5k_amb: simplify probing / device identification Enrico Weigelt, metux IT consult
2019-06-06 16:33   ` Guenter Roeck [this message]

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=20190606163308.GA29829@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=info@metux.net \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®