Re: Possible broken MM code in dell-laptop.c?

From: Darren Hart
Date: Tue Jun 16 2015 - 23:43:57 EST


On Tue, Jun 16, 2015 at 09:15:23AM +0200, Pali Rohár wrote:
> On Tuesday 16 June 2015 08:33:46 Michal Hocko wrote:
> > On Mon 15-06-15 23:27:59, Pali Rohár wrote:
> > > On Monday 15 June 2015 23:18:16 Michal Hocko wrote:
> > > > On Sun 14-06-15 11:05:07, Pali Rohár wrote:
> > > > > Hello,
> > > > >
> > > > > in drivers/platform/x86/dell-laptop.c is this part of code:
> > > > >
> > > > > static int __init dell_init(void)
> > > > > {
> > > > > ...
> > > > >
> > > > > /*
> > > > >
> > > > > * Allocate buffer below 4GB for SMI data--only 32-bit physical
> > > > > addr * is passed to SMI handler.
> > > > > */
> > > > >
> > > > > bufferpage = alloc_page(GFP_KERNEL | GFP_DMA32);
> > > >
> > > > [...]
> > > >
> > > > > buffer = page_address(bufferpage);
> > > >
> > > > [...]
> > > >
> > > > > fail_rfkill:
> > > > > free_page((unsigned long)bufferpage);
> > > >
> > > > This one should be __free_page because it consumes struct page* and
> > > > it is the proper counter part for alloc_page. free_page, just to
> > > > make it confusing, consumes an address which has to be translated to
> > > > a struct page.
> > > >
> > > > I have no idea why the API has been done this way and yeah, it is
> > > > really confusing.
> > > >
> > > > [...]
> > > >
> > > > > static void __exit dell_exit(void)
> > > > > {
> > > > > ...
> > > > >
> > > > > free_page((unsigned long)buffer);
> > >
> > > So both, either:
> > >
> > > free_page((unsigned long)buffer);
> > >
> > > or
> > >
> > > __free_page(bufferpage);
> > >
> > > is correct?
> >
> > Yes. Although I would use __free_page variant as both seem to be
> > globally visible.
> >

Michal - thanks for the context.

I'm surprised by your recommendation to use __free_page() out here in platform
driver land.

I'd also prefer that the driver consistently free the same address to avoid
confusion.

For these reasons, free_page((unsigned long)buffer) seems like the better
option.

Can you elaborate on why you feel __free_page() is a better choice?

--
Darren Hart
Intel Open Source Technology Center
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/