Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp7219431ybi; Wed, 5 Jun 2019 13:22:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqxGKWHIamTa3OISLsqDnEm7v4Uxrx7jIqMz4QUUJnRyEJkn3PZNtt/c2jOFKfsZOhNfS2ib X-Received: by 2002:a17:90a:9202:: with SMTP id m2mr46929067pjo.37.1559766174315; Wed, 05 Jun 2019 13:22:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559766174; cv=none; d=google.com; s=arc-20160816; b=tTrhNFQdT//2/9JmEbbkwj8O0+XOJYepjdL0l6By475lsfhucOOjdRrFAsuyRd4yrd piI7KNzUsk5KH2HcDHj57i31Nc+ducnF1rUPOhPNd7VVfFhqN28NV7+09oI4YyqKUsak tQ5DadGgEkyRDp1GoxJEeNaevrPi3Rf1HzPrY4GQyFMVwCoblEAVBNG6LtQQfGs/XIWK HshJDP2TdeaC8PUh2+2vFovEoLxP0Kc2kQbyJJHtzL7II2gfdgEprRyChxuExbmFxm5Z +vHv4007NzLkE8YB8clwgrC7FeEJYt7bYvIyy0cPo760R27dZa/WO0trtxkwP9b+rTZg jo6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=a23dw9qztWcz3b3QKk1MGLNahxdaBieL3lGWGrnStH4=; b=dOrH14TUsKqMJdQnfa1BbpRO76B7jA9TrG8JyHY50WD27czi7V1UUynJpVmbGMnVFn xcvzPdmcrV/l2mrey6P9Hy3Kn5+rOBBUXSKSisYnZVPjTpsS+ko1w/v4MKeoC/TYAO+C rHYvHDuNcDwWauPGzIAdKXijO4M0S+rWEQxg/KZg/lWbziOrgOVWuRqMR8pTMNJiXr1d Mw0414OCH3HBHUKH/5UDDncoQBAHOqao/+uWMwVOobbQ2wE40gbK9AQzH9rLKBbXx5sb VlfAkpeE/UN3KN7/eMvjMyfaCPieTil2I6Y+JyZOdSb02S/UGXvyoF6qAOAzu4mnOuH5 wE2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=O62AVfLH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g17si29166745pgk.500.2019.06.05.13.22.37; Wed, 05 Jun 2019 13:22:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=O62AVfLH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726645AbfFEUVM (ORCPT + 99 others); Wed, 5 Jun 2019 16:21:12 -0400 Received: from mail-oi1-f195.google.com ([209.85.167.195]:40269 "EHLO mail-oi1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726528AbfFEUVM (ORCPT ); Wed, 5 Jun 2019 16:21:12 -0400 Received: by mail-oi1-f195.google.com with SMTP id w196so9665315oie.7; Wed, 05 Jun 2019 13:21:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=a23dw9qztWcz3b3QKk1MGLNahxdaBieL3lGWGrnStH4=; b=O62AVfLHOS2mSvjtvIx7Q1hdgKyXLEvw3ETdEANYPaOrgtPSQPMLEsaKJGErVwCIX2 ZokHJq1KIlKkjcdPIEwNowN8ba0I6OaI+pmHdWyq2lktEUrwtnVZakBdkfTCu+lvzT44 kzVmGGHZcXidy2twnCQc+hSuXndr4t+OWZZuJI06uYY7FfkdN/wMBPwzdD8SQyaoK5AA e0MSa89ZDcHb8hf6/Und8ReEj8VqkuIEo3OhGJztilw9FJg5FEAgkLYTCE7siSBTHGPg xm8V8dMd6AerUe9Le+xFuv66Dsj7W9uy+Z4GQ1I5j0FtWCZSVPZdmTIBlZdeTJGt1AQv i6hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=a23dw9qztWcz3b3QKk1MGLNahxdaBieL3lGWGrnStH4=; b=nLqT18A521690BjlVY5MI4oyKH6o17oD93q3IUfSDeurlv7J3bdu0TR5zXCHkfRj9M tMm2PKtyof2f3XEIv07T3Z0DPcAL+SfAd9/818WaEm837MRV4+/jMRkZc/XW1EjXe/jN ZrGnUIkh7FMsS0X8QOQP6e+FDSVwg0UyE0My8ZKXVmjiFpesVcW+fO73MhNnrPNr6tXJ Hc5i3ibfoB+i1ROb81oaZOYdC4TpoQGJcCARXXhtrnSkpViWqO0xF+p6MfI9+DukkJ90 vTuNKQvCwhDbwBfdxEg59Iczujbg+q+nuy8BrnxjslO+SpY43dZ0b1I9gbsv30/Oogg7 wKKw== X-Gm-Message-State: APjAAAVpJTL1XtQYQRZILyzd3WhCAJAZkZzWfLfZ6iDyjC+UqMcyF3is CFNL1tZzXFTxIOJHyCqoo11U4a9BZygPCTRtYQE= X-Received: by 2002:aca:b606:: with SMTP id g6mr7507212oif.101.1559766071541; Wed, 05 Jun 2019 13:21:11 -0700 (PDT) MIME-Version: 1.0 References: <1559651193-17982-1-git-send-email-92siuyang@gmail.com> In-Reply-To: <1559651193-17982-1-git-send-email-92siuyang@gmail.com> From: "Lad, Prabhakar" Date: Wed, 5 Jun 2019 21:20:45 +0100 Message-ID: Subject: Re: [PATCH] media: davinci: vpif_capture: fix memory leak in vpif_probe() To: Young Xiao <92siuyang@gmail.com> Cc: Mauro Carvalho Chehab , Hans Verkuil , linux-media , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 4, 2019 at 1:25 PM Young Xiao <92siuyang@gmail.com> wrote: > > If vpif_probe() fails on v4l2_device_register() and vpif_probe_complete(), > then memory allocated at initialize_vpif() for global vpif_obj.dev[i] > become unreleased. > > The patch adds deallocation of vpif_obj.dev[i] on the error path. > > Signed-off-by: Young Xiao <92siuyang@gmail.com> > --- > drivers/media/platform/davinci/vpif_capture.c | 16 ++++++++++++++-- > 1 file changed, 14 insertions(+), 2 deletions(-) > Acked-by: Lad, Prabhakar Cheers, --Prabhakar Lad > diff --git a/drivers/media/platform/davinci/vpif_capture.c b/drivers/media/platform/davinci/vpif_capture.c > index b5aacb0..75c2c10 100644 > --- a/drivers/media/platform/davinci/vpif_capture.c > +++ b/drivers/media/platform/davinci/vpif_capture.c > @@ -1385,6 +1385,14 @@ static int initialize_vpif(void) > return err; > } > > +static inline void free_vpif_objs(void) > +{ > + int i; > + > + for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) > + kfree(vpif_obj.dev[i]); > +} > + > static int vpif_async_bound(struct v4l2_async_notifier *notifier, > struct v4l2_subdev *subdev, > struct v4l2_async_subdev *asd) > @@ -1654,7 +1662,7 @@ static __init int vpif_probe(struct platform_device *pdev) > err = v4l2_device_register(vpif_dev, &vpif_obj.v4l2_dev); > if (err) { > v4l2_err(vpif_dev->driver, "Error registering v4l2 device\n"); > - goto cleanup; > + goto vpif_free; > } > > while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, res_idx))) { > @@ -1701,7 +1709,9 @@ static __init int vpif_probe(struct platform_device *pdev) > "registered sub device %s\n", > subdevdata->name); > } > - vpif_probe_complete(); > + err = vpif_probe_complete(); > + if (err) > + goto probe_subdev_out; > } else { > vpif_obj.notifier.ops = &vpif_async_ops; > err = v4l2_async_notifier_register(&vpif_obj.v4l2_dev, > @@ -1720,6 +1730,8 @@ static __init int vpif_probe(struct platform_device *pdev) > kfree(vpif_obj.sd); > vpif_unregister: > v4l2_device_unregister(&vpif_obj.v4l2_dev); > +vpif_free: > + free_vpif_objs(); > cleanup: > v4l2_async_notifier_cleanup(&vpif_obj.notifier); > > -- > 2.7.4 >