Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp6027389imm; Mon, 23 Jul 2018 10:06:32 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf45hUY64enh96HJ3AWnBvBKNJUngMYJKEU+Gzvwh51j2j6M82kwWq9O/XJU4yxxFYyLx3t X-Received: by 2002:a62:cd44:: with SMTP id o65-v6mr14003395pfg.47.1532365592825; Mon, 23 Jul 2018 10:06:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532365592; cv=none; d=google.com; s=arc-20160816; b=eUniBr1nGvi8pPxWmkKirubuLAvGdUqTEKgCdtnJCjLs+QCs+TV36UnVrPvqmjDI9V mhDaJXuytGfMxC4nw0xEUIPP+Y17ROH/zltCtxdGgWXbLK56h1as3rtN5uZOlGFT7bWU TFqyeMRlwmZeO3YIz99ex+wj64INxqBMO+rqdWCtvrJgHZzfFCuphhgXMobagla+qUH2 ymBdQcGG3yBfNPNM9uUlQ/zQ/X2OZdzZ8X8BUmP12EqVh2jTwIyYhJqPT7a+e7U/WJFq gVQyU73hTke76xYFIlMqCgE5/86i2vbKlF634DQHoEdC6rTFsmWwhDEedFakSk2rPX39 vE5w== 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=AZFOxpdXiCNofZ1zJBJVcEFVI1Wal2D6/VKLVA2kZHw=; b=Xyos93nN0vxnKxtyejZdg35Xj/w3f2C++M/QyhdldNy5xga3qXzLXa61wJa+dEU0UY 3Zz7Xi8jWDNVR0UoLPRfe9ScC52Ea3N49nAV6aH+ib286S2Yid99BG3fHYRDNVKrM3hB Js2U3ADoNeIkelrjPwpOpEhG7N4jTEyzXS2xTzeWiMFP/qVRRninaM4OqFFePbHvMQeM 0wPDK7DcDixzl/RRhaJ3Jaqc8BloyJdTPntFUZc52T6p7C1UHyaP3TyzVU+3Tj8RDABU jJy/gvrPXTU1Dftx0KVCRIot2Mh13kQBOnsulttcHCH0vHizuBhQLw/EPoESVRb9Q5+U R2xg== 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 v129-v6si9292381pfv.278.2018.07.23.10.06.18; Mon, 23 Jul 2018 10:06:32 -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 S2388928AbeGWSHX (ORCPT + 99 others); Mon, 23 Jul 2018 14:07:23 -0400 Received: from bran.ispras.ru ([83.149.199.196]:13965 "EHLO smtp.ispras.ru" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2388200AbeGWSHX (ORCPT ); Mon, 23 Jul 2018 14:07:23 -0400 Received: from myklebust.intra.ispras.ru (unknown [10.10.2.207]) by smtp.ispras.ru (Postfix) with ESMTP id 0B365203C3; Mon, 23 Jul 2018 20:05:11 +0300 (MSK) From: Anton Vasilyev To: Mauro Carvalho Chehab Cc: Anton Vasilyev , Jonathan Corbet , Enrico Mioso , Bhumika Goyal , Sean Young , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, ldv-project@linuxtesting.org Subject: [PATCH] media: dw2102: Fix memleak on sequence of probes Date: Mon, 23 Jul 2018 20:04:54 +0300 Message-Id: <20180723170454.25905-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 Each call to dw2102_probe() allocates memory by kmemdup for structures p1100, s660, p7500 and s421, but there is no their deallocation. dvb_usb_device_init() copies the corresponding structure into dvb_usb_device->props, so there is no use of original structure after dvb_usb_device_init(). The patch moves structures from global scope to local and adds their deallocation. Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Anton Vasilyev --- drivers/media/usb/dvb-usb/dw2102.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c index 0d4fdd34a710..9ce8b4d79d1f 100644 --- a/drivers/media/usb/dvb-usb/dw2102.c +++ b/drivers/media/usb/dvb-usb/dw2102.c @@ -2101,14 +2101,12 @@ static struct dvb_usb_device_properties s6x0_properties = { } }; -static struct dvb_usb_device_properties *p1100; static const struct dvb_usb_device_description d1100 = { "Prof 1100 USB ", {&dw2102_table[PROF_1100], NULL}, {NULL}, }; -static struct dvb_usb_device_properties *s660; static const struct dvb_usb_device_description d660 = { "TeVii S660 USB", {&dw2102_table[TEVII_S660], NULL}, @@ -2127,14 +2125,12 @@ static const struct dvb_usb_device_description d480_2 = { {NULL}, }; -static struct dvb_usb_device_properties *p7500; static const struct dvb_usb_device_description d7500 = { "Prof 7500 USB DVB-S2", {&dw2102_table[PROF_7500], NULL}, {NULL}, }; -static struct dvb_usb_device_properties *s421; static const struct dvb_usb_device_description d421 = { "TeVii S421 PCI", {&dw2102_table[TEVII_S421], NULL}, @@ -2334,6 +2330,11 @@ static int dw2102_probe(struct usb_interface *intf, const struct usb_device_id *id) { int retval = -ENOMEM; + struct dvb_usb_device_properties *p1100; + struct dvb_usb_device_properties *s660; + struct dvb_usb_device_properties *p7500; + struct dvb_usb_device_properties *s421; + p1100 = kmemdup(&s6x0_properties, sizeof(struct dvb_usb_device_properties), GFP_KERNEL); if (!p1100) @@ -2402,8 +2403,16 @@ static int dw2102_probe(struct usb_interface *intf, 0 == dvb_usb_device_init(intf, &t220_properties, THIS_MODULE, NULL, adapter_nr) || 0 == dvb_usb_device_init(intf, &tt_s2_4600_properties, - THIS_MODULE, NULL, adapter_nr)) + THIS_MODULE, NULL, adapter_nr)) { + + /* clean up copied properties */ + kfree(s421); + kfree(p7500); + kfree(s660); + kfree(p1100); + return 0; + } retval = -ENODEV; kfree(s421); -- 2.18.0