lkml.org 
[lkml]   [2012]   [Jul]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 1/6] drivers/pci/hotplug/cpci_hotplug_core.c: ensure a consistent return value in error case
    Date
    From: Julia Lawall <Julia.Lawall@lip6.fr>

    Typically, the return value desired for the failure of a function with an
    integer return value is a negative integer. In these cases, the return
    value is sometimes a negative integer and sometimes 0, due to a subsequent
    initialization of the return variable within the loop.

    A simplified version of the semantic match that finds this problem is:
    (http://coccinelle.lip6.fr/)

    //<smpl>
    @r exists@
    identifier ret;
    position p;
    constant C;
    expression e1,e3,e4;
    statement S;
    @@

    ret = -C
    ... when != ret = e3
    when any
    if@p (...) S
    ... when any
    if (\(ret != 0\|ret < 0\|ret > 0\) || ...) { ... return ...; }
    ... when != ret = e3
    when any
    *if@p (...)
    {
    ... when != ret = e4
    return ret;
    }
    //</smpl>

    Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

    ---
    drivers/pci/hotplug/cpci_hotplug_core.c | 14 ++++++++++----
    1 file changed, 10 insertions(+), 4 deletions(-)

    diff --git a/drivers/pci/hotplug/cpci_hotplug_core.c b/drivers/pci/hotplug/cpci_hotplug_core.c
    index 3fadf2f..2b4c412 100644
    --- a/drivers/pci/hotplug/cpci_hotplug_core.c
    +++ b/drivers/pci/hotplug/cpci_hotplug_core.c
    @@ -225,7 +225,7 @@ cpci_hp_register_bus(struct pci_bus *bus, u8 first, u8 last)
    struct hotplug_slot *hotplug_slot;
    struct hotplug_slot_info *info;
    char name[SLOT_NAME_SIZE];
    - int status = -ENOMEM;
    + int status;
    int i;

    if (!(controller && bus))
    @@ -237,18 +237,24 @@ cpci_hp_register_bus(struct pci_bus *bus, u8 first, u8 last)
    */
    for (i = first; i <= last; ++i) {
    slot = kzalloc(sizeof (struct slot), GFP_KERNEL);
    - if (!slot)
    + if (!slot) {
    + status = -ENOMEM;
    goto error;
    + }

    hotplug_slot =
    kzalloc(sizeof (struct hotplug_slot), GFP_KERNEL);
    - if (!hotplug_slot)
    + if (!hotplug_slot) {
    + status = -ENOMEM;
    goto error_slot;
    + }
    slot->hotplug_slot = hotplug_slot;

    info = kzalloc(sizeof (struct hotplug_slot_info), GFP_KERNEL);
    - if (!info)
    + if (!info) {
    + status = -ENOMEM;
    goto error_hpslot;
    + }
    hotplug_slot->info = info;

    slot->bus = bus;


    \
     
     \ /
      Last update: 2012-07-14 19:21    [W:2.551 / U:0.028 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site