Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1481228pxf; Fri, 12 Mar 2021 10:26:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJw4Xo5gvrjKn6zdcJ9K0jDOrcrbrtwIEW3jMcThdoI2tFqSNQ9cFycq1qhHYo6SJtkspV4j X-Received: by 2002:a05:6402:4309:: with SMTP id m9mr16320888edc.25.1615573609761; Fri, 12 Mar 2021 10:26:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615573609; cv=none; d=google.com; s=arc-20160816; b=HRkGV2DZDLOGGQfmPkk+gyLI86ExKF9DH7VGlK/Tb9f2elVS5x+pSERnvXejlG/UMO E6iOyk8qmPJEul3INl44KPGsnOH0RKRPfYn8EhXN1BjqQI4sHyYMjKrmKl3KTRQpHzJf FEPa0ZDYLalSV2Vz5z2PxaxSmrKdDNolyLZYescj7CWvU0ozw6KhRJ10vrigG2ID8R3m fG7aCCPvhatBqxrRdldjZ6aS8kYYm0iAnbWpg+KqRu+QsjX0jxXycwhCvaFkYNVXJr3O KfMAAS4njjb8wcFYMrc5+VPVxn5WON+Tk9jKUVeG9liAx6pjKe5xMsV5N2+2yIImlSwG Bj8Q== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=9PmnfUuYv3VdoyOxqE/a/3ot9+bBK65V7caHG1NVpQM=; b=O3y2hEfoCYHl8Yzrpt27I1arXwNElcMov0s+su5AWGehYuhunBkg8l4u8ZiiV6QV9H 9IElxD2z6yy4ZRF5oIRypEaH2Oc5+MW/BWK6QXPDyiP2Fm92rGa+9Egb2eLQHYW+I69P kDe/9uVq36Z9vBGlpBs1uKcI87Wx3ESf4ZHib8wFccsfH3JdQtNUolWKu3ULuS+N2nGK UBWo54Y32ELWUxTLWCy4F96fXEta6eaRRZfImoRrvaQTRGD0bRZAvATNVmFeHgZ/vnik bkkStxgYodt8LoqZPs/cZu4g3oSzXx5RR/PsJnCVeElG6OmYq/WLWXcy07sl31fMAyyB FbVA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i10si4568755ejd.240.2021.03.12.10.26.25; Fri, 12 Mar 2021 10:26:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233197AbhCLSXX (ORCPT + 99 others); Fri, 12 Mar 2021 13:23:23 -0500 Received: from mga02.intel.com ([134.134.136.20]:36913 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233125AbhCLSXN (ORCPT ); Fri, 12 Mar 2021 13:23:13 -0500 IronPort-SDR: iBj3Ds8xswpqOa3dOdzXzWGBHoNJ27VEMmGuRzliQ9MFhQ80c46ydUjMvAtUVCvCj3RgMu4h6X BWLxce7YWQCg== X-IronPort-AV: E=McAfee;i="6000,8403,9921"; a="175999090" X-IronPort-AV: E=Sophos;i="5.81,244,1610438400"; d="scan'208";a="175999090" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Mar 2021 10:23:11 -0800 IronPort-SDR: hRKnoHE/VowBFnczbtcE9mCoFpZg3OvRWwVpvZEDrZHjTrkzPJX3aue76/cawBAbdFRDqanEua 37ijkhiH5m/w== X-IronPort-AV: E=Sophos;i="5.81,244,1610438400"; d="scan'208";a="377791911" Received: from amiteshs-mobl.amr.corp.intel.com (HELO pbossart-mobl3.intel.com) ([10.212.37.30]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Mar 2021 10:23:10 -0800 From: Pierre-Louis Bossart To: alsa-devel@alsa-project.org Cc: tiwai@suse.de, broonie@kernel.org, linux-kernel@vger.kernel.org, Pierre-Louis Bossart , Cheng-Yi Chiang , Enric Balletbo i Serra , Guenter Roeck , Liam Girdwood , Jaroslav Kysela , Takashi Iwai , Benson Leung Subject: [PATCH 04/23] ASoC: cros_ec_codec: remove null pointer dereference warning Date: Fri, 12 Mar 2021 12:22:27 -0600 Message-Id: <20210312182246.5153-5-pierre-louis.bossart@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210312182246.5153-1-pierre-louis.bossart@linux.intel.com> References: <20210312182246.5153-1-pierre-louis.bossart@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Cppcheck complains of a possible issue: sound/soc/codecs/cros_ec_codec.c:98:10: warning: Possible null pointer dereference: in [nullPointer] memcpy(in, msg->data, insize); ^ sound/soc/codecs/cros_ec_codec.c:162:34: note: Calling function 'send_ec_host_command', 5th argument 'NULL' value is 0 (uint8_t *)&p, sizeof(p), NULL, 0); ^ sound/soc/codecs/cros_ec_codec.c:98:10: note: Null pointer dereference memcpy(in, msg->data, insize); ^ In practice the access to the pointer is protected by another argument, but this is likely to fool other static analysis tools. Add a test to avoid doing the memcpy if the pointer is NULL or the size is zero. Signed-off-by: Pierre-Louis Bossart --- sound/soc/codecs/cros_ec_codec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sound/soc/codecs/cros_ec_codec.c b/sound/soc/codecs/cros_ec_codec.c index c4772f82485a..a201d652aca2 100644 --- a/sound/soc/codecs/cros_ec_codec.c +++ b/sound/soc/codecs/cros_ec_codec.c @@ -94,7 +94,7 @@ static int send_ec_host_command(struct cros_ec_device *ec_dev, uint32_t cmd, if (ret < 0) goto error; - if (insize) + if (in && insize) memcpy(in, msg->data, insize); ret = 0; -- 2.25.1