Message ID | 20200429152951.18504-1-srinivas.kandagatla@linaro.org |
---|---|
State | New |
Headers | show |
Series | misc: fastrpc: fix memory leak | expand |
On Wed 29 Apr 08:29 PDT 2020, Srinivas Kandagatla wrote: > if misc_register() fails, previously allocated data is left without freeing, > this could result in memory leak. s/could/will/ > > So fix it! > As Markus pointed out, a Fixes: tag would be in order to make sure this is backported properly. PS: although unlikely, if of_platform_populate() where to fail we're leaking both the contet and the misc device. Regards, Bjorn > Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org> > --- > drivers/misc/fastrpc.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c > index e3e085e33d46..9065d3e71ff7 100644 > --- a/drivers/misc/fastrpc.c > +++ b/drivers/misc/fastrpc.c > @@ -1613,8 +1613,10 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev) > domains[domain_id]); > data->miscdev.fops = &fastrpc_fops; > err = misc_register(&data->miscdev); > - if (err) > + if (err) { > + kfree(data); > return err; > + } > > kref_init(&data->refcount); > > -- > 2.21.0 >
diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index e3e085e33d46..9065d3e71ff7 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -1613,8 +1613,10 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev) domains[domain_id]); data->miscdev.fops = &fastrpc_fops; err = misc_register(&data->miscdev); - if (err) + if (err) { + kfree(data); return err; + } kref_init(&data->refcount);
if misc_register() fails, previously allocated data is left without freeing, this could result in memory leak. So fix it! Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org> --- drivers/misc/fastrpc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)