Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1464226pxb; Mon, 11 Oct 2021 06:37:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz9taNdBRw3OoE8z72UcQwLw8CNivrdZOvpI2kWO03/oSDmKZ7zCQR0hN+SjEF4aD06zJMq X-Received: by 2002:a17:906:c005:: with SMTP id e5mr25499966ejz.480.1633959421753; Mon, 11 Oct 2021 06:37:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633959421; cv=none; d=google.com; s=arc-20160816; b=BGAu4S79muxP4020TuOpXlYn3vbTebD/9SdswIKPJGI4wHUlWp/5rXVqfkVlLdpCUq 74AjONvllPGpoPgD5/d5k8ygNmTfqARKXnv1ys23dFXx7zIjzS/RRpCTrHkDOcoKBfq1 NZW8IHUpZS13M4ZGq5QjlfUsfkLku5Ta+miI7PnkRolQ+91r6j6pySMk9cltef2HLxx0 4Dgh3RrTRAYg/64hlH5IdGcr+fxqPx0my0DXBJ1HAAEOKLCEem/Wf7Rj43fyLzjXk+3d 7A6zrFT8P8P0WMhxjqlIYl2qTJ7FwYGNWKquHPCAf+UfL3237AzFIv7Aiopcsy5Bceeh +QUA== 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 :message-id:date:subject:cc:to:from; bh=2unZ6PRQufKfA6eSdvXGnlXypzhzKz8D4dCrCSi1WKo=; b=bxR79xk1bKpjaznQAm6mdMo4zeo96jBth2ssS4XlPn/y7Wo/sFPqtCI3IJwgHvSK1z hppElrzPF23+psUc3r/uEcMTRD6NaNs5ACum6Bzu6ha+9CqqGXe5P2P3Q+yImAcQk6k1 C/sJI96t5XWjefItLYwBVX/5zVaGw+wW+dk1T9QbppN6HIqX+drlNjMOHGCT2GIl4ntk PSpIrIRT+XBY+SEZQl0MDvXcMdHgv1wrT93mxKdvyX/aOkwNHlhn6wT8/ykFco3In52F h93WiW2uTVKotbKwn5dsnCPtnU5Xw0CfD1FMGbEAYSyVIBIBmUT3ZNjSr1AhUrs3uMcQ ZV/Q== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id nd29si7010406ejc.75.2021.10.11.06.36.36; Mon, 11 Oct 2021 06:37:01 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235990AbhJKLDK (ORCPT + 99 others); Mon, 11 Oct 2021 07:03:10 -0400 Received: from szxga08-in.huawei.com ([45.249.212.255]:25119 "EHLO szxga08-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235971AbhJKLDI (ORCPT ); Mon, 11 Oct 2021 07:03:08 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4HSbQq5nBPz1DHYp; Mon, 11 Oct 2021 18:59:31 +0800 (CST) Received: from dggpemm100009.china.huawei.com (7.185.36.113) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Mon, 11 Oct 2021 19:01:06 +0800 Received: from huawei.com (10.175.113.32) by dggpemm100009.china.huawei.com (7.185.36.113) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Mon, 11 Oct 2021 19:01:05 +0800 From: Liu Shixin To: Mauro Carvalho Chehab CC: , , Liu Shixin Subject: [PATCH] media: lm3560: prevent memory leak of v4l2_ctrl_handler Date: Mon, 11 Oct 2021 19:39:15 +0800 Message-ID: <20211011113915.2646960-1-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm100009.china.huawei.com (7.185.36.113) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If lm3560_subdev_init() or lm3560_init_device() failed, lm3560_probe() will directly return without free v4l2_ctrl_handler, which results memory leak: unreferenced object 0xffff8881ea566e00 (size 256): comm "xrun", pid 396, jiffies 4294949372 (age 80.376s) hex dump (first 32 bytes): d8 82 81 4d 81 88 ff ff 00 4c 56 ea 81 88 ff ff ...M.....LV..... 10 6e 56 ea 81 88 ff ff 10 6e 56 ea 81 88 ff ff .nV......nV..... backtrace: [<0000000055d4bb48>] __kmalloc_node+0x198/0x330 [<00000000e3b57405>] kvmalloc_node+0x65/0x130 [<0000000061e6063e>] v4l2_ctrl_new+0x820/0x1d40 [videodev] [<00000000d7174c1b>] v4l2_ctrl_new_std+0x1d5/0x2b0 [videodev] [<00000000cefb1a26>] lm3560_subdev_init+0x374/0x5e0 [lm3560] [<00000000cda4c495>] lm3560_probe+0x1c2/0x61a [lm3560] [<00000000d9502788>] i2c_device_probe+0xa07/0xbb0 [<00000000a5e908d0>] really_probe+0x285/0xc30 [<000000002fee9400>] __driver_probe_device+0x35f/0x4f0 [<0000000025fd5e96>] driver_probe_device+0x4f/0x140 [<00000000d37732ef>] __device_attach_driver+0x24c/0x330 [<000000001e0f0dfd>] bus_for_each_drv+0x15d/0x1e0 [<00000000c6c72d57>] __device_attach+0x267/0x410 [<000000005f7e4b8c>] bus_probe_device+0x1ec/0x2a0 [<000000001c3d09f6>] device_add+0xc1c/0x1d50 [<00000000cddb870a>] i2c_new_client_device+0x614/0xb00 Fixes: 7f6b11a18c30 ("[media] media: i2c: add driver for dual LED Flash, lm3560") Reported-by: Hulk Robot Signed-off-by: Liu Shixin --- drivers/media/i2c/lm3560.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/media/i2c/lm3560.c b/drivers/media/i2c/lm3560.c index 9e34ccce4fc3..8d2e224c725b 100644 --- a/drivers/media/i2c/lm3560.c +++ b/drivers/media/i2c/lm3560.c @@ -432,15 +432,22 @@ static int lm3560_probe(struct i2c_client *client, rval = lm3560_subdev_init(flash, LM3560_LED1, "lm3560-led1"); if (rval < 0) - return rval; + goto free_led0; rval = lm3560_init_device(flash); if (rval < 0) - return rval; + goto free_led1; i2c_set_clientdata(client, flash); return 0; + +free_led1: + v4l2_ctrl_handler_free(&flash->ctrls_led[LM3560_LED1]); +free_led0: + v4l2_ctrl_handler_free(&flash->ctrls_led[LM3560_LED0]); + + return rval; } static int lm3560_remove(struct i2c_client *client) -- 2.25.1