02 May, 2016

1 commit

  • My static checker complains that "ret" could be uninitialized at the
    end, which is true but it's more likely that it would be set to zero.

    Signed-off-by: Dan Carpenter
    Signed-off-by: Greg Kroah-Hartman

    Dan Carpenter
     

04 Oct, 2015

1 commit

  • Andy has reported a __might_sleep warning
    [ 5174.883617] WARNING: CPU: 0 PID: 1532 at
    /home/agrover/git/kernel/kernel/sched/core.c:7389 __might_sleep+0x7d/0x90()
    [ 5174.884407] do not call blocking ops when !TASK_RUNNING; state=1 set at [] uio_read+0x91/0x170 [uio]
    [ 5174.885198] Modules linked in: tcm_loop target_core_user uio target_core_pscsi target_core_file target_core_iblock iscsi_target_mod target_core_mod uinput fuse nfsv3 nfs_acl nfs lockd grace fscache sunrpc microcode i2c_piix4 virtio_balloon i2c_core xfs libcrc32c crc32c_intel virtio_net virtio_blk
    [ 5174.887351] CPU: 0 PID: 1532 Comm: tcmu-runner Not tainted 4.2.0-rc7+
    [ 5174.887853] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996),
    BIOS 1.8.1-20150318_183358- 04/01/2014
    [ 5174.888633] ffffffff81a3b870 ffff880045393ca8 ffffffff817afaae
    0000000000000000
    [ 5174.889224] ffff880045393cf8 ffff880045393ce8 ffffffff8109a846
    ffff880045393cd8
    [ 5174.889793] ffffffffa02a7150 00000000000002dc 0000000000000000
    ffff880045008000
    [ 5174.890375] Call Trace:
    [ 5174.890562] [] dump_stack+0x4c/0x65
    [ 5174.890938] [] warn_slowpath_common+0x86/0xc0
    [ 5174.891388] [] warn_slowpath_fmt+0x46/0x50
    [ 5174.891808] [] ? uio_read+0x91/0x170 [uio]
    [ 5174.892237] [] ? uio_read+0x91/0x170 [uio]
    [ 5174.892653] [] __might_sleep+0x7d/0x90
    [ 5174.893055] [] __might_fault+0x43/0xa0
    [ 5174.893448] [] ? schedule+0x3e/0x90
    [ 5174.893820] [] uio_read+0x132/0x170 [uio]
    [ 5174.894240] [] ? wake_up_q+0x70/0x70
    [ 5174.894620] [] __vfs_read+0x28/0xe0
    [ 5174.894993] [] ? security_file_permission+0xa3/0xc0
    [ 5174.895541] [] ? rw_verify_area+0x4f/0xf0
    [ 5174.896006] [] vfs_read+0x8a/0x140
    [ 5174.896391] [] ? __schedule+0x425/0xcc0
    [ 5174.896788] [] SyS_read+0x49/0xb0

    The warning is a false positive because uio_read doesn't depent on
    TASK_INTERRUPTIBLE after copy_to_user so it is safe to silence the
    warning by an explicit setting the state to TASK_RUNNING in the path
    which might call into TASK_RUNNING.

    Reported-by: Andy Grover
    Signed-off-by: Michal Hocko
    Signed-off-by: Greg Kroah-Hartman

    Michal Hocko
     

06 Aug, 2015

1 commit

  • Destroy uio_idr on module exit, reclaiming the allocated memory.

    This was detected by the following semantic patch (written by Luis Rodriguez
    )

    @ defines_module_init @
    declarer name module_init, module_exit;
    declarer name DEFINE_IDR;
    identifier init;
    @@

    module_init(init);

    @ defines_module_exit @
    identifier exit;
    @@

    module_exit(exit);

    @ declares_idr depends on defines_module_init && defines_module_exit @
    identifier idr;
    @@

    DEFINE_IDR(idr);

    @ on_exit_calls_destroy depends on declares_idr && defines_module_exit @
    identifier declares_idr.idr, defines_module_exit.exit;
    @@

    exit(void)
    {
    ...
    idr_destroy(&idr);
    ...
    }

    @ missing_module_idr_destroy depends on declares_idr && defines_module_exit && !on_exit_calls_destroy @
    identifier declares_idr.idr, defines_module_exit.exit;
    @@

    exit(void)
    {
    ...
    +idr_destroy(&idr);
    }

    Signed-off-by: Johannes Thumshirn
    Signed-off-by: Greg Kroah-Hartman

    Johannes Thumshirn
     

