Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp598357pxb; Thu, 15 Apr 2021 01:56:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0UYH3cjVX1DkK31KKAw6MfX0rL8hz88/gDrFtlDT5TJDb6rCqLoJFDKK9VpkThAGeR581 X-Received: by 2002:a17:90b:198c:: with SMTP id mv12mr2753923pjb.51.1618477005673; Thu, 15 Apr 2021 01:56:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618477005; cv=none; d=google.com; s=arc-20160816; b=gAZ4KHdjCS2BSYl0gQ/AjQrAOi69u/ylqrV92cLfp9Sb+dcnTHzZQUmuq8SFOVmW7H +ttyRsffFZl63Hct9k9ARGweRspSgFXxAUrz0Fi5KfdVywGw40yR+ynOaEIr1TRSjy9b XgVSYcFHTl22vQLYf4Wp00mwYKEQlISNtDqaA4UQojsI91HyqeV/IQXi4lfnX/IKgg/R wl6jS7YClZibhQ7tt9mrUroD599A3fcoc4iSJDKQL8pHhniCPV8bi7pkMyqsydlmWzNX 0ftQywna9ZhHbofmzMSCZArHGt5s3liCjo5f7tnt3ARX7wsY0QQpO00Lmwgsl6dOY+XY w1Dw== 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=vTL6QSo6Gl9j1T0TDybxuGAdxEF8ToYg9KWLlox23kA=; b=XU1ruBuZuYrN0YBnSZ7M5RYxwmX+pQF8jqhcQWdXbQzyT4hfNc3Z0mUNZXDypOIGdP d5dc+zDtoSjLzgbph3F7BkTByO9bFcBfPY+IBbrQY0DzJhPKSDjXmZLARDFH6Zif6wBN tpMB/HxXhsJP7swWFxa1J7qf6LQfL/fQ9urwqBZXhloEnkB9oVaK6pfDSEhbH2F5MD1q Q7q0RPMHvd17kmHb8RpthDDsYB7ThTaFhPCfvSYLM/17YUTvKKmvQH5VZRH8mUkv3WMT FR7lwcxRxuQ88o+/wL58GiqG56GjQmUIg87CWAMVOkjWHG6QVqCr0V7Z1Ylrl7x3x8gY pEoA== 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=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p16si2619403plf.146.2021.04.15.01.56.33; Thu, 15 Apr 2021 01:56:45 -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=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231809AbhDOI4H (ORCPT + 99 others); Thu, 15 Apr 2021 04:56:07 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:38759 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231143AbhDOI4G (ORCPT ); Thu, 15 Apr 2021 04:56:06 -0400 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1lWxmi-00016L-Fb; Thu, 15 Apr 2021 08:55:36 +0000 From: Colin King To: Wolfgang Grandegger , Marc Kleine-Budde , "David S . Miller" , Jakub Kicinski , Vincent Mailhol , Arunachalam Santhanam , linux-can@vger.kernel.org, netdev@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][next] can: etas_es58x: Fix potential null pointer dereference on pointer cf Date: Thu, 15 Apr 2021 09:55:35 +0100 Message-Id: <20210415085535.1808272-1-colin.king@canonical.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Colin Ian King The pointer cf is being null checked earlier in the code, however the update of the rx_bytes statistics is dereferencing cf without null checking cf. Fix this by moving the statement into the following code block that has a null cf check. Addresses-Coverity: ("Dereference after null check") Fixes: 8537257874e9 ("can: etas_es58x: add core support for ETAS ES58X CAN USB interfaces") Signed-off-by: Colin Ian King --- drivers/net/can/usb/etas_es58x/es58x_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/can/usb/etas_es58x/es58x_core.c b/drivers/net/can/usb/etas_es58x/es58x_core.c index 7222b3b6ca46..5198e1d6b6ad 100644 --- a/drivers/net/can/usb/etas_es58x/es58x_core.c +++ b/drivers/net/can/usb/etas_es58x/es58x_core.c @@ -856,9 +856,10 @@ int es58x_rx_err_msg(struct net_device *netdev, enum es58x_err error, * consistency. */ netdev->stats.rx_packets++; - netdev->stats.rx_bytes += cf->can_dlc; if (cf) { + netdev->stats.rx_bytes += cf->can_dlc; + if (cf->data[1]) cf->can_id |= CAN_ERR_CRTL; if (cf->data[2] || cf->data[3]) { -- 2.30.2