Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp817488rdb; Thu, 30 Nov 2023 21:55:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IH2FX6MIA0m4uBgVlS9FZ6WWiZkEMmf7GbwD4z/LCJNcHqadzSvhs+WV/HHH3Hzd6l5p/vP X-Received: by 2002:a05:6a20:4419:b0:187:4ee0:e95e with SMTP id ce25-20020a056a20441900b001874ee0e95emr27352024pzb.52.1701410143543; Thu, 30 Nov 2023 21:55:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701410143; cv=none; d=google.com; s=arc-20160816; b=lQ57y+JBSVfAO1znx+1e/wFx2W8zfdJWmZaQk74mEOb3MHJhe9uSgm42woEZeaTsFS n/gOxKOJDv5g6Fbs9u0EG1z+h/NEZb+au8eQGJVTATgWntjdnf0cVoUV4iiRfgQXDJzU r3Wsp7qucSVPM14B+LuY4rdLKxEqp3uTaE/uEdE2Ac1BVMItkY84V8iqcLjZnzZnGdn6 FDuhUnwNSsckXjT/EOlhTH8boeMqcQHd6cC7SG5AxZzBKaX3SkDCcUOeHd8kGZDGFVlL K3o8kT/NjIz7zhYkrPxOuTtGWgy+mrU8BmQgS+IUU9dG2bo2Kh68DMCK8mPgSdWsa+CI 0lHw== 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=UrfpfKFqz2ujzPtk3wDKlTJ1q84Sl3bJN7UjBSqqXDM=; fh=dfPwvvILtVcHwLWRnuNUuspVU+BOZY0Mr6DxUsscfFQ=; b=ZQ97muHHj9SKFlIGK5v9CAasANn+XGBYL8eIdRoo2YNuedzX0Ip/UiFlJGkyyBV2GQ pN2iwfk0HibJvyRB0GqHE8IxsioA2ccb6GzowdS83Zpts4HSGlVua+EzHCVmQlrnK7mS LaC1zgD3hpPuZ+SNSvcH5aeYgvtm1jqpetlzKuFbntQsIsjk6VqRuIwz5mcSEeoocbMY donOuTk+PcxZAmf1bd5g05nAexMW29QoGMEQyB79LFr3MStQAJ8FWtlnPpXzrPfneBFI Df2DjfcS0SO47f2mvPVx2xYkTTJPNyHlij3J79rer0Pvvh61iiawUXkYwwuEnEJOdgSW tOPQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id e29-20020a631e1d000000b0059f0cebd046si2630185pge.729.2023.11.30.21.55.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 21:55:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 7366A80DFF79; Thu, 30 Nov 2023 21:55:41 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377505AbjLAFzc (ORCPT + 99 others); Fri, 1 Dec 2023 00:55:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229808AbjLAFza (ORCPT ); Fri, 1 Dec 2023 00:55:30 -0500 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AB5CF2; Thu, 30 Nov 2023 21:55:32 -0800 (PST) X-UUID: af621b157147467a8b72dd521f25fb77-20231201 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.33,REQID:4370d4bb-2196-4939-a7ad-15607adacd4b,IP:5,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:-10 X-CID-INFO: VERSION:1.1.33,REQID:4370d4bb-2196-4939-a7ad-15607adacd4b,IP:5,URL :0,TC:0,Content:0,EDM:0,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:-10 X-CID-META: VersionHash:364b77b,CLOUDID:abcb0696-10ce-4e4b-85c2-c9b5229ff92b,B ulkID:231201135519P328HBSD,BulkQuantity:0,Recheck:0,SF:66|38|24|17|19|44|1 02,TC:nil,Content:0,EDM:-3,IP:-2,URL:11|1,File:nil,Bulk:nil,QS:nil,BEC:nil ,COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_FAS,TF_CID_SPAM_FSD,TF_CID_SPAM_FSI, TF_CID_SPAM_ULN X-UUID: af621b157147467a8b72dd521f25fb77-20231201 X-User: chentao@kylinos.cn Received: from vt.. [(116.128.244.169)] by mailgw (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1806735794; Fri, 01 Dec 2023 13:55:17 +0800 From: Kunwu Chan To: hdegoede@redhat.com, ilpo.jarvinen@linux.intel.com, vadimp@nvidia.com, jdelvare@suse.com, linux@roeck-us.net, shravankr@nvidia.com, jiri@resnulli.us Cc: kunwu.chan@hotmail.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, Kunwu Chan Subject: [PATCH v2] platform/mellanox: Add some null/error pointer checks to mlxbf-pmc.c Date: Fri, 1 Dec 2023 13:54:47 +0800 Message-Id: <20231201055447.2356001-1-chentao@kylinos.cn> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY 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 (snail.vger.email [0.0.0.0]); Thu, 30 Nov 2023 21:55:41 -0800 (PST) devm_kasprintf() returns a pointer to dynamically allocated memory which can be NULL upon failure. devm_hwmon_device_register_with_groups return a error pointer upon failure. Compile-tested only. Fixes: 1a218d312e65 ("platform/mellanox: mlxbf-pmc: Add Mellanox BlueField PMC driver") Suggested-by: Ilpo Järvinen Suggested-by: Vadim Pasternak Signed-off-by: Kunwu Chan --- drivers/platform/mellanox/mlxbf-pmc.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/platform/mellanox/mlxbf-pmc.c b/drivers/platform/mellanox/mlxbf-pmc.c index 0b427fc24a96..1dd84c7a79de 100644 --- a/drivers/platform/mellanox/mlxbf-pmc.c +++ b/drivers/platform/mellanox/mlxbf-pmc.c @@ -1771,6 +1771,8 @@ static int mlxbf_pmc_init_perftype_counter(struct device *dev, int blk_num) attr->dev_attr.show = mlxbf_pmc_event_list_show; attr->nr = blk_num; attr->dev_attr.attr.name = devm_kasprintf(dev, GFP_KERNEL, "event_list"); + if (!attr->dev_attr.attr.name) + return -ENOMEM; pmc->block[blk_num].block_attr[i] = &attr->dev_attr.attr; attr = NULL; @@ -1784,6 +1786,8 @@ static int mlxbf_pmc_init_perftype_counter(struct device *dev, int blk_num) attr->nr = blk_num; attr->dev_attr.attr.name = devm_kasprintf(dev, GFP_KERNEL, "enable"); + if (!attr->dev_attr.attr.name) + return -ENOMEM; pmc->block[blk_num].block_attr[++i] = &attr->dev_attr.attr; attr = NULL; } @@ -1810,6 +1814,8 @@ static int mlxbf_pmc_init_perftype_counter(struct device *dev, int blk_num) attr->nr = blk_num; attr->dev_attr.attr.name = devm_kasprintf(dev, GFP_KERNEL, "counter%d", j); + if (!attr->dev_attr.attr.name) + return -ENOMEM; pmc->block[blk_num].block_attr[++i] = &attr->dev_attr.attr; attr = NULL; @@ -1821,6 +1827,8 @@ static int mlxbf_pmc_init_perftype_counter(struct device *dev, int blk_num) attr->nr = blk_num; attr->dev_attr.attr.name = devm_kasprintf(dev, GFP_KERNEL, "event%d", j); + if (!attr->dev_attr.attr.name) + return -ENOMEM; pmc->block[blk_num].block_attr[++i] = &attr->dev_attr.attr; attr = NULL; } @@ -1853,6 +1861,8 @@ static int mlxbf_pmc_init_perftype_reg(struct device *dev, int blk_num) attr->nr = blk_num; attr->dev_attr.attr.name = devm_kasprintf(dev, GFP_KERNEL, events[j].evt_name); + if (!attr->dev_attr.attr.name) + return -ENOMEM; pmc->block[blk_num].block_attr[i] = &attr->dev_attr.attr; attr = NULL; i++; @@ -1882,6 +1892,8 @@ static int mlxbf_pmc_create_groups(struct device *dev, int blk_num) pmc->block[blk_num].block_attr_grp.attrs = pmc->block[blk_num].block_attr; pmc->block[blk_num].block_attr_grp.name = devm_kasprintf( dev, GFP_KERNEL, pmc->block_name[blk_num]); + if (!pmc->block[blk_num].block_attr_grp.name) + return -ENOMEM; pmc->groups[pmc->group_num] = &pmc->block[blk_num].block_attr_grp; pmc->group_num++; @@ -2063,6 +2075,8 @@ static int mlxbf_pmc_probe(struct platform_device *pdev) pmc->hwmon_dev = devm_hwmon_device_register_with_groups( dev, "bfperf", pmc, pmc->groups); + if (IS_ERR(pmc->hwmon_dev)) + return PTR_ERR(pmc->hwmon_dev); platform_set_drvdata(pdev, pmc); return 0; -- 2.34.1