rpmsg: glink: use put_device() if device_register fail
authorArvind Yadav <arvind.yadav.cs@gmail.com>
Tue, 21 Apr 2020 12:40:06 +0000 (13:40 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 24 Apr 2020 06:01:04 +0000 (08:01 +0200)
[ Upstream commit a9011726c4bb37e5d6a7279bf47fcc19cd9d3e1a ]

if device_register() returned an error! Always use put_device()
to give up the reference initialized. And unregister device for
other return error.

Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/rpmsg/qcom_glink_smem.c

index 2b54e71886d9c17d9c254c2c05a1d48d96553aa4..69a14041ef1fecc26d15c3537ab6ca98e59096ab 100644 (file)
@@ -212,6 +212,7 @@ struct qcom_glink *qcom_glink_smem_register(struct device *parent,
        ret = device_register(dev);
        if (ret) {
                pr_err("failed to register glink edge\n");
+               put_device(dev);
                return ERR_PTR(ret);
        }
 
@@ -294,7 +295,7 @@ struct qcom_glink *qcom_glink_smem_register(struct device *parent,
        return glink;
 
 err_put_dev:
-       put_device(dev);
+       device_unregister(dev);
 
        return ERR_PTR(ret);
 }