mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sergey Shtylyov <s.shtylyov@omp.ru>
To: Philipp Stanner <pstanner@redhat.com>,
	Damien Le Moal <dlemoal@kernel.org>,
	Niklas Cassel <cassel@kernel.org>,
	Mikael Pettersson <mikpelinux@gmail.com>
Cc: <linux-ide@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] ata: Replace deprecated PCI devres functions
Date: Wed, 21 Aug 2024 23:49:49 +0300	[thread overview]
Message-ID: <c4111bbb-b59c-be35-561b-4eb79809918d@omp.ru> (raw)
In-Reply-To: <94a378e6c2d442e0e7ae06fbd496d02983f9baaa.camel@redhat.com>

On 8/16/24 10:47 AM, Philipp Stanner wrote:
[...]

>>> The ata subsystem uses the PCI devres functions pcim_iomap_table()
>>> and
>>> pcim_request_regions(), which have been deprecated in commit
>>> e354bb84a4c1
>>> ("PCI: Deprecate pcim_iomap_table(),
>>> pcim_iomap_regions_request_all()").
>>>
>>> These functions internally already use their successors, notably
>>> pcim_request_region(), so they are quite trivial to replace.
>>>
>>> However, one thing special about ata is that it stores the iomap
>>> table
>>> provided by pcim_iomap_table() in struct ata_host. This can be
>>> replaced
>>> with a __iomem pointer table, statically allocated with size
>>> PCI_STD_NUM_BARS so it can house the maximum number of PCI BARs.
>>> The
>>> only further modification then necessary is to explicitly fill that
>>> table, whereas before it was filled implicitly by
>>> pcim_request_regions().
>>>
>>> Modify the iomap table in struct ata_host.
>>>
>>> Replace all calls to pcim_request_region() with ones to
>>> pcim_request_region().

[...]

>>> diff --git a/drivers/ata/libata-sff.c b/drivers/ata/libata-sff.c
>>> index 250f7dae05fd..d58db8226436 100644
>>> --- a/drivers/ata/libata-sff.c
>>> +++ b/drivers/ata/libata-sff.c
>> [...]
>>> @@ -2172,8 +2173,41 @@ int ata_pci_sff_init_host(struct ata_host
>>> *host)
>>>  			continue;
>>>  		}
>>>  
>>> -		rc = pcim_iomap_regions(pdev, 0x3 << base,
>>> -					dev_driver_string(gdev));
>>> +		/*
>>> +		 * In a first loop run, we want to get BARs 0 and
>>> 1.
>>> +		 * In a second run, we want BARs 2 and 3.
>>> +		 */
>>> +		if (i == 0) {
>>> +			io_tmp = pcim_iomap_region(pdev, 0,
>>> drv_name);
>>> +			if (IS_ERR(io_tmp)) {
>>> +				rc = PTR_ERR(io_tmp);
>>> +				goto err;
>>> +			}
>>> +			host->iomap[0] = io_tmp;
>>> +
>>> +			io_tmp = pcim_iomap_region(pdev, 1,
>>> drv_name);
>>> +			if (IS_ERR(io_tmp)) {
>>> +				rc = PTR_ERR(io_tmp);
>>> +				goto err;
>>> +			}
>>> +			host->iomap[1] = io_tmp;
>>> +		} else {
>>> +			io_tmp = pcim_iomap_region(pdev, 2,
>>> drv_name);
>>> +			if (IS_ERR(io_tmp)) {
>>> +				rc = PTR_ERR(io_tmp);
>>> +				goto err;
>>> +			}
>>> +			host->iomap[2] = io_tmp;
>>> +
>>> +			io_tmp = pcim_iomap_region(pdev, 3,
>>> drv_name);
>>> +			if (IS_ERR(io_tmp)) {
>>> +				rc = PTR_ERR(io_tmp);
>>> +				goto err;
>>> +			}
>>> +			host->iomap[3] = io_tmp;
>>> +		}
>>> +
>>
>>    Ugh... Why you couldn't keep using base (or just i * 2) and avoid
>> such code duplication?
> 
> I mean, this would at least make it perfectly readable what's being
> done.

   It looks pretty horrible, to my taste... :-)

> I guess we could do something like this, maybe with a comment explining
> what is going on:
> 
> for_each_set_bit(j, 0x3 << base, PCI_STD_NUM_BARS) {

   We're only interested in 4 first BARs, not all 6 of 'em. :-)
And you can't just pass 3 << base to for_each_set_bit() -- it needs
a bitmap ptr... :-)
   Why not just do s/th like:

for (j = base, j < base + 2, j++) {

> 	host->iomap[j] = pcim_iomap_region(pdev, j, drv_name);
> 	if (IS_ERR(host->iomap[j])) {
> 		rc = PTR_ERR(host->iomap[j]);
> 		break;
> 	}
> }
> 
> if (rc) {
> 	dev_warn(gdev,

[...]

MBR, Sergey

  reply	other threads:[~2024-08-21 20:49 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-12  8:48 Philipp Stanner
2024-08-14 17:32 ` Sergey Shtylyov
2024-08-16  7:47   ` Philipp Stanner
2024-08-21 20:49     ` Sergey Shtylyov [this message]
2024-08-16  8:37   ` Philipp Stanner
2024-08-20 21:33     ` Sergey Shtylyov

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=c4111bbb-b59c-be35-561b-4eb79809918d@omp.ru \
    --to=s.shtylyov@omp.ru \
    --cc=cassel@kernel.org \
    --cc=dlemoal@kernel.org \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mikpelinux@gmail.com \
    --cc=pstanner@redhat.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

all inboxes | Powered by JetHome®