Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1908464rdb; Tue, 3 Oct 2023 05:06:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG41kZq/Bg8J9TaKBUOYjKcjmq0NwERuLszT60HSHjJ2JzrJciqpEGNjh9ELIAmFRmfGhJY X-Received: by 2002:a05:6a21:1f08:b0:13f:1622:29de with SMTP id ry8-20020a056a211f0800b0013f162229demr10815794pzb.7.1696334769621; Tue, 03 Oct 2023 05:06:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696334769; cv=none; d=google.com; s=arc-20160816; b=Mfrotx8a6TGFJTr75BL519NAK5aCeyqrD1aBi36V1YBUoE8766iKKXD6DP7OrnhYex ehmWTKZU2U0G1CyPk5SHhWdbRFrQ4YOlJ5cdEzLwIWyBJlHHo8hvf1c7gQu1mTHe4wuw rNiVwmTWyJDU8dJWShbMWTs3ANy+bqkCx22j4WeqPHRrUw+YjDq1NvSs1QSaBYt+7uXD AaXdviPLXTcHLWMV5bH0N/AMDktpTxH2ZTgQTXQnEGpyOt5EZYMz+KfNrwZc3wApt6qw qat0E0No/Vs4z5aKv3ZV2J4L3q5lN3VXy2FuirloWLgVtKVD4uaQONYykxgx0viRbO5s fwsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature; bh=0SH57+6g9hnw1l3LrZ4BWAR5LEJwEkJP03anBQryaEo=; fh=rkPbqiAzS6gvKaEIztoJnH3RkwEY7W9UHr8Jz2WiWYc=; b=o3xz5kCyyt8xSb0ODGsk6ywOnD+lJgFC8qq5nYC9TCKWSa6kTUxPY88k5BMpBIvBHx qXb8Ppf88Q9VBtwxI7wQTsmQ3JwblAZW6DCv+VVXG/lIq4sCo/O0U5mts5EfN4j9ua4b 2s/F00i560fgv069crU0JuAqnESRJAUtoOeBl+wxcHojuXB59rRlPzhiWyZofQg/e+1R IhV3GTB7l4CYC6n6vqM/ARvmvEjRnafgdbf2ZSfoftZsY2yM9ERuUlaenDwyqoEB1K3d yK2EpbZYIlFAhkm+C9GXwELaFGS/6dyFXqTd7J0Ov/qgs3fzMC2YAsWAQk4/DkR+8XA1 6EKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hy6FhSqV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id b130-20020a633488000000b0058599cadbacsi1330491pga.258.2023.10.03.05.06.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 05:06:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hy6FhSqV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 266D480AEE3A; Tue, 3 Oct 2023 05:06:01 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232058AbjJCMF5 (ORCPT + 99 others); Tue, 3 Oct 2023 08:05:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231946AbjJCMFz (ORCPT ); Tue, 3 Oct 2023 08:05:55 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65665B0; Tue, 3 Oct 2023 05:05:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696334752; x=1727870752; h=date:from:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=2FVL6oK6St+5P80WJ+yzirfeEardVkYw1NDRImd/gVM=; b=hy6FhSqVPGJW2GTaOqs59afYeTh+sNqjm09T7xMNL7Xt/FD6CSW/YF1a N2Jmni6DBeC6CR1tXVa0epbhNAVS8WJIteMt1KOBFNHnHTxmBHuitkDZQ zruieOvmqBhJ5ZyZTfwW8ugs3E8ta40rRpkke5g0UV1BX4dMh3t4JA82a 2DKo/MWOAHocUENldcgBIm7c19wzwEUJsQtEiWAZUWLDbTznAQo+OxL4W vDI3AWaqUZ+/oRPwlffxQ4CnIUd8pqfH80s8zlfp1aqG0N/PKE5pyZOIT 4ytUG9PCxoJ+XAWapjPjjJomKbC7xLDhtvJ5jUy/iCQaWn4PTsAsUC048 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10851"; a="449347037" X-IronPort-AV: E=Sophos;i="6.03,197,1694761200"; d="scan'208";a="449347037" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Oct 2023 05:05:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10851"; a="727589592" X-IronPort-AV: E=Sophos;i="6.03,197,1694761200"; d="scan'208";a="727589592" Received: from tciutacu-mobl.ger.corp.intel.com (HELO rrabie-mobl.amr.corp.intel.com) ([10.252.40.114]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Oct 2023 05:05:47 -0700 Date: Tue, 3 Oct 2023 15:05:45 +0300 (EEST) From: =?ISO-8859-15?Q?Ilpo_J=E4rvinen?= To: Christophe JAILLET cc: Vadim Pasternak , Hans de Goede , Mark Gross , Michael Shych , LKML , kernel-janitors@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: Re: [PATCH] platform: mellanox: Fix a resource leak in an error handling path in mlxplat_probe() In-Reply-To: <8bd0a7944f0f4f1342333eaf8d92d8e9d5623110.1696141233.git.christophe.jaillet@wanadoo.fr> Message-ID: <7d966897-56b5-4a53-3b75-dd90072e17@linux.intel.com> References: <8bd0a7944f0f4f1342333eaf8d92d8e9d5623110.1696141233.git.christophe.jaillet@wanadoo.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 03 Oct 2023 05:06:01 -0700 (PDT) On Sun, 1 Oct 2023, Christophe JAILLET wrote: > If an error occurs after a successful mlxplat_i2c_main_init(), > mlxplat_i2c_main_exit() should be called to free some resources. > > Add the missing call, as already done in the remove function. > > Fixes: 158cd8320776 ("platform: mellanox: Split logic in init and exit flow") > Signed-off-by: Christophe JAILLET > --- > This patch is based on comparison between functions called in the remove > function and the error handling path of the probe. > > For some reason, the way the code is written and function names are > puzzling to me. Indeed, pre/post are mixed up for init/exit variants which makes everything very confusing and the call to mlxplat_post_init() is buried deep into the call chain. These would seem better names for the init/deinit with proper pairing: - ..._logicdev_init/deinit for FPGA/CPLD init. - ..._mainbus_init/deinit - perhaps the rest could be just ..._platdevs_reg/unreg Those alone would make it much easier to follow. In addition, - mlxplat_i2c_mux_complition_notify() looks just useless call chain level and should be removed (it also has a typo in its name). - Maybe ..._platdev_reg() (currently mlxplat_post_init()) should be called directly from mainbus_init() or even from .probe() and not from the mux topo init. > So Review with care! It does not look complete as also mlxplat_i2c_main_init() lacks rollback it should do it mlxplat_i2c_mux_topology_init() failed. Since currently mlxplat_i2c_main_init() is what ultimately calls mlxplat_post_init() deep down in the call chain (unless the call to it gets moved out from there), it would be appropriate for mlxplat_i2c_main_exit() to do/call the cleanup. And neither .probe() nor .remove() should call mlxplat_pre_exit() directly in that case. So two alternative ways forward for the fix before all the renaming: 1) Move mlxplat_post_init() call out of its current place into .probe() and make the rollback path there to match that. 2) Do cleanup properly in mlxplat_i2c_main_init() and mlxplat_i2c_main_exit(). I'd prefer 1) because it's much simpler to follow the init logic when the init components are not hidden deep into the call chain. -- i. > --- > drivers/platform/x86/mlx-platform.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/drivers/platform/x86/mlx-platform.c b/drivers/platform/x86/mlx-platform.c > index 3d96dbf79a72..64701b63336e 100644 > --- a/drivers/platform/x86/mlx-platform.c > +++ b/drivers/platform/x86/mlx-platform.c > @@ -6598,6 +6598,7 @@ static int mlxplat_probe(struct platform_device *pdev) > fail_register_reboot_notifier: > fail_regcache_sync: > mlxplat_pre_exit(priv); > + mlxplat_i2c_main_exit(priv); > fail_mlxplat_i2c_main_init: > fail_regmap_write: > fail_alloc: >