Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4338236pxj; Tue, 8 Jun 2021 11:52:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5Tq0ELZ40figM1VCIGZ5aJC1+DoczHDHjOGy1biH9gLpK5WIs7V4Wl89ZEENvb6ZD28Ql X-Received: by 2002:aa7:d284:: with SMTP id w4mr27429718edq.347.1623178367838; Tue, 08 Jun 2021 11:52:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623178367; cv=none; d=google.com; s=arc-20160816; b=pMMnkJsyD6A+cNVm6VkujtNsKMu2mhvXAg8FTp/GkOL3qJIGuwFBQtTrf0Uy4bBxvY slP8qmV81l6acQF8v2121QHVyXj064jV+LmnlcZ/EB0292EMNcWFwPpXF6zr6jgF1koo voYx13Ehao5oF7VI9or4b0jIjm5O8M9NLT87JuJofemlK0ZbedAQNwp23QZ0l1LnXuB6 vArZOo0mP9vtptWTPUlKDVqCGzuGyZHP0ECimUBbv7YordKidqhYFA/Oy9EIz744CXBG 3sGgL+jpw7sy+MZMi0Ygr02e2i7o5bCe2udWw8VbbYD9KYAQWZc6mTFN9aCdtb5EZ7bC gyiw== 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=jt66i0yHZymi3DFfW8enRSrQ/qfuBPRMwbx9Y4kxO8o=; b=yh+DiGLQed5hF9HWQGh6WUkMBz8foQYhm3B9NszgrHawGOjlOLuU8mcqvsxRDPly4k zVFbR/ZbwBRnHrXbcWDVCVoI2CmHc8GjtmHgEMbF11tRyjSHmGypFN4e5J4Y2KTmQMl1 Osb3rrkor5oZNpG5y1y+8NfwFi0plqiP1srPMsss1bx8/+F9qdB/u0HoV+XOxwMxudC7 niXHT4i33668FsnKaUugkReHXNR+yM9vV4/FAVN9owbIa0oyRQe5tDTnkbkAA9il7pJY RUPu1fPQPfi3L0YG6Ai8cPyfzZiigq0GuAua1a4gX4sV3ze3DMWIQDjXUteRnUfMbtxT 8awQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=whQqnslZ; 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 bi20si385575edb.462.2021.06.08.11.52.24; Tue, 08 Jun 2021 11:52:47 -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=whQqnslZ; 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 S236152AbhFHSt5 (ORCPT + 99 others); Tue, 8 Jun 2021 14:49:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:44090 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235778AbhFHSpC (ORCPT ); Tue, 8 Jun 2021 14:45:02 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8BCEB613AC; Tue, 8 Jun 2021 18:36:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623177413; bh=Yl7IPL85YzCd2CUddMcgindgnXZi0j50a/KS615JKeo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=whQqnslZcSy6+dRw4ElvTaVfIuOfoYnXplSeMkTyeii3pT91n/QfQOFZUpnE3ku6t ZXzNMnDRmtUvRVYsRBfpFuavHJdooPJdzDkKDMFN112bHUKXg0duMW4szzG2b9p9cL KAQR06no0FWLjX/gw5xM2ac1qr9VvEAZ7P7KUkR8= 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 5.4 43/78] net: caif: fix memory leak in cfusbl_device_notify Date: Tue, 8 Jun 2021 20:27:12 +0200 Message-Id: <20210608175936.713580543@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210608175935.254388043@linuxfoundation.org> References: <20210608175935.254388043@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 @@ -115,6 +115,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), }; @@ -127,6 +132,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 && @@ -169,8 +175,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; @@ -178,6 +187,9 @@ static int cfusbl_device_notify(struct n strlcpy(layer->name, dev->name, sizeof(layer->name)); return 0; +err: + cfusbl_release(link_support); + return res; } static struct notifier_block caif_device_notifier = {