lkml.org 
[lkml]   [2010]   [Aug]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    Subject[PATCH 3/4] regulator/wm831x-ldo: fix potential NULL dereference
    From
    Date
    pdata is dereferenced earlier than tested for being NULL.
    Thus move the dereference of "pdata" below the check for NULL.

    Signed-off-by: Axel Lin <axel.lin@gmail.com>
    ---
    drivers/regulator/wm831x-ldo.c | 27 ++++++++++++++++++---------
    1 files changed, 18 insertions(+), 9 deletions(-)

    diff --git a/drivers/regulator/wm831x-ldo.c b/drivers/regulator/wm831x-ldo.c
    index e686cdb..040515d 100644
    --- a/drivers/regulator/wm831x-ldo.c
    +++ b/drivers/regulator/wm831x-ldo.c
    @@ -303,14 +303,17 @@ static __devinit int wm831x_gp_ldo_probe(struct platform_device *pdev)
    {
    struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
    struct wm831x_pdata *pdata = wm831x->dev->platform_data;
    - int id = pdev->id % ARRAY_SIZE(pdata->ldo);
    struct wm831x_ldo *ldo;
    struct resource *res;
    - int ret, irq;
    + int id, ret, irq;

    + if (pdata == NULL)
    + return -ENODEV;
    +
    + id = pdev->id % ARRAY_SIZE(pdata->ldo);
    dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1);

    - if (pdata == NULL || pdata->ldo[id] == NULL)
    + if (pdata->ldo[id] == NULL)
    return -ENODEV;

    ldo = kzalloc(sizeof(struct wm831x_ldo), GFP_KERNEL);
    @@ -563,14 +566,17 @@ static __devinit int wm831x_aldo_probe(struct platform_device *pdev)
    {
    struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
    struct wm831x_pdata *pdata = wm831x->dev->platform_data;
    - int id = pdev->id % ARRAY_SIZE(pdata->ldo);
    struct wm831x_ldo *ldo;
    struct resource *res;
    - int ret, irq;
    + int id, ret, irq;
    +
    + if (pdata == NULL)
    + return -ENODEV;

    + id = pdev->id % ARRAY_SIZE(pdata->ldo);
    dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1);

    - if (pdata == NULL || pdata->ldo[id] == NULL)
    + if (pdata->ldo[id] == NULL)
    return -ENODEV;

    ldo = kzalloc(sizeof(struct wm831x_ldo), GFP_KERNEL);
    @@ -749,14 +755,17 @@ static __devinit int wm831x_alive_ldo_probe(struct platform_device *pdev)
    {
    struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
    struct wm831x_pdata *pdata = wm831x->dev->platform_data;
    - int id = pdev->id % ARRAY_SIZE(pdata->ldo);
    struct wm831x_ldo *ldo;
    struct resource *res;
    - int ret;
    + int id, ret;
    +
    + if (pdata == NULL)
    + return -ENODEV;

    + id = pdev->id % ARRAY_SIZE(pdata->ldo);
    dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1);

    - if (pdata == NULL || pdata->ldo[id] == NULL)
    + if (pdata->ldo[id] == NULL)
    return -ENODEV;

    ldo = kzalloc(sizeof(struct wm831x_ldo), GFP_KERNEL);
    --
    1.7.2




    \
     
     \ /
      Last update: 2010-08-20 04:01    [W:0.049 / U:59.704 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site