From patchwork Sun Mar 26 09:27:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Chen X-Patchwork-Id: 75034 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp844537vqo; Sun, 26 Mar 2023 02:37:46 -0700 (PDT) X-Google-Smtp-Source: AKy350bVhnjGVitWAAv9Mlc9c5MGxlaXE1/AJKXERX3w6OEyC4j/IhYo2rmd3jiSUn6yXd278+4v X-Received: by 2002:a17:907:9841:b0:8aa:1f89:122e with SMTP id jj1-20020a170907984100b008aa1f89122emr8624781ejc.39.1679823465883; Sun, 26 Mar 2023 02:37:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679823465; cv=none; d=google.com; s=arc-20160816; b=obqpu4gqmL7tDL4VGMtgBe+6OF8eggYgaymaa4g0I+V8V/Dp89PtOHoo+6IxrS7qut FfCKwtJBApoI7JGxdZRYZ1Zb5BG5MHLUYWJCpgbJJvJqtG/0my9Udw0Y5IWnIFXF+VvW XPWA66qHlSWn7cJ/xmetLj5NuLTAoaLAtSyEpL737ohOciNI3pdL21XzRlHh1+FFh4Ej HoXjj65YEQzQ54qACL5m2f5fipe/Vt2qEbjW/4jhTFqzu2mUHKgULUUOxsJ7eeXS4JPB aUAYk/JfFeS4y0cJDnB8m/VLPJwtgZe//pO2xNI27PWBin2c4bXWewQiiMxm5mjHo/Lh M6lQ== 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:dkim-signature; bh=i9Wz9FA6K66dH4iQn0+o/IUAerAr/7nO1FAUqwypmmc=; b=Ty2xi77BXE8wVkUP5B5QcOmd4TJRHCMIZdBIimkwCK/S1x5PqU61204fceb+xiHjLP AF0tOXJSq8MMEEKexz/a4AO5AgxzoSfZzmAtdvtZg7Cec6m6/4tq4QLs9I50KEeD58jn NbXKO4BpJd0BdcmVTGVuUGRMSuymgFwqKTeN0Fg/mfzV22X5Zmw2eyyKLBSSrvp0T69e cAi9BQoO2HePfzgljb+TEGOai8AApzDRL/G68DMUbDodIl9J8kXVY6/sm4Of4CmuvJCz u412MrlT+Id/VKYRly+jLKxq3y8+hUtckha3oxvLQDDTW93rXlghVGoZo894KS4557Qx gQIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Zy2mEILs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hr36-20020a1709073fa400b00932b2915d60si31823542ejc.681.2023.03.26.02.37.22; Sun, 26 Mar 2023 02:37:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Zy2mEILs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232152AbjCZJ1e (ORCPT + 99 others); Sun, 26 Mar 2023 05:27:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231905AbjCZJ1V (ORCPT ); Sun, 26 Mar 2023 05:27:21 -0400 Received: from mail-oa1-x2c.google.com (mail-oa1-x2c.google.com [IPv6:2001:4860:4864:20::2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E6DB1B6; Sun, 26 Mar 2023 02:27:20 -0700 (PDT) Received: by mail-oa1-x2c.google.com with SMTP id 586e51a60fabf-177ca271cb8so6337369fac.2; Sun, 26 Mar 2023 02:27:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679822840; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=i9Wz9FA6K66dH4iQn0+o/IUAerAr/7nO1FAUqwypmmc=; b=Zy2mEILszn1VXZ4Ywhouk3Rno3vyq78tnWi1nySuIR3RStvomuHO64quO85ROT7ohY 9VYpO66eMjykYlEGCLvBT5De+qYze0Wg9xdV5/DFXE6B/mWliyqHK5OYKXbYB0gCN/qV LThdm3e/IqswUt9DVAfFVHJBJQK2T/LOqaAUHuIunGRYoGgC654xRC7PEdBg7WN4ILPk tdY14TILf6e9KcVQDi/JY7KBePLRxoCZCFgk+WWd4DFvu+ELMeBJnknY656vIulZhNkY I5WJWsPhlsgnnsqvhKOEve/G6i7LSMWM6U3LWvBqL8xucrd5mRkMUnn1rw7aoMty8XT7 v4Jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679822840; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=i9Wz9FA6K66dH4iQn0+o/IUAerAr/7nO1FAUqwypmmc=; b=GBPW3CTejVqlIPPJll4kor0TnnmVgi32c42aid50d7G8B5kTd96wVALQmLXghH6a5U RimusjJN2d+7bqcBlHu32DRTgGoEwDGtLA/aEiyCxabdXAZvEzewKG59VHQLzhPPIGeA fvrRe34cRfXmyZa/0v0gzXKd95Y076AZHCQftjbWoxqQT4kEDhQIbv39xQWTr5fgzvrW qu1JQyUptKDwjaHkLORXFoLtdgj62v/x+JC4kToy3uTgkUeWIk2qz+z7/kxBNu7f1ary mIMyOA8kiEoxFC6zsFh2sMt0lTb0bVKyOilcbZlAgGm/xjaVVN/BXFw263PGMwKVXEtH f94g== X-Gm-Message-State: AAQBX9cJ3b3o9sfZ4VgaERHq2/NcpK6z/OHwdg9ofb7+5uaTdFB5MI2z tVctDTW1OIJI9/1CT01LqpM= X-Received: by 2002:a05:6870:f154:b0:177:a1ab:8c53 with SMTP id l20-20020a056870f15400b00177a1ab8c53mr5766544oac.12.1679822839849; Sun, 26 Mar 2023 02:27:19 -0700 (PDT) Received: from chcpu13.cse.ust.hk (191host119.mobilenet.cse.ust.hk. [143.89.191.119]) by smtp.gmail.com with ESMTPSA id v10-20020aca610a000000b003848dbe505fsm10068303oib.57.2023.03.26.02.27.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Mar 2023 02:27:19 -0700 (PDT) From: Wei Chen To: martink@posteo.de Cc: mchehab@kernel.org, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Wei Chen Subject: [PATCH v2] media: hi846: Fix memleak in hi846_init_controls() Date: Sun, 26 Mar 2023 09:27:12 +0000 Message-Id: <20230326092712.139791-1-harperchen1110@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Spam-Status: No, score=0.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761422570469220474?= X-GMAIL-MSGID: =?utf-8?q?1761422570469220474?= hi846_init_controls doesn't clean the allocated ctrl_hdlr in case there is a failure, which causes memleak. Add v4l2_ctrl_handler_free to free the resource properly. Signed-off-by: Wei Chen Reviewed-by: Martin Kepplinger --- Changes in v2: - move v4l2_ctrl_handler_free to error tag - handle memleak in other failure positions drivers/media/i2c/hi846.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/media/i2c/hi846.c b/drivers/media/i2c/hi846.c index 7c61873b7198..f86997a261f5 100644 --- a/drivers/media/i2c/hi846.c +++ b/drivers/media/i2c/hi846.c @@ -1472,21 +1472,26 @@ static int hi846_init_controls(struct hi846 *hi846) if (ctrl_hdlr->error) { dev_err(&client->dev, "v4l ctrl handler error: %d\n", ctrl_hdlr->error); - return ctrl_hdlr->error; + ret = ctrl_hdlr->error; + goto error; } ret = v4l2_fwnode_device_parse(&client->dev, &props); if (ret) - return ret; + goto error; ret = v4l2_ctrl_new_fwnode_properties(ctrl_hdlr, &hi846_ctrl_ops, &props); if (ret) - return ret; + goto error; hi846->sd.ctrl_handler = ctrl_hdlr; return 0; + +error: + v4l2_ctrl_handler_free(ctrl_hdlr); + return ret; } static int hi846_set_video_mode(struct hi846 *hi846, int fps)