Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3180467pxf; Mon, 15 Mar 2021 03:44:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxy8WMpqt5Q127VJhNO6BU/Ak73FPUJaHrpUgpobZCE+NdM6pQOTlVbBwGqe6/MpKnRu8V0 X-Received: by 2002:aa7:c345:: with SMTP id j5mr28395388edr.338.1615805045410; Mon, 15 Mar 2021 03:44:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615805045; cv=none; d=google.com; s=arc-20160816; b=NCJpP5YI51IL/T4rQkenI2kiuy5vDBq3pc49POZcYzmpBLOsNzhYg241diSV4VuN6s IlVbGs5MfG/sWSFW45zM8ijSW16s0PkOPKbNHf29wip1v+4+ZPedbaz7ujXli9u+Kwl+ YA862eRZeQYzCsMSuYzyMiZAGp2snW44ZH9rKtPyAgm4oY9o+kuoDJ0q0z3Hf4CO2/eL pvD9zklWk+HEvxYNxuX4SVrPJHywlJJHcLEMwJTuDR1bwrpunsqQ6ro/vTqLFmcQvnLH lqEibtTmoTiNap7g03ZtUvwVk/bG+kKx3AoYrrZW2gg6WN2xJEfyTV+JL6DEfnEsOR6I Twtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=jJ1rQbWo3v0n3XAnAcpOXdiG3NjDEOcjosUGAw4bkjc=; b=TL5e1Z3Rew+hgR5yUcvwQBgJmDEa5BKZWEGVuq+pMYgH0q+IbTxyWhMwqyUMI3y4jv m+G7JiyEBomCdv1AEyoR1cMLt3I/Wwqkw82kJcIMNs27XUfzbP7IZIIGCwQ6pYzXP860 xvFabC9afDrzc8utu+LkQLNSq72F2ghY17XViJLBZBs9ORElB2YV2wgR3SBhaX0Yh6uL uxQcU2e7YISxsOLUy/I+xvmCX+EMUa/nkJPfjPDS9GtoJP/BwBj87W5JEeyHkUkFUSsQ S8hD2S0mafo+GkfThX31hV9i5KJzEm+jWn6sKbTyqQ/1av6e/5u1FsdZrAWMa8oxyvy9 +Qng== 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=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b15si10729539ejv.689.2021.03.15.03.43.43; Mon, 15 Mar 2021 03:44:05 -0700 (PDT) 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=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229868AbhCOKkE (ORCPT + 99 others); Mon, 15 Mar 2021 06:40:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229672AbhCOKjd (ORCPT ); Mon, 15 Mar 2021 06:39:33 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23351C061574 for ; Mon, 15 Mar 2021 03:39:32 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: eballetbo) with ESMTPSA id 420AA1F45CDA Subject: Re: [PATCH 04/23] ASoC: cros_ec_codec: remove null pointer dereference warning To: Pierre-Louis Bossart , alsa-devel@alsa-project.org Cc: tiwai@suse.de, broonie@kernel.org, linux-kernel@vger.kernel.org, Cheng-Yi Chiang , Guenter Roeck , Liam Girdwood , Jaroslav Kysela , Takashi Iwai , Benson Leung References: <20210312182246.5153-1-pierre-louis.bossart@linux.intel.com> <20210312182246.5153-5-pierre-louis.bossart@linux.intel.com> From: Enric Balletbo i Serra Message-ID: Date: Mon, 15 Mar 2021 11:39:27 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: <20210312182246.5153-5-pierre-louis.bossart@linux.intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Pierre-Louis, Thank you for you patch. On 12/3/21 19:22, Pierre-Louis Bossart wrote: > 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 Looks good to me, so Acked-by: Enric Balletbo i Serra > --- > 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; >