Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5116611ybi; Tue, 4 Jun 2019 01:19:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqzz0qI51V7yGbSa/oi/gSQt1r8yKLdhwqUu4Ze2oX/pBT5u+iwTufai7VTqujfj5GFgUVmR X-Received: by 2002:a17:902:324:: with SMTP id 33mr35119175pld.284.1559636357996; Tue, 04 Jun 2019 01:19:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559636357; cv=none; d=google.com; s=arc-20160816; b=XavlxLsy9eQ8aLfA8cAajFdvIAymtiHYFsVqm2RPwV/wxnar94fbGSZTydl00lNKOf wllSFIJR3HYOhuzWf+q9tGTQBS1MSPtjWeu5mRfVnCg69lfkXdi7iTN3bIa5lMy3Fghw ZF8rK/PfYzs/Jwukj7T2QWT+Sj7mf5S5xE9a6c+5+8L8jA3Or/gte6RCXNQfTs4i6hbt ei8FY+9/CE0HP7q/HCkNPvCNBfftEi4zRp8l936sMBFf0iU3j+lBLS2GczbWwXnvNRuy ntzMxVb2aLczJrfgK5AtUhOE9cIevFgsXo26Ctl3AuYOUSWOCnDFo3yza5kVymBn6E/m vyvA== 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=0P8XfByoZm6wKL9UI7hjVSwllit04FWD2v61aqDNCsk=; b=famo1KC1BXNo5Vkd3gy8vlwS0Aay8uWExsgWLp4TYSzCgmrtFHu3wVsUXhEcpJhWDS +8ado9fa/7g49ScziAyRH9LMNoU4a3xmTV3O2IIw7FDSXE32hrR3XdJ5mhq7tQcZ7tGZ tSUp3GLjmflOrIRwmtdsyY4I/yUdeUKVuos0E9ToddQMdbMIQic46H21fkC4vrv02LEE TjC8JFDGjfxXaQLqbmIY0aogukNoOT2kB5aDg89xcTnpb2CTAiZ+R3tRGWzkLXL2gc5l MKN8lPN5vQKOc7rOiAc9GdZpr4eScPsO11D1eNKFjFhIzdA6mI+eEzu1rANkcOGmRzny iIBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=QYYfbrVD; 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 16si8505621pfo.12.2019.06.04.01.19.02; Tue, 04 Jun 2019 01:19:17 -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=QYYfbrVD; 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 S1726788AbfFDIPz (ORCPT + 99 others); Tue, 4 Jun 2019 04:15:55 -0400 Received: from mail-oi1-f195.google.com ([209.85.167.195]:42840 "EHLO mail-oi1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727184AbfFDIPw (ORCPT ); Tue, 4 Jun 2019 04:15:52 -0400 Received: by mail-oi1-f195.google.com with SMTP id s184so3889488oie.9; Tue, 04 Jun 2019 01:15:52 -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=0P8XfByoZm6wKL9UI7hjVSwllit04FWD2v61aqDNCsk=; b=QYYfbrVDHfyi4+hEVQ1HJudI8csHpDdfwoBUhZn+mkEtYtDFRbnTMN41mguZKHRST4 lIAZ0wCvOXIp4tyw8iqrB5scRQxvrl82Iu64YPGEEYTgEVrNxWUZdpwZnxugqlysi5nL djZv9bZKtJf1PxjQqNKmBHT+7J8ZIlyFxzx7zt/6dkFJCN3NtU5zTQ2BgZYCoU2pTWNT dbIJSBST3vVA8GBgXFr0XJPhnbC58lFsn7hhpRn3d30t+PtXRDpiRYgdvBhYz3ZhxnJB q01kj33P4n7A1/7oXHJL18v9AiUT0KNx8tcYH3JPYhfxciR0p2T4X2f+D4WxjQuyeIRn L5Dg== 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=0P8XfByoZm6wKL9UI7hjVSwllit04FWD2v61aqDNCsk=; b=KwchwimQ0oh1sjuUoCQfaRtiu7xx1Y+Jqu6CKOgyAsJcNnFERUI2F0IZHOcOCqtiuP EbpV6cfztzgSfYsZj3HmHs/zazpJtSmZ7IabRk/P+zUvyovymtGYdJUQ0MY0s7UhKrlR H67RMO4zOq5ZFSS5ySdCR0QL24i25b9SC2cFZ8emWfL+z9DD2xOh3ysCR2fwTuUJr8+A jcrvyjV+PcORLdToHK6QhSlMPeKGjj/zBPl53gjEPZgF6i6ZyK+ncWBvuZhDzilTIPr3 YudZEGD8IMSUMLJxLS3JdjZyxGWKqF68rUngXRCcTaEtEips2r2o4jmSoEe5Tm1TapgG aZPQ== X-Gm-Message-State: APjAAAUj+g7Nhi1yztBG3jsWbmS9d6XN01MYuXMugNQKRoL/jdxrihKM NF9c83tWoYDNTMpofh7JU6fa8nzINyxKrUnQTFQ= X-Received: by 2002:aca:b606:: with SMTP id g6mr1605787oif.101.1559636151980; Tue, 04 Jun 2019 01:15:51 -0700 (PDT) MIME-Version: 1.0 References: <1559634617-16264-1-git-send-email-92siuyang@gmail.com> In-Reply-To: <1559634617-16264-1-git-send-email-92siuyang@gmail.com> From: "Lad, Prabhakar" Date: Tue, 4 Jun 2019 09:15:25 +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 , linux-media , LKML , Hans Verkuil 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 Hi Young, Thanks for the patch. On Tue, Jun 4, 2019 at 8:49 AM 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 | 19 ++++++++++++++++--- > 1 file changed, 16 insertions(+), 3 deletions(-) > > diff --git a/drivers/media/platform/davinci/vpif_capture.c b/drivers/media/platform/davinci/vpif_capture.c > index b5aacb0..277d500 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 void free_vpif_objs(void) > +{ function could be made inline. > + int i; > + > + for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) VPIF_DISPLAY_MAX_DEVICES ? this should be VPIF_CAPTURE_MAX_DEVICES > + 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,10 @@ 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; > + } No need for { and } as per kernel coding style. > } else { > vpif_obj.notifier.ops = &vpif_async_ops; > err = v4l2_async_notifier_register(&vpif_obj.v4l2_dev, > @@ -1720,6 +1731,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); > > @@ -1748,8 +1761,8 @@ static int vpif_remove(struct platform_device *device) > ch = vpif_obj.dev[i]; > /* Unregister video device */ > video_unregister_device(&ch->video_dev); > - kfree(vpif_obj.dev[i]); > } > + free_vpif_objs(); no need for this change, leave it as it is. Cheers, Prabhakar Lad