Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp709185imm; Fri, 27 Jul 2018 04:54:27 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf1m4VIsPrgnhhvo2VAmamgpDWgeF5P5+00pY6c2lxde1bGyQZZyJsD8cYEyc5TfrHZm0ga X-Received: by 2002:a62:42d7:: with SMTP id h84-v6mr6374824pfd.146.1532692467472; Fri, 27 Jul 2018 04:54:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532692467; cv=none; d=google.com; s=arc-20160816; b=q2kPajr8VQjGtjQ+4OhbYlYIczbTM5OVwkUnccyZwvLOBlKOYLJD4tok4fHf17hG1v qIs3gOiV+2hCIlpfi59D3/G3SPAo+RNA+0FTP3/QfA8MZOQcLgxvBG+OmR9omrzH5A8N YJ0Ke96SXgwX/P0W2BCjwIQ4MdEnS6+GM6SdiRNuhOP4r4C8Pjzo2rkR2KBTr3gknPKB ku+Onqs8jRWDCU6M5WlD5H7MYyObtieqSOdijm4cVaMq/P0L/mlhucOl8jywHi5QZcU0 JPIjJ7rGcAwLa46xkzMDOVOB9hOjjTF/e9wKj2Uz4/hYQXx4RAEoZqBTP3twkgm5gAEg yxsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=0CNg8ve0meUgssgyuAuXaWgB7AsqxLiX+dxgZS3DuFY=; b=sdpu/9ulpiySj4Q2mOvK5jL7prHBkNeSrl6r//GM0V8pLL6Psy/geygiS9/ZXyICCC ZSlGlfu0hTAErb6dNDHFRNqBaB1Uz8uhHRwlH/oiyXal20T5qXL20NTQO/M9/JxokprT jDeauNHNU9tg5+mq1EXu1XgjNLC0hk7asVLsHnTuh2aGe0vxNuEuucJs6R+Sq3N/GrOR fWf1w81+vgKh0jW8hQEk1KWhR2fHreKGrLOGyDyuKBoJvjC543qOb5Ooxqfz3yXKfFhA GGTqS+NGmtj50gEJC6kUr9Pi3bQAbPVWtojsm8OKQHOXVfYSXiUSH2WB6RTEg3rFBwTF BeLQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 61-v6si3386588plc.155.2018.07.27.04.54.12; Fri, 27 Jul 2018 04:54:27 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732559AbeG0NOH (ORCPT + 99 others); Fri, 27 Jul 2018 09:14:07 -0400 Received: from bran.ispras.ru ([83.149.199.196]:19599 "EHLO smtp.ispras.ru" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730126AbeG0NOG (ORCPT ); Fri, 27 Jul 2018 09:14:06 -0400 Received: from myklebust.intra.ispras.ru (unknown [10.10.2.207]) by smtp.ispras.ru (Postfix) with ESMTP id 872C4203B2; Fri, 27 Jul 2018 14:52:31 +0300 (MSK) From: Anton Vasilyev To: "Lad, Prabhakar" Cc: Anton Vasilyev , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, ldv-project@linuxtesting.org Subject: [PATCH] media: davinci: vpif_display: Mix memory leak on probe error path Date: Fri, 27 Jul 2018 14:52:20 +0300 Message-Id: <20180727115220.10991-1-vasilyev@ispras.ru> X-Mailer: git-send-email 2.18.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; - } - 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; + } } 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(); 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(); return 0; } -- 2.18.0