From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
To: Kronos <kronos@kronoz.cjb.net>
Cc: Linux Kernel list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] VGA arbitration: draft of kernel side
Date: Wed, 09 Mar 2005 09:46:20 +1100 [thread overview]
Message-ID: <1110321980.13607.294.camel@gaston> (raw)
In-Reply-To: <20050308212909.GA18376@dreamland.darkstar.lan>
On Tue, 2005-03-08 at 22:29 +0100, Kronos wrote:
> > + bus = pdev->bus;
> > + while (bus) {
> > + bridge = bus->self;
> > + if (bridge) {
> > + pci_read_config_word(bridge, PCI_BRIDGE_CONTROL, &cmd);
> > + if (!(cmd & PCI_BRIDGE_CTL_VGA))
> > + continue;
>
> This seems wrong: if the condition is true the loop will restart with
> the same bus device and will never stop. I think you should do:
Yup. I always try to avoid nesting if's tho, which is why I wrote it
that way :) But yes, it should be fixed.
> > +
> > + /* Only deal with VGA class devices */
> > + if ((pdev->class >> 8) != PCI_CLASS_DISPLAY_VGA)
> > + return;
> > +
> > + /* Allocate structure */
> > + vgadev = kmalloc(sizeof(struct vga_device), GFP_KERNEL);
>
> Not checking return value of kmalloc, this is evil :P
> Also it may be worth to change return type in order to signal the error.
Yah, yah, I know :) will fix. I'm not sure there is point signaling the
error to the PCI layer. It won't do anything good with it.
> > +#endif
> > +
> > + /* Add to the list */
> > + list_add(&vgadev->list, &vga_list);
> > + spin_unlock_irqrestore(&vga_lock, flags);
>
> Missing return?
Yup.
> > + fail:
> > + spin_unlock_irqrestore(&vga_lock, flags);
> > + kfree(vgadev);
> > +}
> > +
> > +void vga_arbiter_del_pci_device(struct pci_dev *pdev)
> > +{
> > + struct vga_device *vgadev;
> > + unsigned long flags;
> > +
> > + spin_lock_irqsave(&vga_lock, flags);
> > + vgadev = vgadev_find(pdev);
> > + if (vgadev == NULL)
> > + goto bail;
> > + if (vgadev->locks)
> > + __vga_put(vgadev, vgadev->locks);
> > + list_del(&vgadev->list);
> > + bail:
> > + spin_unlock_irqrestore(&vga_lock, flags);
> > + if (vgadev)
> > + kfree(vgadev);
>
> kfree(NULL) is fine, no need to check for null pointer.
>
Hehe, yes, but I don't like it :)
Thanks. I spotted a few other issues (I was quite tired yesterday when I
finished this code). I'll do another pass on it today. One thing is: I
don't have x86 hardware, or at least, nothing where I can have 2 VGA
cards in (I may have access to an old laptop). So I'll need help &
testers at one point.
Ben.
next prev parent reply other threads:[~2005-03-08 22:51 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-03-08 7:11 [PATCH] VGA arbitration: draft of kernel side Benjamin Herrenschmidt
2005-03-08 21:29 ` Kronos
2005-03-08 22:46 ` Benjamin Herrenschmidt [this message]
2005-03-09 10:22 ` Pekka Enberg
2005-03-09 20:06 ` Kronos
2005-03-08 22:01 ` Benjamin Herrenschmidt
2005-03-08 23:47 ` Jon Smirl
2005-03-09 0:02 ` Benjamin Herrenschmidt
2005-03-09 3:17 ` Jon Smirl
2005-03-09 3:53 ` Benjamin Herrenschmidt
2005-03-09 4:35 ` Jon Smirl
2005-03-09 5:37 ` Benjamin Herrenschmidt
2005-03-09 5:58 ` Jon Smirl
2005-03-09 6:00 ` Benjamin Herrenschmidt
2005-03-09 8:04 ` Benjamin Herrenschmidt
2005-03-09 16:57 ` Jesse Barnes
2005-03-09 10:45 ` Pekka Enberg
2005-03-09 22:02 ` Benjamin Herrenschmidt
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=1110321980.13607.294.camel@gaston \
--to=benh@kernel.crashing.org \
--cc=kronos@kronoz.cjb.net \
--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