From patchwork Tue Aug 23 07:21:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Verma, Vishal L" X-Patchwork-Id: 12951793 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 126ECC32774 for ; Tue, 23 Aug 2022 07:21:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240547AbiHWHVX (ORCPT ); Tue, 23 Aug 2022 03:21:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240654AbiHWHVV (ORCPT ); Tue, 23 Aug 2022 03:21:21 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CDC061D9D for ; Tue, 23 Aug 2022 00:21:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661239281; x=1692775281; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5Jo0M7JLkpca4mmJEMDx0p2jux4rGpK3VNeWC/VQ7yw=; b=mYuFdwQihnYljvhv+bb5DLFNeIia7h5a++QCraj6XQmIk4023P6NmrZX lsYCvQXm/SOpvxzXMyeujM4/S2R20GgohfcxSU0X8XkLLAKU1QMDkCtAw S7pgD9ARjl49+c0nxxzvEgmoDyj+sK9Qsr4U+HfCiBeIXvHcbZLeiYnsO cLuuB3bmBV2uV0EONLh0HiOcR7Ipbqj3AHn2q9+pU9+tr1ydU5SRbeC0o egOTMgT6lc/ejFT3DUxBrg1o/27H6iZJ1K+fYaA5tDm8ibaQcODs1Y0OI 6cqz5y4YWryrDcusDKYoe42yjf7qdQD5gDllQeeL+Wl4APhocPUNOo06s Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10447"; a="273366244" X-IronPort-AV: E=Sophos;i="5.93,256,1654585200"; d="scan'208";a="273366244" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Aug 2022 00:21:10 -0700 X-IronPort-AV: E=Sophos;i="5.93,256,1654585200"; d="scan'208";a="735388584" Received: from skummith-mobl1.amr.corp.intel.com (HELO vverma7-desk1.intel.com) ([10.212.54.206]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Aug 2022 00:21:10 -0700 From: Vishal Verma To: Cc: , Dan Williams , Vishal Verma Subject: [ndctl PATCH 1/3] cxl/region: fix a dereferecnce after NULL check Date: Tue, 23 Aug 2022 01:21:04 -0600 Message-Id: <20220823072106.398076-2-vishal.l.verma@intel.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823072106.398076-1-vishal.l.verma@intel.com> References: <20220823072106.398076-1-vishal.l.verma@intel.com> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=883; h=from:subject; bh=5Jo0M7JLkpca4mmJEMDx0p2jux4rGpK3VNeWC/VQ7yw=; b=owGbwMvMwCXGf25diOft7jLG02pJDMks9Q/vFNl6f34hmd2mvmcNY2JsUeXKykN/+idtltedUO/F e+haRykLgxgXg6yYIsvfPR8Zj8ltz+cJTHCEmcPKBDKEgYtTACYScJrhD9+ehh/CqvfVONjkfbT3st 1INxBqdxd6cHprX0v6a6HTqQz/PWtf5HlzJDyfJx/1Sr9IybKqQDe3uudrmNM0AYdtLvlMAA== X-Developer-Key: i=vishal.l.verma@intel.com; a=openpgp; fpr=F8682BE134C67A12332A2ED07AFA61BEA3B84DFF Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org A NULL check in region_action() implies that 'decoder' might be NULL, but later we dereference it during cxl_decoder_foreach(). Since cxl_decoder_foreach() won't ever enter the loop with a NULL decoder, the check was superfluous. Remove it. Cc: Dan Williams Signed-off-by: Vishal Verma --- cxl/region.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/cxl/region.c b/cxl/region.c index a30313c..9372d6b 100644 --- a/cxl/region.c +++ b/cxl/region.c @@ -688,8 +688,6 @@ static int region_action(int argc, const char **argv, struct cxl_ctx *ctx, cxl_decoder_foreach (port, decoder) { decoder = util_cxl_decoder_filter(decoder, param.root_decoder); - if (!decoder) - continue; rc = decoder_region_action(p, decoder, action, count); if (rc) err_rc = rc; From patchwork Tue Aug 23 07:21:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Verma, Vishal L" X-Patchwork-Id: 12951792 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD794C32789 for ; Tue, 23 Aug 2022 07:21:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240646AbiHWHVW (ORCPT ); Tue, 23 Aug 2022 03:21:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240547AbiHWHVV (ORCPT ); Tue, 23 Aug 2022 03:21:21 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA18161D94 for ; Tue, 23 Aug 2022 00:21:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661239280; x=1692775280; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=L8XrefDPQMXBCMvyyrEG92ZKAXZ8Ao9a9bnYvHgSICM=; b=UCXyJ6/0U1ZfbA2AFjpWa3m7RI+GkKzNSzxLodza/Puo6T8sD7NqfXna 1L0gjMruN9UXyYiGkIm35AaDFZumocnSxHErBZ+XlWzzLs3WNbyV5lx88 lyTRy9gq3rSNGOkmsbsDIc43K5cywZ9iz/IXo530PMUZVgHCdsYmHOLwx WXKVU6AwlnuWf9LhADHjLkTWLVWS74/bN5xxn6N5ARJHy59BnEkVJzaiv mWRnwaL2G/m9qbHS6a4aRpODQ4//MQiusWxheO9WvCG6vhDLAOBjvUi78 yo60EHuHyHFw6Yq51hwvRCMsAZWYuoEe5vX5bNEjN+XG+W7UCkV2d1MYW A==; X-IronPort-AV: E=McAfee;i="6500,9779,10447"; a="273366245" X-IronPort-AV: E=Sophos;i="5.93,256,1654585200"; d="scan'208";a="273366245" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Aug 2022 00:21:11 -0700 X-IronPort-AV: E=Sophos;i="5.93,256,1654585200"; d="scan'208";a="735388587" Received: from skummith-mobl1.amr.corp.intel.com (HELO vverma7-desk1.intel.com) ([10.212.54.206]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Aug 2022 00:21:10 -0700 From: Vishal Verma To: Cc: , Dan Williams , Vishal Verma Subject: [ndctl PATCH 2/3] libcxl: fox a resource leak and a forward NULL check Date: Tue, 23 Aug 2022 01:21:05 -0600 Message-Id: <20220823072106.398076-3-vishal.l.verma@intel.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823072106.398076-1-vishal.l.verma@intel.com> References: <20220823072106.398076-1-vishal.l.verma@intel.com> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1127; h=from:subject; bh=L8XrefDPQMXBCMvyyrEG92ZKAXZ8Ao9a9bnYvHgSICM=; b=owGbwMvMwCXGf25diOft7jLG02pJDMks9Y8+bmosbnrrefe1xLyNMsskFpv943997/nk+aH6rCJi 3kkTOkpZGMS4GGTFFFn+7vnIeExuez5PYIIjzBxWJpAhDFycAjAR172MDEfk3G3sxS9w/eQ5/7n+0u ErPGK7SpnEGfIvr2m+fjzVdwEjw5Y762583Lqt347LweDyq2d8dwQqZS5lZ2yUWO0V03HQnhUA X-Developer-Key: i=vishal.l.verma@intel.com; a=openpgp; fpr=F8682BE134C67A12332A2ED07AFA61BEA3B84DFF Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org Static analysis reports a couple of issues in add_cxl_region(). Firstly, 'path' wasn't freed in the success case, only in the error case. Secondly, the error handling after 'calloc()'ing the region object erroneously jumped to the error path which tried to free the region object, instead of directly returning NULL. Cc: Dan Williams Signed-off-by: Vishal Verma --- cxl/lib/libcxl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c index 021d59f..9945fd1 100644 --- a/cxl/lib/libcxl.c +++ b/cxl/lib/libcxl.c @@ -482,7 +482,7 @@ static void *add_cxl_region(void *parent, int id, const char *cxlregion_base) region = calloc(1, sizeof(*region)); if (!region) - goto err; + return NULL; region->id = id; region->ctx = ctx; @@ -551,6 +551,7 @@ static void *add_cxl_region(void *parent, int id, const char *cxlregion_base) list_add_sorted(&decoder->regions, region, list, region_start_cmp); + free(path); return region; err: free(region->dev_path); From patchwork Tue Aug 23 07:21:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Verma, Vishal L" X-Patchwork-Id: 12951791 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED814C32793 for ; Tue, 23 Aug 2022 07:21:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240675AbiHWHVV (ORCPT ); Tue, 23 Aug 2022 03:21:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240646AbiHWHVU (ORCPT ); Tue, 23 Aug 2022 03:21:20 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1625B61D9A for ; Tue, 23 Aug 2022 00:21:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661239280; x=1692775280; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8rJ8gEEBtVLYGXTt1L5arjJ8aeJKmNlD+4PYtRRCVes=; b=YA1GT5aP4qJZkeZOrAmPIh1ttpCvQkyYe3rE7MxX33bHUUWbOmpKQ2M3 KVtELmTz1VKNzUCvOME0We6vC+C4lDG2lukd/u3rEMub3Qod3R0tsiSAh jQiNp39Jk+2CaAmNJN0ejR1bm1MmvemJhyZcZPJlUuvfWsM1KcU8VaLco 3B3cElfFNQj0Go+OvdO3rLqb12bppDeb0C1vsCpxajWAogGK/jjLdqNjs SPF4l8hJIPewzIefvSuTn5geiryGRZI0BNmOi+JlgpEctGbdtON80faxF bBgbXYv50Awc5MMPjPfBZrlYmqYPNOcnxDhszVaql8OfPqYshklMD2X5T g==; X-IronPort-AV: E=McAfee;i="6500,9779,10447"; a="273366246" X-IronPort-AV: E=Sophos;i="5.93,256,1654585200"; d="scan'208";a="273366246" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Aug 2022 00:21:11 -0700 X-IronPort-AV: E=Sophos;i="5.93,256,1654585200"; d="scan'208";a="735388590" Received: from skummith-mobl1.amr.corp.intel.com (HELO vverma7-desk1.intel.com) ([10.212.54.206]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Aug 2022 00:21:11 -0700 From: Vishal Verma To: Cc: , Dan Williams , Vishal Verma Subject: [ndctl PATCH 3/3] cxl/filter: Fix an uninitialized pointer dereference Date: Tue, 23 Aug 2022 01:21:06 -0600 Message-Id: <20220823072106.398076-4-vishal.l.verma@intel.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823072106.398076-1-vishal.l.verma@intel.com> References: <20220823072106.398076-1-vishal.l.verma@intel.com> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=837; h=from:subject; bh=8rJ8gEEBtVLYGXTt1L5arjJ8aeJKmNlD+4PYtRRCVes=; b=owGbwMvMwCXGf25diOft7jLG02pJDMks9Y82rpzD9XiPz/5/vlEpvj4ZhrEnntescBLlLH+lvv2L 0NGTHaUsDGJcDLJiiix/93xkPCa3PZ8nMMERZg4rE8gQBi5OAZjIF26G//XTtos/2bts0aWdBZu67K u9vihHn/V2i10ef3njrovLT5cx/A/f9Wu7/eOY2Gv8V9hlvoaa1UXqhR/Srv4bxPg4/KrfeUYA X-Developer-Key: i=vishal.l.verma@intel.com; a=openpgp; fpr=F8682BE134C67A12332A2ED07AFA61BEA3B84DFF Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org Static analysis points out that there was a chance that 'jdecoder' could be used while uninitialized in walk_decoders(). Initialize it to NULL to avoid this. Cc: Dan Williams Signed-off-by: Vishal Verma --- cxl/filter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cxl/filter.c b/cxl/filter.c index 9a3de8c..56c6599 100644 --- a/cxl/filter.c +++ b/cxl/filter.c @@ -796,7 +796,7 @@ static void walk_decoders(struct cxl_port *port, struct cxl_filter_params *p, cxl_decoder_foreach(port, decoder) { const char *devname = cxl_decoder_get_devname(decoder); struct json_object *jchildregions = NULL; - struct json_object *jdecoder; + struct json_object *jdecoder = NULL; if (!p->decoders) goto walk_children;