25 May, 2015

1 commit

  • UIO base driver should only free_irq that it has requested.
    UIO supports drivers without interrupts (irq == 0) or custom handlers.

    This fixes warnings like:

    WARNING: CPU: 1 PID: 5478 at kernel/irq/manage.c:1244 __free_irq+0xa9/0x1e0()
    Trying to free already-free IRQ 0

    Signed-off-by: Stephen Hemminger
    Signed-off-by: Greg Kroah-Hartman

    Stephen Hemminger
     

20 Mar, 2015

1 commit

  • Separate irq request/free from the device lifecycle.
    After device unregister the parent module can call pci_disable_msi.
    >From the PCI MSI how to:

    "Before calling this function, a device driver must always call free_irq()
    on any interrupt for which it previously called request_irq().
    Failure to do so results in a BUG_ON(), leaving the device with
    MSI enabled and thus leaking its vector."

    So we need to separately free the irq at unregister to allow the device
    to be kept around in the case of it still having open FDs.

    Signed-off-by: Brian Russell
    Signed-off-by: Greg Kroah-Hartman

    Brian Russell
     

08 Nov, 2014

1 commit


03 Oct, 2014

1 commit

  • In order to prevent a O(n) search of the filesystem to link up its uio
    node with its target configuration, TCMU needs to know the minor number
    that UIO assigned. Expose the definition of this struct so TCMU can
    access this field.

    Signed-off-by: Andy Grover
    Signed-off-by: Nicholas Bellinger

    Andy Grover
     

18 Jun, 2014

1 commit

  • This reverts commit ddb09754e6c7239e302c7b675df9bbd415f8de5d.

    Linus objected to this originally, I can see why it might be needed, but
    given that no one spoke up defending this patch, I'm going to revert it.

    If you have hardware that requires this change, please speak up in the
    future and defend the patch.

    Reported-by: Linus Torvalds
    Cc: Bin Wang
    Cc: Nobuhiro Iwamatsu
    Cc: Norbert Ciosek
    Cc: stable
    Signed-off-by: Greg Kroah-Hartman

    Greg Kroah-Hartman
     

28 May, 2014

1 commit

  • the vma range size is always page size aligned in mmap, while the
    real io space range may not be page aligned, thus leading to range
    check failure in the uio_mmap_physical().

    for example, in a case of io range size "mem->size == 1KB", and we
    have (vma->vm_end - vma->vm_start) == 4KB, due to "len" is aligned
    to page size in do_mmap_pgoff().

    now fix this issue by align mem->size to page size in the check.

    Signed-off-by: Bin Wang
    Signed-off-by: Nobuhiro Iwamatsu
    Cc: stable
    Signed-off-by: Greg Kroah-Hartman

    Bin Wang
     

21 Dec, 2013

1 commit

  • Commit e6789cd3dfb553077606ccafeb05e0043f072481 (uio: Simplify uio error
    path by using devres functions) converted uio to use devm_request_irq().
    This introduced a change in behaviour since the IRQ is associated with
    the parent device instead of the created UIO device. The IRQ will remain
    active after uio_unregister_device() is called, and some drivers will
    crash because of this. The patch fixes this.

    Signed-off-by: Aaro Koskinen
    Cc: stable # 3.13
    Signed-off-by: Greg Kroah-Hartman

    Aaro Koskinen
     

03 Dec, 2013

