i2c: mux: reg: put away the parent i2c adapter on probe failure
authorPeter Rosin <peda@axentia.se>
Sun, 7 May 2017 05:16:30 +0000 (07:16 +0200)
committerPeter Rosin <peda@axentia.se>
Mon, 15 May 2017 16:44:58 +0000 (18:44 +0200)
It is only prudent to let go of resources that are not used.

Fixes: b3fdd32799d8 ("i2c: mux: Add register-based mux i2c-mux-reg")
Signed-off-by: Peter Rosin <peda@axentia.se>
drivers/i2c/muxes/i2c-mux-reg.c

index 406d5059072cbe41964105d752a42236e66f7c8d..11974e3cd1e5522e5ed537f56abee0d0aa9be463 100644 (file)
@@ -196,20 +196,25 @@ static int i2c_mux_reg_probe(struct platform_device *pdev)
                res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
                mux->data.reg_size = resource_size(res);
                mux->data.reg = devm_ioremap_resource(&pdev->dev, res);
-               if (IS_ERR(mux->data.reg))
-                       return PTR_ERR(mux->data.reg);
+               if (IS_ERR(mux->data.reg)) {
+                       ret = PTR_ERR(mux->data.reg);
+                       goto err_put_parent;
+               }
        }
 
        if (mux->data.reg_size != 4 && mux->data.reg_size != 2 &&
            mux->data.reg_size != 1) {
                dev_err(&pdev->dev, "Invalid register size\n");
-               return -EINVAL;
+               ret = -EINVAL;
+               goto err_put_parent;
        }
 
        muxc = i2c_mux_alloc(parent, &pdev->dev, mux->data.n_values, 0, 0,
                             i2c_mux_reg_select, NULL);
-       if (!muxc)
-               return -ENOMEM;
+       if (!muxc) {
+               ret = -ENOMEM;
+               goto err_put_parent;
+       }
        muxc->priv = mux;
 
        platform_set_drvdata(pdev, muxc);
@@ -233,6 +238,8 @@ static int i2c_mux_reg_probe(struct platform_device *pdev)
 
 add_adapter_failed:
        i2c_mux_del_adapters(muxc);
+err_put_parent:
+       i2c_put_adapter(parent);
 
        return ret;
 }