From patchwork Thu Feb 1 12:48:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhipeng Lu X-Patchwork-Id: 195305 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2719:b0:106:209c:c626 with SMTP id hl25csp123804dyb; Thu, 1 Feb 2024 04:49:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IFPbRhNmDlFvi0IM/ENuVh4N9LdK6xM7SU8ymcgRTQv080y2wjd1x6CHS/9/GChN4yrSlTT X-Received: by 2002:ad4:5f0c:0:b0:68c:4caa:dd1e with SMTP id fo12-20020ad45f0c000000b0068c4caadd1emr6174108qvb.6.1706791785551; Thu, 01 Feb 2024 04:49:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706791785; cv=pass; d=google.com; s=arc-20160816; b=wtb/MABYDstCk52Vf/ppz6JDlYzQqc7IZn09P6ozk+4l/HvvUNArITUHogjlx1PFNB Djp6Rgcde0Wyt377IoPyeMRLsjhLjjdKJ5trl2sbPgwxW0V2/r5nG/wycSn2tqK+piDU ZsjH779+r3aoTIz7m8BRZ/6DKBQeDAajGLyN7R/42oqNeUdLD/hnQsx2wlYoOAKZWt6o Xj+8KORWiX2gD4b3WFK3zXHcuL5KhCiow6QSeNYZ+sFUOW1xvi32RdJ6FBlXdEbQPrSz uTEwBODF0U9aUh9VdRr8RXdSo1Dr7QJ2KDop5L1nHDPcjwJed727qgGXotVby0GYmHcQ fJMQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=clPdPqUlnaI5ZM6K+qQeuibdfDMeAtflFlc2LWWOVPs=; fh=KA5qffJDZq9GNV/Q9WzGW5mQFbOCX3HjRPcih7CJO/E=; b=rB1TZmjBPekK+8bha0lhNxHURwiytv5qQTesQIT8+WY9v2gevCydd/QeDl2brZkWT3 7drjosgqEHT+zJdduq9uA8SpTCgbcyzAkiZXKEgcaiHKLumQ4+nkHmYr7gpOp5qsyAsO /Csoy1U+tEPaBH4Wkb5Wqgw+qGG/ZObSSu2iWLHUAaVS3PePwYHW/DVU/lwvanXkpYsQ krxgMXZud0KYvEsq9vZEFffGJ7jKGpuJZJoUGoTRspBGJ7NX5xBqsIUT3KBPmzMU/OvG tOPhZt7HvHOaOgLzu5ExxhVgEfjj7VsLY7vEanXdUDIUiOwsfEp04A1XkW7H/Aj3yJWS juwA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=zju.edu.cn); spf=pass (google.com: domain of linux-kernel+bounces-48159-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48159-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUDaJ+9kf0HvRH5NsAAqdA3nLjDcUx7U7meZd74RLBxpPRlceRRgI0hKIZ7tYGjLatVJEBArN3AczNUUx/ZH3M1Lc0i/A== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id b2-20020a0ce882000000b0068c7bfeb4c3si1033735qvo.89.2024.02.01.04.49.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 04:49:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-48159-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=zju.edu.cn); spf=pass (google.com: domain of linux-kernel+bounces-48159-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48159-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 533391C27F14 for ; Thu, 1 Feb 2024 12:49:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6E7C24D9E9; Thu, 1 Feb 2024 12:49:28 +0000 (UTC) Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net (zg8tmtyylji0my4xnjqumte4.icoremail.net [162.243.164.118]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C9BBA8663F; Thu, 1 Feb 2024 12:49:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.243.164.118 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706791766; cv=none; b=OiU7qJF8akDwINMo/YHNUOr65PQYi/OJwNyJ12GV1b5Z0Bs5B++vCFxxuwxIGPpjr9VfwOQIzcXSFmv++zAl/bLpN27WBuCkagrzfCmXUcKqsD/hcudeeDNU/jMhHGXJ+9zaY10eNiHmQ37g8ejM+bE+oQ/DtI8BIJo72xJUai8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706791766; c=relaxed/simple; bh=Yi8Yp0mra6HVN4MohQAem1CrTDUOAi3hKvHb8V/rYVg=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=AIgTFWQAyAeJkT2ttOW6+6ARxwVQzlQHwGQTAmdKVWi1120AozIO59XrCoDIC7RwHdO/9/RjV7QBo9OyE91L+qa7EbcOOyck82pRidF2DkSyWRrSyc/hS4NuHEyqDGnJ9GY4B1v/gYGj4z95mWhhJJBgDEp1GatUh/dxqbtDJWc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zju.edu.cn; spf=pass smtp.mailfrom=zju.edu.cn; arc=none smtp.client-ip=162.243.164.118 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zju.edu.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zju.edu.cn Received: from luzhipeng.223.5.5.5 (unknown [183.128.135.43]) by mail-app2 (Coremail) with SMTP id by_KCgDXGqpDk7tl6tQxAQ--.4622S2; Thu, 01 Feb 2024 20:49:07 +0800 (CST) From: Zhipeng Lu To: alexious@zju.edu.cn Cc: Mauro Carvalho Chehab , Hans Verkuil , Ezequiel Garcia , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] media: v4l2-mem2mem: fix a memleak in v4l2_m2m_register_entity Date: Thu, 1 Feb 2024 20:48:44 +0800 Message-Id: <20240201124846.3054579-1-alexious@zju.edu.cn> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: by_KCgDXGqpDk7tl6tQxAQ--.4622S2 X-Coremail-Antispam: 1UD129KBjvdXoWrKw4rWryrJFy3AF45KF48JFb_yoWkAFg_uF s7uFnxWF1UKw43G3WUK395Z340ga9Fqrn3Ga13tF43tFy5JasxtFWDZrn8X397WF17A3sx Crn8WrWfCF1jkjkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbskFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8w A2z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j 6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oV Cq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0 I7IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r 4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY1x0262kKe7AKxVWU AVWUtwCY02Avz4vE14v_Xr1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr 1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE 14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7 IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E 87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73Uj IFyTuYvjfU0FApUUUUU X-CM-SenderInfo: qrsrjiarszq6lmxovvfxof0/ X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789700903327576803 X-GMAIL-MSGID: 1789700903327576803 The entity->name (i.e. name) is allocated in v4l2_m2m_register_entity but isn't freed in its following error-handling paths. This patch adds such deallocation to prevent memleak of entity->name. Fixes: be2fff656322 ("media: add helpers for memory-to-memory media controller") Signed-off-by: Zhipeng Lu --- drivers/media/v4l2-core/v4l2-mem2mem.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-mem2mem.c b/drivers/media/v4l2-core/v4l2-mem2mem.c index 0cc30397fbad..8db9ac9c1433 100644 --- a/drivers/media/v4l2-core/v4l2-mem2mem.c +++ b/drivers/media/v4l2-core/v4l2-mem2mem.c @@ -1084,11 +1084,17 @@ static int v4l2_m2m_register_entity(struct media_device *mdev, entity->function = function; ret = media_entity_pads_init(entity, num_pads, pads); - if (ret) + if (ret) { + kfree(entity->name); + entity->name = NULL; return ret; + } ret = media_device_register_entity(mdev, entity); - if (ret) + if (ret) { + kfree(entity->name); + entity->name = NULL; return ret; + } return 0; }