1 commit

  • In commit 7314e613d5ff ("Fix a few incorrectly checked
    [io_]remap_pfn_range() calls") the uio driver started more properly
    checking the passed-in user mapping arguments against the size of the
    actual uio driver data.

    That in turn exposed that some driver authors apparently didn't realize
    that mmap can only work on a page granularity, and had tried to use it
    with smaller mappings, with the new size check catching that out.

    So since it's not just the user mmap() arguments that can be confused,
    make the uio mmap code also verify that the uio driver has the memory
    allocated at page boundaries in order for mmap to work. If the device
    memory isn't properly aligned, we return

    [ENODEV]
    The fildes argument refers to a file whose type is not supported by mmap().

    as per the open group documentation on mmap.

    Reported-by: Holger Brunck
    Acked-by: Greg KH
    Signed-off-by: Linus Torvalds

    Linus Torvalds
     

07 Nov, 2013

1 commit

  • Pull char/misc patches from Greg KH:
    "Here's the big char/misc driver patchset for 3.13-rc1.

    Lots of stuff in here, including some new drivers for Intel's "MIC"
    co-processor devices, and a new eeprom driver. Other things include
    the driver attribute cleanups, extcon driver updates, hyperv updates,
    and a raft of other miscellaneous driver fixes.

    All of these have been in linux-next for a while"

    * tag 'char-misc-3.13-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc: (121 commits)
    misc: mic: Fixes for randconfig build errors and warnings.
    tifm: fix error return code in tifm_7xx1_probe()
    w1-gpio: Use devm_* functions
    w1-gpio: Detect of_gpio_error for first gpio
    uio: Pass pointers to virt_to_page(), not integers
    uio: fix memory leak
    misc/at24: avoid infinite loop on write()
    misc/93xx46: avoid infinite loop on write()
    misc: atmel_pwm: add deferred-probing support
    mei: wd: host_init propagate error codes from called functions
    mei: replace stray pr_debug with dev_dbg
    mei: bus: propagate error code returned by mei_me_cl_by_id
    mei: mei_cl_link remove duplicated check for open_handle_count
    mei: print correct device state during unexpected reset
    mei: nfc: fix memory leak in error path
    lkdtm: add tests for additional page permissions
    lkdtm: adjust recursion size to avoid warnings
    lkdtm: isolate stack corruption test
    mei: move host_clients_map cleanup to device init
    mei: me: downgrade two errors to debug level
    ...

    Linus Torvalds
     

30 Oct, 2013

3 commits

  • Most architectures define virt_to_page() as a macro that casts its
    argument such that an argument of type unsigned long will be accepted
    without complaint. However, the proper type is void *, and passing
    unsigned long results in a warning on MIPS.

    Compile-tested only.

    Signed-off-by: Ben Hutchings
    Signed-off-by: Greg Kroah-Hartman

    Ben Hutchings
     
  • we have to call kobject_put() to clean up the kobject after function
    kobject_init(), kobject_add(), or kobject_uevent() is called.

    Signed-off-by: Cong Ding
    Acked-by: Sebastian Andrzej Siewior
    Signed-off-by: Greg Kroah-Hartman

    Cong Ding
     
  • Nico Golde reports a few straggling uses of [io_]remap_pfn_range() that
    really should use the vm_iomap_memory() helper. This trivially converts
    two of them to the helper, and comments about why the third one really
    needs to continue to use remap_pfn_range(), and adds the missing size
    check.

    Reported-by: Nico Golde
    Cc: stable@kernel.org
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org.

    Linus Torvalds
     

26 Sep, 2013

1 commit


04 Sep, 2013

1 commit

  • Pull driver core patches from Greg KH:
    "Here's the big driver core pull request for 3.12-rc1.

    Lots of tiny changes here fixing up the way sysfs attributes are
    created, to try to make drivers simpler, and fix a whole class race
    conditions with creations of device attributes after the device was
    announced to userspace.

    All the various pieces are acked by the different subsystem
    maintainers"

    * tag 'driver-core-3.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core: (119 commits)
    firmware loader: fix pending_fw_head list corruption
    drivers/base/memory.c: introduce help macro to_memory_block
    dynamic debug: line queries failing due to uninitialized local variable
    sysfs: sysfs_create_groups returns a value.
    debugfs: provide debugfs_create_x64() when disabled
    rbd: convert bus code to use bus_groups
    firmware: dcdbas: use binary attribute groups
    sysfs: add sysfs_create/remove_groups for when SYSFS is not enabled
    driver core: add #include to core files.
    HID: convert bus code to use dev_groups
    Input: serio: convert bus code to use drv_groups
    Input: gameport: convert bus code to use drv_groups
    driver core: firmware: use __ATTR_RW()
    driver core: core: use DEVICE_ATTR_RO
    driver core: bus: use DRIVER_ATTR_WO()
    driver core: create write-only attribute macros for devices and drivers
    sysfs: create __ATTR_WO()
    driver-core: platform: convert bus code to use dev_groups
    workqueue: convert bus code to use dev_groups
    MEI: convert bus code to use dev_groups
    ...

    Linus Torvalds
     

13 Aug, 2013

2 commits


25 Jul, 2013

1 commit


04 Jul, 2013

1 commit


30 Mar, 2013

1 commit

  • Until recently uio_get_minor() returned 0 for success and
    a negative value on failure. This became non-negative for suceess and
    negative for failure. Restore the original return value spec so that we can
    successfully initialize UIO devices with a non-zero minor device
    number.

    Cc: "Hans J. Koch"
    Signed-off-by: Damian Hobson-Garcia
    Signed-off-by: Greg Kroah-Hartman

    Damian Hobson-Garcia
     

28 Feb, 2013

1 commit


09 Oct, 2012

1 commit

  • A long time ago, in v2.4, VM_RESERVED kept swapout process off VMA,
    currently it lost original meaning but still has some effects:

    | effect | alternative flags
    -+------------------------+---------------------------------------------
    1| account as reserved_vm | VM_IO
    2| skip in core dump | VM_IO, VM_DONTDUMP
    3| do not merge or expand | VM_IO, VM_DONTEXPAND, VM_HUGETLB, VM_PFNMAP
    4| do not mlock | VM_IO, VM_DONTEXPAND, VM_HUGETLB, VM_PFNMAP

    This patch removes reserved_vm counter from mm_struct. Seems like nobody
    cares about it, it does not exported into userspace directly, it only
    reduces total_vm showed in proc.

    Thus VM_RESERVED can be replaced with VM_IO or pair VM_DONTEXPAND | VM_DONTDUMP.

    remap_pfn_range() and io_remap_pfn_range() set VM_IO|VM_DONTEXPAND|VM_DONTDUMP.
    remap_vmalloc_range() set VM_DONTEXPAND | VM_DONTDUMP.

    [akpm@linux-foundation.org: drivers/vfio/pci/vfio_pci.c fixup]
    Signed-off-by: Konstantin Khlebnikov
    Cc: Alexander Viro
    Cc: Carsten Otte
    Cc: Chris Metcalf
    Cc: Cyrill Gorcunov
    Cc: Eric Paris
    Cc: H. Peter Anvin
    Cc: Hugh Dickins
    Cc: Ingo Molnar
    Cc: James Morris
    Cc: Jason Baron
    Cc: Kentaro Takeda
    Cc: Matt Helsley
    Cc: Nick Piggin
    Cc: Oleg Nesterov
    Cc: Peter Zijlstra
    Cc: Robert Richter
    Cc: Suresh Siddha
    Cc: Tetsuo Handa
    Cc: Venkatesh Pallipadi
    Acked-by: Linus Torvalds
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Konstantin Khlebnikov
     

19 Oct, 2011

1 commit

  • To support >32-bit physical addresses for UIO_MEM_PHYS type we need to
    extend the width of 'addr' in struct uio_mem. Numerous platforms like
    embedded PPC, ARM, and X86 have support for systems with larger physical
    address than logical.

    Since 'addr' may contain a physical, logical, or virtual address the
    easiest solution is to just change the type to 'phys_addr_t' which
    should always be greater than or equal to the sizeof(void *) such that
    it can properly hold any of the address types.

    For physical address we can support up to a 44-bit physical address on a
    typical 32-bit system as we utilize remap_pfn_range() for the mapping of
    the memory region and pfn's are represnted by shifting the address by
    the page size (typically 4k).

    Signed-off-by: Kai Jiang
    Signed-off-by: Minghuan Lian
    Signed-off-by: Kumar Gala
    Signed-off-by: Hans J. Koch
    Signed-off-by: Greg Kroah-Hartman

    Kai Jiang
     

23 Aug, 2011

1 commit


20 Apr, 2011

2 commits

  • The number of uio devices that could be used should be less than
    UIO_MAX_DEVICES by design, and this work guards any cases in which id
    more than UIO_MAX_DEVICES is utilized.

    Signed-off-by: Hillf Danton
    Signed-off-by: Hans J. Koch
    Signed-off-by: Greg Kroah-Hartman

    Hillf Danton
     
  • When finding mm index for vma it looks more flexible that the mm could
    be sparse, and both the size of mm and the pgoff of vma could give
    correct selection.

    Signed-off-by: Hillf Danton
    Signed-off-by: Hans J. Koch
    Signed-off-by: Greg Kroah-Hartman

    Hillf Danton
     

11 Nov, 2010

1 commit


23 Oct, 2010

6 commits

  • * git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core-2.6: (31 commits)
    driver core: Display error codes when class suspend fails
    Driver core: Add section count to memory_block struct
    Driver core: Add mutex for adding/removing memory blocks
    Driver core: Move find_memory_block routine
    hpilo: Despecificate driver from iLO generation
    driver core: Convert link_mem_sections to use find_memory_block_hinted.
    driver core: Introduce find_memory_block_hinted which utilizes kset_find_obj_hinted.
    kobject: Introduce kset_find_obj_hinted.
    driver core: fix build for CONFIG_BLOCK not enabled
    driver-core: base: change to new flag variable
    sysfs: only access bin file vm_ops with the active lock
    sysfs: Fail bin file mmap if vma close is implemented.
    FW_LOADER: fix kconfig dependency warning on HOTPLUG
    uio: Statically allocate uio_class and use class .dev_attrs.
    uio: Support 2^MINOR_BITS minors
    uio: Cleanup irq handling.
    uio: Don't clear driver data
    uio: Fix lack of locking in init_uio_class
    SYSFS: Allow boot time switching between deprecated and modern sysfs layout
    driver core: remove CONFIG_SYSFS_DEPRECATED_V2 but keep it for block devices
    ...

    Linus Torvalds
     
  • Instead of adding uio class attributes manually after the uio device has
    been created and we have sent a uevent to userspace, use the class
    attribute mechanism. This removes races and makes the code simpler.

    At the same time don't bother to dynamically allocate a struct class for
    uio, just declare one statically. Less code is needed and it is easier
    to set the class parameters.tune the class

    Signed-off-by: Eric W. Biederman
    Reviewed-by: Thomas Gleixner
    Signed-off-by: Hans J. Koch
    Signed-off-by: Greg Kroah-Hartman

    Eric W. Biederman
     
  • register_chrdev limits uio devices to 256 minor numbers which causes
    problems on one system I have with 384+ uio devices. So instead set
    UIO_MAX_DEVICES to the maximum number of minors and use
    alloc_chrdev_region to reserve the uio minors.

    The final result is that the code works the same but the uio driver now
    supports any minor the idr allocator comes up with.

    Signed-off-by: Eric W. Biederman
    Reviewed-by: Thomas Gleixner
    Signed-off-by: Hans J. Koch
    Signed-off-by: Greg Kroah-Hartman

    Eric W. Biederman
     
  • Change the value of UIO_IRQ_NONE -2 to 0. 0 is well defined in the rest
    of the kernel as the value to indicate an irq has not been assigned.

    Update the calls to request_irq and free_irq to only ignore UIO_IRQ_NONE
    and UIO_IRQ_CUSTOM allowing the rest of the kernel's possible irq
    numbers to be used.

    Signed-off-by: Eric W. Biederman
    Reviewed-by: Thomas Gleixner
    Signed-off-by: Hans J. Koch
    Signed-off-by: Greg Kroah-Hartman

    Eric W. Biederman
     
  • Currently uio sets it's driver data to NULL just as it is unregistering
    attributes. sysfs maks the guaranatee that it will not call attributes
    after device_destroy is called so this is unncessary and leads to lots
    of unnecessary code in uio.c

    Signed-off-by: Eric W. Biederman
    Reviewed-by: Thomas Gleixner
    Signed-off-by: Hans J. Koch
    Signed-off-by: Greg Kroah-Hartman

    Eric W. Biederman
     
  • There is no locking in init_uio_class so multiple
    drivers can race and create multiple uio classes.

    Fix this by simplifying the code. In particular always
    register the uio class during module_init and make things
    simpler.

    Signed-off-by: Eric W. Biederman
    Reviewed-by: Thomas Gleixner
    Signed-off-by: Hans J. Koch
    Signed-off-by: Greg Kroah-Hartman

    Eric W. Biederman
     

15 Oct, 2010

1 commit

  • All file_operations should get a .llseek operation so we can make
    nonseekable_open the default for future file operations without a
    .llseek pointer.

    The three cases that we can automatically detect are no_llseek, seq_lseek
    and default_llseek. For cases where we can we can automatically prove that
    the file offset is always ignored, we use noop_llseek, which maintains
    the current behavior of not returning an error from a seek.

    New drivers should normally not use noop_llseek but instead use no_llseek
    and call nonseekable_open at open time. Existing drivers can be converted
    to do the same when the maintainer knows for certain that no user code
    relies on calling seek on the device file.

    The generated code is often incorrectly indented and right now contains
    comments that clarify for each added line why a specific variant was
    chosen. In the version that gets submitted upstream, the comments will
    be gone and I will manually fix the indentation, because there does not
    seem to be a way to do that using coccinelle.

    Some amount of new code is currently sitting in linux-next that should get
    the same modifications, which I will do at the end of the merge window.

    Many thanks to Julia Lawall for helping me learn to write a semantic
    patch that does all this.

    ===== begin semantic patch =====
    // This adds an llseek= method to all file operations,
    // as a preparation for making no_llseek the default.
    //
    // The rules are
    // - use no_llseek explicitly if we do nonseekable_open
    // - use seq_lseek for sequential files
    // - use default_llseek if we know we access f_pos
    // - use noop_llseek if we know we don't access f_pos,
    // but we still want to allow users to call lseek
    //
    @ open1 exists @
    identifier nested_open;
    @@
    nested_open(...)
    {

    }

    @ open exists@
    identifier open_f;
    identifier i, f;
    identifier open1.nested_open;
    @@
    int open_f(struct inode *i, struct file *f)
    {

    }

    @ read disable optional_qualifier exists @
    identifier read_f;
    identifier f, p, s, off;
    type ssize_t, size_t, loff_t;
    expression E;
    identifier func;
    @@
    ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
    {

    }

    @ read_no_fpos disable optional_qualifier exists @
    identifier read_f;
    identifier f, p, s, off;
    type ssize_t, size_t, loff_t;
    @@
    ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
    {
    ... when != off
    }

    @ write @
    identifier write_f;
    identifier f, p, s, off;
    type ssize_t, size_t, loff_t;
    expression E;
    identifier func;
    @@
    ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
    {

    }

    @ write_no_fpos @
    identifier write_f;
    identifier f, p, s, off;
    type ssize_t, size_t, loff_t;
    @@
    ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
    {
    ... when != off
    }

    @ fops0 @
    identifier fops;
    @@
    struct file_operations fops = {
    ...
    };

    @ has_llseek depends on fops0 @
    identifier fops0.fops;
    identifier llseek_f;
    @@
    struct file_operations fops = {
    ...
    .llseek = llseek_f,
    ...
    };

    @ has_read depends on fops0 @
    identifier fops0.fops;
    identifier read_f;
    @@
    struct file_operations fops = {
    ...
    .read = read_f,
    ...
    };

    @ has_write depends on fops0 @
    identifier fops0.fops;
    identifier write_f;
    @@
    struct file_operations fops = {
    ...
    .write = write_f,
    ...
    };

    @ has_open depends on fops0 @
    identifier fops0.fops;
    identifier open_f;
    @@
    struct file_operations fops = {
    ...
    .open = open_f,
    ...
    };

    // use no_llseek if we call nonseekable_open
    ////////////////////////////////////////////
    @ nonseekable1 depends on !has_llseek && has_open @
    identifier fops0.fops;
    identifier nso ~= "nonseekable_open";
    @@
    struct file_operations fops = {
    ... .open = nso, ...
    +.llseek = no_llseek, /* nonseekable */
    };

    @ nonseekable2 depends on !has_llseek @
    identifier fops0.fops;
    identifier open.open_f;
    @@
    struct file_operations fops = {
    ... .open = open_f, ...
    +.llseek = no_llseek, /* open uses nonseekable */
    };

    // use seq_lseek for sequential files
    /////////////////////////////////////
    @ seq depends on !has_llseek @
    identifier fops0.fops;
    identifier sr ~= "seq_read";
    @@
    struct file_operations fops = {
    ... .read = sr, ...
    +.llseek = seq_lseek, /* we have seq_read */
    };

    // use default_llseek if there is a readdir
    ///////////////////////////////////////////
    @ fops1 depends on !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
    identifier fops0.fops;
    identifier readdir_e;
    @@
    // any other fop is used that changes pos
    struct file_operations fops = {
    ... .readdir = readdir_e, ...
    +.llseek = default_llseek, /* readdir is present */
    };

    // use default_llseek if at least one of read/write touches f_pos
    /////////////////////////////////////////////////////////////////
    @ fops2 depends on !fops1 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
    identifier fops0.fops;
    identifier read.read_f;
    @@
    // read fops use offset
    struct file_operations fops = {
    ... .read = read_f, ...
    +.llseek = default_llseek, /* read accesses f_pos */
    };

    @ fops3 depends on !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
    identifier fops0.fops;
    identifier write.write_f;
    @@
    // write fops use offset
    struct file_operations fops = {
    ... .write = write_f, ...
    + .llseek = default_llseek, /* write accesses f_pos */
    };

    // Use noop_llseek if neither read nor write accesses f_pos
    ///////////////////////////////////////////////////////////

    @ fops4 depends on !fops1 && !fops2 && !fops3 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
    identifier fops0.fops;
    identifier read_no_fpos.read_f;
    identifier write_no_fpos.write_f;
    @@
    // write fops use offset
    struct file_operations fops = {
    ...
    .write = write_f,
    .read = read_f,
    ...
    +.llseek = noop_llseek, /* read and write both use no f_pos */
    };

    @ depends on has_write && !has_read && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
    identifier fops0.fops;
    identifier write_no_fpos.write_f;
    @@
    struct file_operations fops = {
    ... .write = write_f, ...
    +.llseek = noop_llseek, /* write uses no f_pos */
    };

    @ depends on has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
    identifier fops0.fops;
    identifier read_no_fpos.read_f;
    @@
    struct file_operations fops = {
    ... .read = read_f, ...
    +.llseek = noop_llseek, /* read uses no f_pos */
    };

    @ depends on !has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
    identifier fops0.fops;
    @@
    struct file_operations fops = {
    ...
    +.llseek = noop_llseek, /* no read or write fn */
    };
    ===== End semantic patch =====

    Signed-off-by: Arnd Bergmann
    Cc: Julia Lawall
    Cc: Christoph Hellwig

    Arnd Bergmann
     

30 Mar, 2010

1 commit

  • …it slab.h inclusion from percpu.h

    percpu.h is included by sched.h and module.h and thus ends up being
    included when building most .c files. percpu.h includes slab.h which
    in turn includes gfp.h making everything defined by the two files
    universally available and complicating inclusion dependencies.

    percpu.h -> slab.h dependency is about to be removed. Prepare for
    this change by updating users of gfp and slab facilities include those
    headers directly instead of assuming availability. As this conversion
    needs to touch large number of source files, the following script is
    used as the basis of conversion.

    http://userweb.kernel.org/~tj/misc/slabh-sweep.py

    The script does the followings.

    * Scan files for gfp and slab usages and update includes such that
    only the necessary includes are there. ie. if only gfp is used,
    gfp.h, if slab is used, slab.h.

    * When the script inserts a new include, it looks at the include
    blocks and try to put the new include such that its order conforms
    to its surrounding. It's put in the include block which contains
    core kernel includes, in the same order that the rest are ordered -
    alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
    doesn't seem to be any matching order.

    * If the script can't find a place to put a new include (mostly
    because the file doesn't have fitting include block), it prints out
    an error message indicating which .h file needs to be added to the
    file.

    The conversion was done in the following steps.

    1. The initial automatic conversion of all .c files updated slightly
    over 4000 files, deleting around 700 includes and adding ~480 gfp.h
    and ~3000 slab.h inclusions. The script emitted errors for ~400
    files.

    2. Each error was manually checked. Some didn't need the inclusion,
    some needed manual addition while adding it to implementation .h or
    embedding .c file was more appropriate for others. This step added
    inclusions to around 150 files.

    3. The script was run again and the output was compared to the edits
    from #2 to make sure no file was left behind.

    4. Several build tests were done and a couple of problems were fixed.
    e.g. lib/decompress_*.c used malloc/free() wrappers around slab
    APIs requiring slab.h to be added manually.

    5. The script was run on all .h files but without automatically
    editing them as sprinkling gfp.h and slab.h inclusions around .h
    files could easily lead to inclusion dependency hell. Most gfp.h
    inclusion directives were ignored as stuff from gfp.h was usually
    wildly available and often used in preprocessor macros. Each
    slab.h inclusion directive was examined and added manually as
    necessary.

    6. percpu.h was updated not to include slab.h.

    7. Build test were done on the following configurations and failures
    were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
    distributed build env didn't work with gcov compiles) and a few
    more options had to be turned off depending on archs to make things
    build (like ipr on powerpc/64 which failed due to missing writeq).

    * x86 and x86_64 UP and SMP allmodconfig and a custom test config.
    * powerpc and powerpc64 SMP allmodconfig
    * sparc and sparc64 SMP allmodconfig
    * ia64 SMP allmodconfig
    * s390 SMP allmodconfig
    * alpha SMP allmodconfig
    * um on x86_64 SMP allmodconfig

    8. percpu.h modifications were reverted so that it could be applied as
    a separate patch and serve as bisection point.

    Given the fact that I had only a couple of failures from tests on step
    6, I'm fairly confident about the coverage of this conversion patch.
    If there is a breakage, it's likely to be something in one of the arch
    headers which should be easily discoverable easily on most builds of
    the specific arch.

    Signed-off-by: Tejun Heo <tj@kernel.org>
    Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>

    Tejun Heo
     

08 Mar, 2010

1 commit

  • Constify struct sysfs_ops.

    This is part of the ops structure constification
    effort started by Arjan van de Ven et al.

    Benefits of this constification:

    * prevents modification of data that is shared
    (referenced) by many other structure instances
    at runtime

    * detects/prevents accidental (but not intentional)
    modification attempts on archs that enforce
    read-only kernel data at runtime

    * potentially better optimized code as the compiler
    can assume that the const data cannot be changed

    * the compiler/linker move const data into .rodata
    and therefore exclude them from false sharing

    Signed-off-by: Emese Revfy
    Acked-by: David Teigland
    Acked-by: Matt Domsch
    Acked-by: Maciej Sosnowski
    Acked-by: Hans J. Koch
    Acked-by: Pekka Enberg
    Acked-by: Jens Axboe
    Acked-by: Stephen Hemminger
    Signed-off-by: Greg Kroah-Hartman

    Emese Revfy
     

12 Oct, 2009

1 commit


28 Sep, 2009

1 commit