Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4324163pxj; Tue, 8 Jun 2021 11:30:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzptrRCUWwRiLq4h6vmBuwOYTmZgAZ+S528CTfeUam1OkBsZBMkiZ/xNfa8dcnhXsPQuTUz X-Received: by 2002:a17:906:cc14:: with SMTP id ml20mr25662837ejb.515.1623177048526; Tue, 08 Jun 2021 11:30:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623177048; cv=none; d=google.com; s=arc-20160816; b=H20AK2C2WUeNLJZcFtgEMzacib4LDemZuw3M8qZFA0sH2HAWSIwIthiYOuX9QS773W CDAxBJaEI2oLauhXnZd59PtMi5Zxv3jaFvKlKxkeCWusqT5qyuUXcuC1G9dNcXS3NLfZ ok75C3CVHhbrQJbC2VLmmGC+sLSO8FaQ10vCvBPK7C5kFdxWNdjN8WB9YwWVpym1WsrG 3UvzdA3ZQ25tafSQ5DKCrXu1lQ4mNIsw4uOr/CDfMPv4QYPum6ywBrmKfzrmIiFD85Ff EnMzKcO2llyIWm/rEoejSdz1BZ+6R0EF6cuTVELhAncZVGrSWjeCNUJ2Ck5OD2KOYsSk hFLw== 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=yB0LLFZOJ+hLOUN+0OcgkOTyM+tI48dF4wiDXt7d51TWuzr+3yA/kkjjI6BMxHvITP vbuX7duQqVams3+ghOpIRxGKqNfyvq5PEOLuJ8m+DgngWspfFzGdnbpCq5QclxzgrC2V tHXiwhfZS+PdfouaIJbmCzoCVaFIkrNLAdHRsuo524kqB3oy+x4rJiEUFx93Rdon+Mfp zHSz1wFthT9qOmV5eBQV7nvC1IdfXEXCQemtJPH6o8jMfylnPGiJLE4ym027fpHEg/6a WuWsO3Zi7oxP8sMbBo8VL3eZJ8f7sQuE4mtfF37quHUxWD6AszitV7SJt7XH5llQHXqT DtZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="F5/LnCkL"; 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 z97si365135ede.245.2021.06.08.11.30.24; Tue, 08 Jun 2021 11:30:48 -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="F5/LnCkL"; 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 S233118AbhFHSai (ORCPT + 99 others); Tue, 8 Jun 2021 14:30:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:55134 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232746AbhFHSah (ORCPT ); Tue, 8 Jun 2021 14:30:37 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E8B49613AE; Tue, 8 Jun 2021 18:28:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623176924; bh=u/YoHiPNvaOjM6DSUbtCv9cuDvMIjhzS/H0FsmXQYhk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F5/LnCkLpEHweH/O60HG8Qe1oeFbHrfmTCLAL6IuKzzCrWiOc+DKhI/MguXARH/dz j2ujYOkn126XzU+ghhl5cdJvwTF9DKfrRq9hOyXbOaCzWKJ+sy8amkJvBb0K0cS5Qb Jumsw1QV+grUjpbyvZPh4BCYSx8OdOqY2hOR2pZ0= 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.4 14/23] net: caif: fix memory leak in cfusbl_device_notify Date: Tue, 8 Jun 2021 20:27:06 +0200 Message-Id: <20210608175926.999530831@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210608175926.524658689@linuxfoundation.org> References: <20210608175926.524658689@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 = {