Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3718790pxb; Mon, 24 Jan 2022 16:14:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJxjUquCkevP6HjlwO0nSiJgwpJ3PzLtkaT/Llj9lCXBGRTWBkoscqVFFkPrQrR328wu7pfZ X-Received: by 2002:a17:90a:f982:: with SMTP id cq2mr826688pjb.36.1643069665210; Mon, 24 Jan 2022 16:14:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643069665; cv=none; d=google.com; s=arc-20160816; b=vZ0iTLzN8fr/o2y3xdGdCXrW6Ml0cXviKPkjp1hp+Ers5BgRrpOG2+1YclCyykaLZi 6Jh+MLOEdDfCeodcanbU7vAkbjiXNJ6Ctm65cIexC7EXfRzwCuckMcNx6AvOOGSCjNu0 1Svi8J37tQEAvee9e1a9qPiKRx2EClVTTeenNuD4zJYOf0BQ0vO2iy0lx7F4Hd1rBipV OsYlQULMzsJessigg+45Nobx1tyAER1b/hxjnetAlkqsqxsiyiBAuKZ586BsRzTL5sec GZcg+Educ16ioBQboRcECp5xo3Kqi650IfeVLEomN8bJlHUpmBrRI663yoTUJSxpyiyc j/FQ== 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=dNdPpu4gF5G2kR9pMYQDe1i7u0xbmhsDTv3Ln1HFRqw=; b=WrnTb+FRwSbjI2baG7Qyv1ZS7d+E04kjDqlJ478xS54zYiKXYTI4p0GmZx+68cXBpl Vud1pm8rpnb8z4zpBau7qNRlAR9BCzVaAWjs7v9tYvfZKLHgCN6oI1vsnJkumVfeziyk PbeUZ5O9j0LWIylrbZVCzOVBuoN857HKp6qeZ4ExC/LCDQ+Uk8p1HM5UsGLuTDdyuBOU L2HmQ+V0aD/f/0DRjuX6nla4yqvWcrT7tGWCIfAUuz0h4syLV4zCxdnuI1xRzkbGpt1m 62mXjdX2u2Alp8RtITXKZ8+cjmVQM3jKQgDoiab4TQn0sDeG8klHTfZDZhBdxbrqjJLL J2VA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=om49342W; 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 ij15si12422259plb.239.2022.01.24.16.14.13; Mon, 24 Jan 2022 16:14:25 -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=om49342W; 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 S2372041AbiAYAK2 (ORCPT + 99 others); Mon, 24 Jan 2022 19:10:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353848AbiAXWlo (ORCPT ); Mon, 24 Jan 2022 17:41:44 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 566FBC04D63D; Mon, 24 Jan 2022 13:04:59 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 1E610B81057; Mon, 24 Jan 2022 21:04:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 58A5FC340E5; Mon, 24 Jan 2022 21:04:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643058296; bh=0jacikwTIJ8ekpPO0T6TP7Ryl+hPhvGeAirLDHLFhi0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=om49342WxKRfZk3S5Ibmid3vseHt82qsNzlNPnVMh+htL5ivNigBiyXffnU8vUDXq ey+c37AFop8ObGMfjZpbua8h6B1w6OHtAUb5LLAPQQkYoMa3jpQQiNeVuUNj3yi0QV IKj+VDyTasR6MpcjVI8K6adwxXrATfv/Kk0LyEs0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Colin Ian King , Ricardo Ribalda , Laurent Pinchart , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 5.16 0244/1039] media: uvcvideo: Fix memory leak of object map on error exit path Date: Mon, 24 Jan 2022 19:33:53 +0100 Message-Id: <20220124184133.523951292@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@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: Colin Ian King [ Upstream commit 4b065060555b14c7a9b86c013a1c9bee8e8b6fbd ] Currently when the allocation of map->name fails the error exit path does not kfree the previously allocated object map. Fix this by setting ret to -ENOMEM and taking the free_map exit error path to ensure map is kfree'd. Addresses-Coverity: ("Resource leak") Fixes: 70fa906d6fce ("media: uvcvideo: Use control names from framework") Signed-off-by: Colin Ian King Reviewed-by: Ricardo Ribalda Signed-off-by: Laurent Pinchart Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/usb/uvc/uvc_v4l2.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index f4e4aff8ddf77..711556d13d03a 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -44,8 +44,10 @@ static int uvc_ioctl_ctrl_map(struct uvc_video_chain *chain, if (v4l2_ctrl_get_name(map->id) == NULL) { map->name = kmemdup(xmap->name, sizeof(xmap->name), GFP_KERNEL); - if (!map->name) - return -ENOMEM; + if (!map->name) { + ret = -ENOMEM; + goto free_map; + } } memcpy(map->entity, xmap->entity, sizeof(map->entity)); map->selector = xmap->selector; -- 2.34.1