Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5130665ybi; Tue, 4 Jun 2019 01:36:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqyWZdQcR9g5mvoF3JKRaC1NrgfGy1QSZ4hIxAC7y1482OFJdgl53a84nfJC73wYbSyYSe/4 X-Received: by 2002:a17:90a:aa81:: with SMTP id l1mr34018256pjq.55.1559637411920; Tue, 04 Jun 2019 01:36:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559637411; cv=none; d=google.com; s=arc-20160816; b=zyde7l4VILY/QRZpnLXkzqnuc/yhOhqm+5epPUKJ0K/WISFwB8gPpjSf6nDIz4VDdy 7GtgROeV9oWL4kNAG2SaxgXPfaSo2O31s3S6k6xbk+4bNo0XuNccj9qmLueBfChv7CUP B0/taoiSKaKEl9YX+umlLfZxcZujL1TVfyg0WUzXIn4/6fTSszj2ldZN7dT8moz3Dpsx DFv0AO3juHbeUGrX1sMIA7wJP3ljZc6i5HkOLOkyNkUbVjKA6S4bng9HAgMlArRS8Lh3 Uf8fpNTSdVEkz5MbbqdpwXkBCKYZfTABSBl77aNF537zrq+aDDh4aQ4pl2CTDfDwuqZ0 OfZg== 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=vJ45MV+BASoppHJ2PxusDyNNyvOx4jaha4ViGHy9S30=; b=NzHgirvk5Q2uMNtr0Ydy99I6upnrHgrKuDkIclKvwTGH2XM7Y5nml1z6Pp0k6nW3JP Hhpy1Y5Us6pV470y3VZt2qKUXXwLV42N8Pd1z7dEqxd2+l0w5SjqqUIlj3CzmGpN21GW Tgt6uQZPssFsoaFpFRW+Mss9G1zjX9flwe0BRkRmYAoAL4WDEUDnBz2XFOQ7YGQ35NNN BNAf16N8bjUmvsUt5KQ8kOXVsPWWMYMj/FEDrBF5JgGHQtv//0VPt86dSXxGQ24XfWda dgf0bv/c+8qAtYEKw+HCCSzt/FhRSTxiQQjrry17b7UF4hKOay4gIHGFdNpTj4kEuVSx QTWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=sLtbsS60; 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 y10si22011638pgq.173.2019.06.04.01.36.33; Tue, 04 Jun 2019 01:36:51 -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=sLtbsS60; 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 S1727089AbfFDIe3 (ORCPT + 99 others); Tue, 4 Jun 2019 04:34:29 -0400 Received: from mail-vs1-f65.google.com ([209.85.217.65]:32904 "EHLO mail-vs1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726735AbfFDIe2 (ORCPT ); Tue, 4 Jun 2019 04:34:28 -0400 Received: by mail-vs1-f65.google.com with SMTP id m8so3897816vsj.0; Tue, 04 Jun 2019 01:34:27 -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=vJ45MV+BASoppHJ2PxusDyNNyvOx4jaha4ViGHy9S30=; b=sLtbsS60jUXae/oFGfWV5MmP+uLUlWMKyghbv0ZpgLYhhcUvwUlavdh+GkBAu9OyFd w531oCcELQZlq3aHLYJB/rhKJgZCj407l70vI7ifKd74N3+oXzdYrz6vb8aqoLkhCbNC /AfkFJhC0C3Xh0YAGO3cx0qqOdJrz0L4m7TgZTEy746aAlEEiqWxrSQLSN9WoaKtI47J Bb/Bv+AGzf5uhMnP8jC68uLnhmHVH1jxY/HfOi95NzWSVFDldifZ+RvXwb3l8EWH0t+s SQ1rKdS4VwvbbcXgeT4ihZoJrvoFDH3X4uwgkr840QSjXfcHtc2CsYfNLDdtyNLFGtnY GycQ== 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=vJ45MV+BASoppHJ2PxusDyNNyvOx4jaha4ViGHy9S30=; b=SL70RGi2sdC/DBVaLn/GuGHhV0dSTf0nqYszxPGWMbYPjMO9tpvuZw1FolKmpRqlBq pOUrnpUseHBv/jao42vNpy1+/FgwsoZVamiQRe6WxuUoPHwP6pDDuVsmNINDCq5RmZPy Uu4ujyHH2LPKHVkNJIWsALJTdnBGt6HmTJBw7O6KG4dn5/5Wj6Pw/1ckC1Z4WrYAnOl3 LfVYQchGHl38bF/vov76TeAOBMFiF2flkbNfNIrAAPSSirBAfD8qTiCAq7oMpQGDgevO OV3ne0pOSEyeZUVU2fSL79jEpTBsxeItuVrWjhbeOPtlF+IQULk/yJpwJtV+kGrqbwKa MHHw== X-Gm-Message-State: APjAAAWObiXSbCHdhtWVBUCsGfNY+uU01ZoUH+iCxNsx6W+LPtTmSJnL OPteFI8XiMrcOkSqPFEFZtmXwT7pwMkalxpneVQ= X-Received: by 2002:a67:c295:: with SMTP id k21mr92148vsj.140.1559637267073; Tue, 04 Jun 2019 01:34:27 -0700 (PDT) MIME-Version: 1.0 References: <1559634617-16264-1-git-send-email-92siuyang@gmail.com> In-Reply-To: From: Yang Xiao <92siuyang@gmail.com> Date: Tue, 4 Jun 2019 16:33:46 +0800 Message-ID: Subject: Re: [PATCH] media: davinci: vpif_capture: fix memory leak in vpif_probe() To: "Lad, Prabhakar" 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 On Tue, Jun 4, 2019 at 4:15 PM Lad, Prabhakar wrote: > > 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. Sorry, I can not get your point here. There is no need to check the return value of vpif_probe_complete(), isn't it? So, we just fix the memory leak in the error path of v4l2_device_register()? > > > } 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 -- Best regards! Young -----------------------------------------------------------