Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4293649pxu; Tue, 1 Dec 2020 01:03:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJya9Is7e/h9eQRenUok/Fu+7n6nY4lJE0cwerck3iuO95Jahpe1paBFxzr2fw9oJEEBdwkK X-Received: by 2002:a05:6402:17b5:: with SMTP id j21mr1953263edy.94.1606813391825; Tue, 01 Dec 2020 01:03:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606813391; cv=none; d=google.com; s=arc-20160816; b=UmfxNjxGX2YSGejPT+Q+UxW9Xx63djMRZMlo6Z9Rz+R3fSfqe7b0/GU0f+tOD7FNLY xk1yOE+tduesvUrrb6HcrQLSYRNdgxavcf92kl1FzAdZEfo573/9hhcJfONKK8lhr6Ly nW4egdLUeZipzSvb2bassE+ZKlaxacqxmlyp6qUdsv/5ZPntOUS5EyqVTYSsAyL6EQk5 V2iMlKD+nW2npfUSuUdhdM6QT2Bwj7dtYlkPZVcopZvLa6N/+F70UNDkWGDVZNMKvmnb ElIjYmx7ArGDp/eVZnVViuyH0UuOc5benAwuvnjZqlqYqggWkDtD57mwU//oqetpAsL0 WmdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=UL+eHamty3QL7v5pZ+T1n52bmoO0ovHJmOkgYr34jZU=; b=emi92bOMjwoBpE/Wd+aKYl9SrdJSTE8rXYnVrkSveot5aGrmJ5Y/ucSUbLosUKs5B3 q2JFVFIfzmX8JnRwFM+hr5OJxqoPALUUsyN68O/svHPzUCcD3/vG7hYu4KJ8lnFf0SsB ZODk40qBfKT1DSiY5NNoMSKJrIOoAtr2GD1jc+Y0hugcF7EcWXcLsJKkvlHZQrqjWDs0 eTSTVRQEIAZQuXUhOygnuSP4jaAR3uFX+M7+yxFhPvSvbjgBEyTnr/49ff+RngayIZuV 3/nsZdlhAi8kBSmNYhQeEx/MfUOXD7KqH3FWsYPFaytTG4bhb6P02ncug3HjzOej85Js reKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GSBPFTrU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l8si713595edn.145.2020.12.01.01.02.49; Tue, 01 Dec 2020 01:03:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GSBPFTrU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388148AbgLAI7i (ORCPT + 99 others); Tue, 1 Dec 2020 03:59:38 -0500 Received: from mail.kernel.org ([198.145.29.99]:35418 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388149AbgLAI7e (ORCPT ); Tue, 1 Dec 2020 03:59:34 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3C6C12222C; Tue, 1 Dec 2020 08:58:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606813133; bh=rW0ulsd0x2mf4yx9x+CuPh113Gw6V2chp8HuAY/tGUY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GSBPFTrUbVKwghk4314KqPrQ4LKBZg3EFDXc/F2pRoPTwc4d9/AHvNrXQIg+b+GsP 0HoWv3ZsFDJFiKgZ7X2uauef2qBuDq1iITjDUaA2//m0wSYB2O16qS0aEuDBYrkWoO eGDePIojXPI+FLLbd9LA27s1tA936fB7QgzHVmQ4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hulk Robot , Zhang Qilong Subject: [PATCH 4.14 44/50] usb: gadget: f_midi: Fix memleak in f_midi_alloc Date: Tue, 1 Dec 2020 09:53:43 +0100 Message-Id: <20201201084650.332320199@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201201084644.803812112@linuxfoundation.org> References: <20201201084644.803812112@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhang Qilong commit e7694cb6998379341fd9bf3bd62b48c4e6a79385 upstream. In the error path, if midi is not null, we should free the midi->id if necessary to prevent memleak. Fixes: b85e9de9e818d ("usb: gadget: f_midi: convert to new function interface with backward compatibility") Reported-by: Hulk Robot Signed-off-by: Zhang Qilong Link: https://lore.kernel.org/r/20201117021629.1470544-2-zhangqilong3@huawei.com Cc: stable Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/function/f_midi.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) --- a/drivers/usb/gadget/function/f_midi.c +++ b/drivers/usb/gadget/function/f_midi.c @@ -1303,7 +1303,7 @@ static struct usb_function *f_midi_alloc midi->id = kstrdup(opts->id, GFP_KERNEL); if (opts->id && !midi->id) { status = -ENOMEM; - goto setup_fail; + goto midi_free; } midi->in_ports = opts->in_ports; midi->out_ports = opts->out_ports; @@ -1315,7 +1315,7 @@ static struct usb_function *f_midi_alloc status = kfifo_alloc(&midi->in_req_fifo, midi->qlen, GFP_KERNEL); if (status) - goto setup_fail; + goto midi_free; spin_lock_init(&midi->transmit_lock); @@ -1331,9 +1331,13 @@ static struct usb_function *f_midi_alloc return &midi->func; +midi_free: + if (midi) + kfree(midi->id); + kfree(midi); setup_fail: mutex_unlock(&opts->lock); - kfree(midi); + return ERR_PTR(status); }