From patchwork Wed Jun 21 10:04:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 110977 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4266883vqr; Wed, 21 Jun 2023 03:47:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5THUMmjFCec4DQ8acWrhPWDe7oajVq2QZTIWtB46MDNsCKnM6s4o7DfywN/z6BmTrrhvl1 X-Received: by 2002:a9d:6387:0:b0:6b5:a499:fa90 with SMTP id w7-20020a9d6387000000b006b5a499fa90mr3092643otk.33.1687344425287; Wed, 21 Jun 2023 03:47:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687344425; cv=none; d=google.com; s=arc-20160816; b=rBC3dwkNjnKFO29ws7eA1GXyW/kVQhBU8Mq2taZlJvMOf5RbXf29zWYRwsmTH5OkgH 8E/r829P5cjfHOZyCyXd9dr+0K/9FKf9o1xnibEjh2Ee/U/PMgjf0Cgome9k7T9aE6/v 1OLS2YTc2VBxWVZyGLQfY2FD8a9c/aNwfkjgI0AI6KZtRf9pFswHS9cGeuhQ3Zi7H1Gm C6qwiT0I9NAikEn9aIQJyB9dcB61KZA4mlEaYq0IF3GdjG0v3QcIztLkYgZpBpy7D6i3 DNbBSlyGQEaGrz6nKA871S1zTN174lncqNt7FKnwOmGBbFDXCMpo2P+sjsdoIXSwPM6K egsQ== 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=GXnSDdoQe966t8NM5bhSnA86hj61Q8pTC+6bdEtmIzk=; b=GA12FCXV/70MyWn8CI92mwsG8A2fBIWBJyBWYMfVQb6e/OxRB43OVQgzo61mNH3sdf AehZO+RhXzBAxzkJjhQaEe/RGdgKkPT34ogHS1RA8qM8mlAmkqx5oOyjVTfezwSU+oHA NpMDzclcRcVVTR3uIBVjIoxn/pPba0P7rJD1Zq2X3BMN0Eb6LJIQJykqswYA6w+Xmzns GLukLQeMry3h0Dd3vXw2umzfDaxNto25pIun8bI4VbXINOGeLP3ImmB5I7sv4CZlWsWS /9w/i9RSJii1T/sR/iR2yrKD82RZPN9phkHQTIB4urZvKs/lOkTyWsjnaCe/xdi4W31u shHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=dXcaRnzE; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t191-20020a6381c8000000b00553371ceeb9si3732344pgd.58.2023.06.21.03.46.46; Wed, 21 Jun 2023 03:47:05 -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=@microchip.com header.s=mchp header.b=dXcaRnzE; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231398AbjFUKMo (ORCPT + 99 others); Wed, 21 Jun 2023 06:12:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231144AbjFUKMR (ORCPT ); Wed, 21 Jun 2023 06:12:17 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 447E81BC8; Wed, 21 Jun 2023 03:11:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1687342289; x=1718878289; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=r0aPIdf9vVpHAKGkxLJol5k5eFJfFNg1FF9HV5m5yD4=; b=dXcaRnzE/5T/jRt3iy/NUOa/k+4Vc7dRXFxhb3QKp90jcT93QwdmfO2S rEv1HDg823Wcsll5FRLetpKQk436Qd0kyNHMX8ROIg1dKEi8y3+jkvFQY T8tdDUzRRBJDIINQwLIysbEOzBymGammFvdS2Bp1Qe2aO7KgtBZnTeWV/ iqq70olkuB5idiSjqkB3RL8HxR/NRzV3B/KbCxh4OHXW1Na25Fv8/YzZ+ 6o9hFKbDdnCzUwV8G/GLGeIXyMA72Rnwai/pg4Db4/QAHNlL26VWwV9i/ +Fp8ZCpPJXff09whVVE4yaFivvsjXngroK4WjbUWg9JVQpC0VSAqTimpX A==; X-IronPort-AV: E=Sophos;i="6.00,260,1681196400"; d="scan'208";a="157908905" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa6.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 21 Jun 2023 03:04:29 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Wed, 21 Jun 2023 03:04:29 -0700 Received: from plexus-g.actel.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2507.21 via Frontend Transport; Wed, 21 Jun 2023 03:04:26 -0700 From: Claudiu Beznea To: , CC: , , "Claudiu Beznea" Subject: [PATCH v2] pinctrl: mcp23s08: check return value of devm_kasprintf() Date: Wed, 21 Jun 2023 13:04:09 +0300 Message-ID: <20230621100409.1608395-1-claudiu.beznea@microchip.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769308868008117530?= X-GMAIL-MSGID: =?utf-8?q?1769308868008117530?= devm_kasprintf() returns a pointer to dynamically allocated memory. Pointer could be NULL in case allocation fails. Check pointer validity. Identified with coccinelle (kmerr.cocci script). Fixes: 0f04a81784fe ("pinctrl: mcp23s08: Split to three parts: core, I²C, SPI") Signed-off-by: Claudiu Beznea Reviewed-by: Andy Shevchenko --- Changes in v2: - use independent checks for devm_kasprintf() drivers/pinctrl/pinctrl-mcp23s08_spi.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/pinctrl/pinctrl-mcp23s08_spi.c b/drivers/pinctrl/pinctrl-mcp23s08_spi.c index 9ae10318f6f3..ea059b9c5542 100644 --- a/drivers/pinctrl/pinctrl-mcp23s08_spi.c +++ b/drivers/pinctrl/pinctrl-mcp23s08_spi.c @@ -91,18 +91,28 @@ static int mcp23s08_spi_regmap_init(struct mcp23s08 *mcp, struct device *dev, mcp->reg_shift = 0; mcp->chip.ngpio = 8; mcp->chip.label = devm_kasprintf(dev, GFP_KERNEL, "mcp23s08.%d", addr); + if (!mcp->chip.label) + return -ENOMEM; config = &mcp23x08_regmap; name = devm_kasprintf(dev, GFP_KERNEL, "%d", addr); + if (!name) + return -ENOMEM; + break; case MCP_TYPE_S17: mcp->reg_shift = 1; mcp->chip.ngpio = 16; mcp->chip.label = devm_kasprintf(dev, GFP_KERNEL, "mcp23s17.%d", addr); + if (!mcp->chip.label) + return -ENOMEM; config = &mcp23x17_regmap; name = devm_kasprintf(dev, GFP_KERNEL, "%d", addr); + if (!name) + return -ENOMEM; + break; case MCP_TYPE_S18: