Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4326484pxj; Tue, 8 Jun 2021 11:34:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0IIdZX9YDnJTIi0FG5Py5lvLPwBP37qq7qelQ5FaO05HZZ66wjSchH31zp+w13EHQfDDT X-Received: by 2002:a17:906:71d2:: with SMTP id i18mr25843528ejk.373.1623177265014; Tue, 08 Jun 2021 11:34:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623177265; cv=none; d=google.com; s=arc-20160816; b=0ooP+vagEKEfJFHrDIKsqM+yDvtFU/60aNKDzoX8/Oq52T2v5zS2Nw2+bR59AY3Ugb M4uQdECtmMCgbWsYyNFC+DhpTudI9hs3u6u1T27DM87d0zMErh4jARCh1wVQyGpiad6y 1AI8k0ggr0nqZYfHdca+EMLA1Sc6DB3owGNn4DiIIcb4MZZlxktK/jHL3esXeVNaUoj4 EK4vy8guMuqrt6QLyPuFf5eFGCnxk+RrVYRIKq/PsHf1HeqtFYVswL4kFFBdWj6FAgV3 fuiFD/RtoHZaRc3qxF0j+D2tpQsjGitumi9AUpmAF92MdecDtVCWBsj0K8ftQtJpsWb3 Sduw== 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=P+Mb4dKFdL9pG2erbijvFOY8jQpRvY8YB8TvqiXNVeM=; b=nSDpSU12dazt5g2Ou+NlPl1Q8kYS1cK0579UV3vgy9wb3iI+mH33b/4nsCyYvqJ0Q5 Z7sqXy446Xd/GMyZuh73BfN3mkBxozTyKr+rxXb1H7JsUZ2vJaZnqdgPiK98rJvEjS2e trWuHZVQ6SThHuBJ8N/v1jcOn109sfqyxaGE/ca0M7OQN84ojyzrwORyrKWMDE23zcNI 9GCkATXKF6T5jMVAP9vpylx9hR5al0gZ0GXkIqlMM6mZYKxNu05mFZyFgfCwY9Lw8TFH oTmxNv4rFZszf531tcApB5CtC/GkMk9BkD2MESHUfVaBWIf5QAa4lxaFqgDXZl/ToiNx /10g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=w1ecqlHd; 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 m3si356191edp.580.2021.06.08.11.34.01; Tue, 08 Jun 2021 11:34:25 -0700 (PDT) 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=w1ecqlHd; 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 S234451AbhFHSdl (ORCPT + 99 others); Tue, 8 Jun 2021 14:33:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:57916 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234430AbhFHSca (ORCPT ); Tue, 8 Jun 2021 14:32:30 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1B488613BC; Tue, 8 Jun 2021 18:30:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623177037; bh=u/YoHiPNvaOjM6DSUbtCv9cuDvMIjhzS/H0FsmXQYhk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=w1ecqlHdMex9EDLjmMArCL1OmZoCNlowmcIcaOATCHtaalPenNWr4LL0soVc9i4tn 2KsFI6I/LMYVakcqZsh+iN9XGYxMf++t3IB/hWRaCQHF2jTOocPSqiheL28HOjY+1w iuSUR3l01Jmv7xotMtNXd6nvDP9nnpp7iKXukY9o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pavel Skripkin , "David S. Miller" Subject: [PATCH 4.9 18/29] net: caif: fix memory leak in cfusbl_device_notify Date: Tue, 8 Jun 2021 20:27:12 +0200 Message-Id: <20210608175928.416437286@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210608175927.821075974@linuxfoundation.org> References: <20210608175927.821075974@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: Pavel Skripkin commit 7f5d86669fa4d485523ddb1d212e0a2d90bd62bb upstream. In case of caif_enroll_dev() fail, allocated link_support won't be assigned to the corresponding structure. So simply free allocated pointer in case of error. Fixes: 7ad65bf68d70 ("caif: Add support for CAIF over CDC NCM USB interface") Cc: stable@vger.kernel.org Signed-off-by: Pavel Skripkin Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/caif/caif_usb.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) --- a/net/caif/caif_usb.c +++ b/net/caif/caif_usb.c @@ -116,6 +116,11 @@ static struct cflayer *cfusbl_create(int return (struct cflayer *) this; } +static void cfusbl_release(struct cflayer *layer) +{ + kfree(layer); +} + static struct packet_type caif_usb_type __read_mostly = { .type = cpu_to_be16(ETH_P_802_EX1), }; @@ -128,6 +133,7 @@ static int cfusbl_device_notify(struct n struct cflayer *layer, *link_support; struct usbnet *usbnet; struct usb_device *usbdev; + int res; /* Check whether we have a NCM device, and find its VID/PID. */ if (!(dev->dev.parent && dev->dev.parent->driver && @@ -170,8 +176,11 @@ static int cfusbl_device_notify(struct n if (dev->num_tx_queues > 1) pr_warn("USB device uses more than one tx queue\n"); - caif_enroll_dev(dev, &common, link_support, CFUSB_MAX_HEADLEN, + res = caif_enroll_dev(dev, &common, link_support, CFUSB_MAX_HEADLEN, &layer, &caif_usb_type.func); + if (res) + goto err; + if (!pack_added) dev_add_pack(&caif_usb_type); pack_added = true; @@ -181,6 +190,9 @@ static int cfusbl_device_notify(struct n layer->name[sizeof(layer->name) - 1] = 0; return 0; +err: + cfusbl_release(link_support); + return res; } static struct notifier_block caif_device_notifier = {