Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7355200imu; Tue, 22 Jan 2019 04:47:15 -0800 (PST) X-Google-Smtp-Source: ALg8bN6klZDU/eajCkmHvhCuzGxhH1Bq5tbTQir/OPgSJd+thQVYslB+V2Ltt+yXThRJidVpDiLA X-Received: by 2002:a17:902:2b84:: with SMTP id l4mr34257510plb.191.1548161235916; Tue, 22 Jan 2019 04:47:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548161235; cv=none; d=google.com; s=arc-20160816; b=E+si4eYFjd2//pTfZ8k/NqEO+CZugmhkN2ttwoyLeEnH+1PQ5VHVEzAAAWGmS+Y/6x HomGTGzhZoFkx9uYKsVRKfhTX86Hwldt4FNr6JzzrnwHnuEHSc12jWLJmKKm2NbE83O2 8zccgzZWVEGxl3j2kLquzl7Tnlc/ZGcK/0S/yL0J3zDxCg4p3Z5MvJGrAvvod11qplVN /RdFJvqRZS7Bumj13Ord/wk2ET4ggz4cFlRshndeLMDqhwWWDfY/DerXOCK/ITVzAfig 43LRS+HszpIv+IULln5oWG4XuoKcfPWYbMhhC8Y9N7R2stlO+tcnl2baBRcRkNGA3J7F fOng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=Q1ekduSB9euBU5kuilOMU5iVIY13tPhNyosmGcPUbRg=; b=UvcJqdSWs+NSpfAFePSQQn08LHhtPvug7K1y011i6Kt+fEWxptqwzhObEU2FVYCjfC 33dQbv646LC3fGvgiP2h4kIA/hC8pC6/zjXkMyjUBGYgrHFKqKMMPEinD38hYW9TigaY vjFt4qmkDG4Shh+Zlxvsx8ADdxOGbd0bbNdwZc1K9/eCCTyAeiMgCu0br6rv1vmaETWi 1PPzpVe8Wt4Cov7eyOAJ5LTR53HeosSjgBFieEqnEIB+2il1KOo8fiz9rqV/tf8mf4Eu ftL/TGj4bNrITMyGXtrQUKi/i5cqtsVWf1v4zDLfeO1s16KGBe2Eqb7irTfbRr2TfUNP 2+NA== 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 i62si10044202pfc.17.2019.01.22.04.47.00; Tue, 22 Jan 2019 04:47:15 -0800 (PST) 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 S1728453AbfAVMpf (ORCPT + 99 others); Tue, 22 Jan 2019 07:45:35 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:2211 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728215AbfAVMpe (ORCPT ); Tue, 22 Jan 2019 07:45:34 -0500 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 7AEF99E715B572238205; Tue, 22 Jan 2019 20:45:25 +0800 (CST) Received: from huawei.com (10.175.104.208) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.408.0; Tue, 22 Jan 2019 20:45:22 +0800 From: Liu Jian To: CC: , Subject: [PATCH v2 1/2] driver: uio: fix possible memory leak in __uio_register_device Date: Wed, 23 Jan 2019 06:45:37 +0800 Message-ID: <1548197138-352285-2-git-send-email-liujian56@huawei.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1548197138-352285-1-git-send-email-liujian56@huawei.com> References: <1548197138-352285-1-git-send-email-liujian56@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.104.208] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 'idev' is malloced in __uio_register_device() and leak free it before leaving from the uio_get_minor() error handing case, it will cause memory leak. Fixes: a93e7b331568 ("uio: Prevent device destruction while fds are open") Signed-off-by: Liu Jian Reviewed-by: Hamish Martin --- drivers/uio/uio.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c index b4ae2d9..4d20220 100644 --- a/drivers/uio/uio.c +++ b/drivers/uio/uio.c @@ -941,8 +941,10 @@ int __uio_register_device(struct module *owner, atomic_set(&idev->event, 0); ret = uio_get_minor(idev); - if (ret) + if (ret) { + kfree(idev); return ret; + } idev->dev.devt = MKDEV(uio_major, idev->minor); idev->dev.class = &uio_class; -- 2.7.4