linux-acpi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Sitnicki <jsitnicki@gmail.com>
To: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: rafael.j.wysocki@intel.com, linux-acpi@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] PNP: Switch from __check_region() to __request_region()
Date: Mon, 22 Dec 2014 12:19:44 +0100	[thread overview]
Message-ID: <87vbl4lynj.fsf@frog.home> (raw)
In-Reply-To: <878uid5my1.fsf@frog.home>

On Fri, Dec 12, 2014 at 08:47 AM CET, Jakub Sitnicki wrote:
> Rafael J. Wysocki <rjw@rjwysocki.net> writes:
>
>> On Monday, December 08, 2014 10:01:57 PM Jakub Sitnicki wrote:
>>> diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
>>> index 782e822..f980ff7 100644
>>> --- a/drivers/pnp/resource.c
>>> +++ b/drivers/pnp/resource.c
>>> @@ -179,8 +179,9 @@ int pnp_check_port(struct pnp_dev *dev, struct resource *res)
>>>  	/* check if the resource is already in use, skip if the
>>>  	 * device is active because it itself may be in use */
>>>  	if (!dev->active) {
>>> -		if (__check_region(&ioport_resource, *port, length(port, end)))
>>> +		if (!request_region(*port, length(port, end), "pnp"))
>>>  			return 0;
>>> +		release_region(*port, length(port, end));
>>
>> Shouldn't we also release the resource returned by request_region() if it is
>> not NULL?
>>
>
> Thanks for taking a look at this. I think we're good here. If you please
> bear with me for a moment:
>
> release_resource() removes an element from the list of resource parent's
> children (and makes it an orphan):
>
> 	p = &old->parent->child;
> 	for (;;) {
> 		tmp = *p;
> 		if (!tmp)
> 			break;
> 		if (tmp == old) {
> 			*p = tmp->sibling;
> 			old->parent = NULL;
> 			return 0;
> 		}
> 		p = &tmp->sibling;
> 	}
>
> release_region() does the same but with additional checks, and also
> frees the resource:
>
> 	p = &parent->child;
>         /* ... */
> 	for (;;) {
> 		struct resource *res = *p;
>
> 		if (!res)
> 			break;
> 		if (res->start <= start && res->end >= end) {
>                         /* ... */
> 			*p = res->sibling;
>                         /* ... */
> 			free_resource(res);
> 			return;
> 		}
> 		p = &res->sibling;
> 	}
>
> When making the change I've based on other code in the kernel which also
> make use of request_region().
>
> To quote one example, drivers/net/ethernet/8390/ne2k-pci.c cleans up its
> I/O port region when initialization fails like so:
>
> static int ne2k_pci_init_one(struct pci_dev *pdev,
> 			     const struct pci_device_id *ent)
> {
>         /* ... */
>
> 	if (request_region (ioaddr, NE_IO_EXTENT, DRV_NAME) == NULL) {
> 		dev_err(&pdev->dev, "I/O resource 0x%x @ 0x%lx busy\n",
> 			NE_IO_EXTENT, ioaddr);
> 		return -EBUSY;
> 	}
>
>         /* ... */
>
> 	dev = alloc_ei_netdev();
> 	if (!dev) {
> 		dev_err(&pdev->dev, "cannot allocate ethernet device\n");
> 		goto err_out_free_res;
> 	}
>
>         /* ... */
>
> err_out_free_res:
> 	release_region (ioaddr, NE_IO_EXTENT);
> 	return -ENODEV;
> }

Just wondering, do you have any further thoughts on this?

Thanks,
Jakub

  reply	other threads:[~2014-12-22 11:19 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-08 21:01 [PATCH] PNP: Switch from __check_region() to __request_region() Jakub Sitnicki
2014-12-10 23:32 ` Rafael J. Wysocki
2014-12-12  7:47   ` Jakub Sitnicki
2014-12-22 11:19     ` Jakub Sitnicki [this message]
2014-12-22 22:34       ` Rafael J. Wysocki
2015-01-30  0:01         ` Rafael J. Wysocki
2015-02-18 20:51           ` Jakub Sitnicki
2015-02-19  1:04             ` Rafael J. Wysocki

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=87vbl4lynj.fsf@frog.home \
    --to=jsitnicki@gmail.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael.j.wysocki@intel.com \
    --cc=rjw@rjwysocki.net \
    /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;
as well as URLs for NNTP newsgroup(s).