Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1893734imm; Thu, 2 Aug 2018 02:53:35 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcHnEm6/knfHhEj+8GsHA2HDptlTP7Va+/YbSs25wqWQNoppOtBVv7ugcavUyvz2dw1dt/I X-Received: by 2002:a17:902:26:: with SMTP id 35-v6mr1743592pla.276.1533203614973; Thu, 02 Aug 2018 02:53:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533203614; cv=none; d=google.com; s=arc-20160816; b=d+6xO0/Njyrtu5S4kijjH+xwxEdCeyV7KVtQMSWhh1L4xa/bcC/FmgSZWM8MDTHIic cduDSPN7gzoC9jT7QuTXYlB6nIC/6doY8VsCxYRa/qOMl/PlOZIuMF1s9tUB1ix8um0P +f4lKdl3zbhFeRL6tD0LIQVJC4SQKoMXosuJ/qzRpfMiVsMUkokS7vNYLBnc7+5oWQJy +XKS3yuzsIfR7hmX1I8BP7tO5DJozgCPHCgwNMvwLBT1YMaTOJ0Trem6kjxspJDw1R/O irnZtdrJkN2dLht3Owc6dvEvJ2mBIBAACmP+9ocwLLXyBOalRT6T68D/kvnCISE+lWH0 Rc9A== 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 :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=MzwBIsl0lvxpOlH5v9xNVTyELIzw7sg3i5YJ3iIGYw0=; b=pCN7eznispSb1d1BssZrcuDHu6Bd9Qj53LTcDdv9ylFivk9Tkx0nYUJZUQRTvOs/sI PjqZ1CQ0fMD6R+br7kVF3KSeYV0EqSCgw+QrJ3y43BhudqkGfXZyhuTjA93F1gRg93qX aIj+D5CfB+L7lNOFLk0ZZ68LbVdenaTidK4iNdC9Y1Gy3yOSAE7Ovl8EJbW+DLDaXubL 7yfcWYw+u4N7cvMK6g9Gd0raqOKPpuJqRHrGSoRNfqI6lFE6C2shBXWTrxMANY5YXRrX JDDGwTLIQzNWD4hcEGXA4IEHSh/7ohd7kKbJQ45+8InP/BqwLvcXPHcBRCy6Jz/OTwXS WdKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Mkmv9rnj; 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 k17-v6si1650504pfj.321.2018.08.02.02.53.20; Thu, 02 Aug 2018 02:53:34 -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=Mkmv9rnj; 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 S1731638AbeHBLmr (ORCPT + 99 others); Thu, 2 Aug 2018 07:42:47 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:37015 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726769AbeHBLmr (ORCPT ); Thu, 2 Aug 2018 07:42:47 -0400 Received: by mail-lj1-f193.google.com with SMTP id v9-v6so1375313ljk.4; Thu, 02 Aug 2018 02:52:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=MzwBIsl0lvxpOlH5v9xNVTyELIzw7sg3i5YJ3iIGYw0=; b=Mkmv9rnjMVrcZ13hc6N6hbWyOyiuOJ+51EYcD8mTCnSCrBHQJS3n56y0dKxH4hqQUg GFeQARAGp8Cx6OPTV0fsA0+tGEgejVi0beXKxTEkKq/Z0drpkXkl++b9CyRQrXx1bNZ7 kENnQs9smeN+b7f5vUsxn7ikhIpBw4NfXU47NArVdZnQHwV82NRDg4zs0w0FeDnxGYry VKrQH7ogviykLjDzkJ7ij18VD1r2WK10lGr0CJIYs58oVtgQJqpMyHaKYc45t3PFxBrJ zmlm7RHoyuuCfCSkJry2rVQGdw59RDjSTS4L5Bm8H9L42z7X1EYwcVslfbU5/UcB0F67 dpPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=MzwBIsl0lvxpOlH5v9xNVTyELIzw7sg3i5YJ3iIGYw0=; b=kdELaRa3BO/wa3Oco6lZ8ZfgFte8jxFaYv5HMbjk/4sflLs2IaHJzookx66iIWoG3R zj80j0W4EhxpoWHQdokf1w5x5TLVGz9GmUK6AK+C30L8DobeWH4FlMQp15HhQ3DfqJ0n tvG2dC5H90RCD8MaXnG6UexdKRnLRR6FhGmgbIb6gox5QA5FpoB7QY+o+LHA2JMTjI95 WhEkrx6g0qgoYruJODWVe4hV01Q1TdiT4v1GxQlPJwhpcBeG/34R6Mr7uhs8V6Wnscsk 6iRyKZYO6VdudF8CCaWMGrgCWUwsk6eOVfvrxzKAYwj7g9tl9eUCddZ16GMdE4jS7a3N Dz6Q== X-Gm-Message-State: AOUpUlG1Zc8O9pnbqpitz66dPmlnnw3tZ8Q1+gHYjDX6nv/mAtk8vDo5 Gd2zkuI9q+UXU9WXLH19p98zEU9JfJcOIVlRQyg= X-Received: by 2002:a2e:8950:: with SMTP id b16-v6mr1746863ljk.111.1533203541978; Thu, 02 Aug 2018 02:52:21 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a19:4d55:0:0:0:0:0 with HTTP; Thu, 2 Aug 2018 02:51:51 -0700 (PDT) In-Reply-To: <20180727115220.10991-1-vasilyev@ispras.ru> References: <20180727115220.10991-1-vasilyev@ispras.ru> From: "Lad, Prabhakar" Date: Thu, 2 Aug 2018 10:51:51 +0100 Message-ID: Subject: Re: [PATCH] media: davinci: vpif_display: Mix memory leak on probe error path To: Anton Vasilyev Cc: Mauro Carvalho Chehab , linux-media , LKML , ldv-project@linuxtesting.org 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, thank you for the patch. On Fri, Jul 27, 2018 at 12:52 PM, Anton Vasilyev wrote: > If vpif_probe() fails on v4l2_device_register() 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 and > removes duplicated check on platform_data presence. > > Found by Linux Driver Verification project (linuxtesting.org). > > Signed-off-by: Anton Vasilyev > --- > drivers/media/platform/davinci/vpif_display.c | 24 ++++++++++++------- > 1 file changed, 16 insertions(+), 8 deletions(-) > > diff --git a/drivers/media/platform/davinci/vpif_display.c b/drivers/media/platform/davinci/vpif_display.c > index 7be636237acf..0f324055cc9f 100644 > --- a/drivers/media/platform/davinci/vpif_display.c > +++ b/drivers/media/platform/davinci/vpif_display.c > @@ -1114,6 +1114,14 @@ static int initialize_vpif(void) > return err; > } > > +static void free_vpif_objs(void) > +{ > + int i; > + > + for (i = 0; i < VPIF_DISPLAY_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) > @@ -1255,11 +1263,6 @@ static __init int vpif_probe(struct platform_device *pdev) > return -EINVAL; > } > > - if (!pdev->dev.platform_data) { > - dev_warn(&pdev->dev, "Missing platform data. Giving up.\n"); > - return -EINVAL; > - } > - Could make this as a separate patch. > vpif_dev = &pdev->dev; > err = initialize_vpif(); > > @@ -1271,7 +1274,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"); > - return err; > + goto vpif_free; > } > > while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, res_idx))) { > @@ -1314,7 +1317,10 @@ static __init int vpif_probe(struct platform_device *pdev) > if (vpif_obj.sd[i]) > vpif_obj.sd[i]->grp_id = 1 << i; > } > - vpif_probe_complete(); > + err = vpif_probe_complete(); > + if (err) { > + goto probe_subdev_out; > + } {} braces are not needed > } else { > vpif_obj.notifier.subdevs = vpif_obj.config->asd; > vpif_obj.notifier.num_subdevs = vpif_obj.config->asd_sizes[0]; > @@ -1334,6 +1340,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(); > Just put the for loop here instead. > return err; > } > @@ -1355,8 +1363,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(); > Just leave this as is, as its already looping and freeing up the objects. > return 0; > } > -- > 2.18.0 > Cheers, --Prabhakar Lad