lkml.org 
[lkml]   [2014]   [Jul]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    From
    SubjectRe: [PATCH v8 3/9] pci: Introduce pci_register_io_range() helper function.
    Date
    Some more detailed comments now

    On Tuesday 01 July 2014 19:43:28 Liviu Dudau wrote:
    > +/*
    > + * Record the PCI IO range (expressed as CPU physical address + size).
    > + * Return a negative value if an error has occured, zero otherwise
    > + */
    > +int __weak pci_register_io_range(phys_addr_t addr, resource_size_t size)
    > +{
    > +#ifdef PCI_IOBASE
    > + struct io_range *res;

    I was confused by the variable naming here: A variable named 'res' is
    normally a 'struct resource'. Maybe better call this 'range'.

    > + resource_size_t allocated_size = 0;
    > +
    > + /* check if the range hasn't been previously recorded */
    > + list_for_each_entry(res, &io_range_list, list) {
    > + if (addr >= res->start && addr + size <= res->start + size)
    > + return 0;
    > + allocated_size += res->size;
    > + }

    A spin_lock around the list lookup should be sufficient to get around
    the race that Will mentioned.

    > + /* range not registed yet, check for available space */
    > + if (allocated_size + size - 1 > IO_SPACE_LIMIT)
    > + return -E2BIG;

    It might be better to limit the size to 64K if it doesn't fit at first.


    Arnd


    \
     
     \ /
      Last update: 2014-07-02 15:21    [W:4.069 / U:0.856 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site