From patchwork Fri Nov 22 22:15:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 3657 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-lj1-f198.google.com (mail-lj1-f198.google.com [209.85.208.198]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 85D503F9F7 for ; Fri, 22 Nov 2024 23:17:11 +0100 (CET) Received: by mail-lj1-f198.google.com with SMTP id 38308e7fff4ca-2ffb0921706sf1555641fa.1 for ; Fri, 22 Nov 2024 14:17:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1732313831; cv=pass; d=google.com; s=arc-20240605; b=k4lgOqPSKvu7uWFQ1UPtSu5qIh3T00iecMDP2lAyKt4raPQWI9czjDCvwXWmSX4BcF BU0K+u8KOZvNouX0XksrWnGGZPa1EU35/8N1+z8RpcbDZ1Pr00+kcT/uWs1Z1uwxb3GR b/Luqzh3dTAMQDgfM2llkyA9j0h9iLjoBcLsYPnnn50yc5mIvnWHbGQZnakGIO/by3X/ QJN7VJldEoNXA38YCMbRlS/AW5Gikw3iIhEtm0IUX4H1zFOsrLkTV9Gx+ycSMGGi8a58 Xsg+ehOJx45/qHjjH8djr+8psD5GV1SoipXuqwahTdRktFRknoht1Lj4j8s8gJeaHAdK 9QRw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=W/2vxF41Yk58HlLmNuXhlSPubDmdS10Klz3WpqtIflk=; fh=10pQ/r/2kOhr+c796gaF3Fz+qRReesl9U8eLwA51WnM=; b=O8tekz/gfBcuB5dVeq8+HD/63FrZNLYOPkdii3RhRXnXllNsM5glF2GQhSSXejfBi4 VyJGplcwG1iD1O37MJ5GPpu9dwcOT1R//8Aoe/veIXTMNSuYYc8Rn7mG9Y4//NR3HZSb OAoXHLrytlPntSWlrZWOYHpsxDmoHU0jEz9GeK9SJIJicyDaPAhVu6WNLs2qfJRw4IZb dSHbYcG25OO/BingtiDl+8zJ/fLRp1/F7/yuMd1tLjuQsJpOlpgLdFVgKeBfp/MrVkC2 Fmw/kUUpzcqjVNatNKf00IVkFayHqfTCIZ314rYF39z6JglAYGaCaVm0sV2fMKzfQfXq dVWw==; darn=patchwork.amarulasolutions.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=NDdUyw0x; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=pass header.i=@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; t=1732313831; x=1732918631; darn=patchwork.amarulasolutions.com; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=W/2vxF41Yk58HlLmNuXhlSPubDmdS10Klz3WpqtIflk=; b=ILrUI9ijELTl2bv4CPKz7ZybG3phPc6tq6SWCqErtz4PVCbYCCp7Vf7XJfA2QA7y+p k4qEz9bEj/sJsiT44wZTNXAL3Hk8glySuKynoFaTB29CjNFe86YwAyB7vWNNZv1YrPxG 3wuwg5SC3t1O+msU4s42kI6Y8+dY9YQ/rlvGw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732313831; x=1732918631; h=list-unsubscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :x-beenthere:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=W/2vxF41Yk58HlLmNuXhlSPubDmdS10Klz3WpqtIflk=; b=XVkzoR5GpzhdKlIZto/tLpT9vdA343EExpuHGFM1/9fia0DURvmFbFUR7zqQCfHryA ZoIfvvxWhCsgl02dNTu1P/trUwlpw856gGzILhlySnCv6vGlrb27vqhJFyTsNrqChvbI R7k0OdJGgtsKdFX94cP7xe7KTiCYo7rglMbvP8RNUNKoPK88/b7zs39z52O3V1tFV5tk mCMB8im61mlkWr1P2xYiUWDkq2XTX+OPS6K8XfT9OoBtIfsvKrd/3c42juAg6rJYdpAd BZNUgUR4EFd2uWsL/YLP+eV8TQHiCJfflQCqkglpR6uHwgHoW2YEtFvQh2oSF6FRRAS/ t/GA== X-Forwarded-Encrypted: i=2; AJvYcCVw7A6iFI7JRfMqdhyGtIxHBux0z7CXsSWlhyh8kOQNYUSlhjUuo93f6Sxbi3IaImwlKuC9OvP8pP1n7fdq@patchwork.amarulasolutions.com X-Gm-Message-State: AOJu0YwB+/qXWqFG1cVS53+C+ueWoysU09MgP0GdQik7Uf/utB0cwlte ewTG5xgWIFyKrWDWpNZ6kpiOS13/1vEEdHy2INvU28P9q4i69wsYSGP4gTjeqyJ1lA== X-Google-Smtp-Source: AGHT+IE+XH5wU8spxur0xr94DAHA7fNB0DaLmabDNrBY9+UaVlkdXsAvVI2I7dCv1MbMvRsZSSjPYw== X-Received: by 2002:a05:651c:985:b0:2ff:95d7:9ed2 with SMTP id 38308e7fff4ca-2ffa716ed4fmr45453681fa.32.1732313830817; Fri, 22 Nov 2024 14:17:10 -0800 (PST) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:651c:1199:b0:2ff:a75d:603a with SMTP id 38308e7fff4ca-2ffa75d6186ls1979441fa.1.-pod-prod-05-eu; Fri, 22 Nov 2024 14:17:09 -0800 (PST) X-Received: by 2002:a05:651c:b20:b0:2ff:7d2e:f4a2 with SMTP id 38308e7fff4ca-2ffa7124e89mr40076771fa.20.1732313828855; Fri, 22 Nov 2024 14:17:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1732313828; cv=none; d=google.com; s=arc-20240605; b=Ww48ImpoLuxIaJnpsFLpKcmzt7r5KWtMZcdzaaMGqjmd2NfqqWxPWVs7KZaLDnpLC+ FNAJBZx6RnBHvN5CB7flW0UjyvQbEBVV4NtW3JCoaBYZG/jvOj8KzO0qvOlT12ugcFJ3 u4ZLhBrLoecgO2K+ud1Jg3by6NLdSM6c8lnu43Yl/HFy31gs080x/4j8hKvSIKvIt7JG +DOE9xcyVjwQD+InW7hyoDaec/BcfsqDldjxD6ep/L/ZoJHJYJckgFiDo3ctqYH9VL+f GEsaztBgyoeC+okmgYq5BaPh9CkI1bJJUuWV5myhiuxPDa5P+vWlkshi9R1jcp/0+nls FIyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=zeHUsvNMH4naO2lNY0rPoAp0glNUJp2xtRk2ah0U1WQ=; fh=CmKGVlYv+zD+LFzklpA0QBH9fKCofsMTPpneubnHAkw=; b=dOL5xCvWNr72U967kWc3vhvRaVpFwW7aiGmiKOmhdHZv9PSP9YiNxSNzIZ3cvOClEa Wk4rYTKKv/CUuCaVc7J4Fkr/DwkBBbem6WFkxqs9LijZ/Dx9ffGBaqdW+juyWJUKXer8 ry9cDjeMNaUDFhW+NA0e6xGQE9INXJUz2ulGNNT6uRnGbq84rOnHIKTDV5e4IWegixUz vdl2gjip6VOiwVKzbCNjNcb6Io5ESCHUJKe2z0Z54cnsL7BawivqNsoyltND+53DydPE 3+i8V657VyuZfUoWAhXQ3oGO4u3L1GWJ2N/cUwi8IvFE9bF0mPLNtOmvzPSRwJ3uLUUQ 1S4Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=NDdUyw0x; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=pass header.i=@amarulasolutions.com Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id 38308e7fff4ca-2ffae685ca0sor3351841fa.0.2024.11.22.14.17.08 for (Google Transport Security); Fri, 22 Nov 2024 14:17:08 -0800 (PST) Received-SPF: pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Gm-Gg: ASbGnct0WuyEqeteNJ9E+ZFE1h7FhtLcPXJ6/PrgDQz7H3zWYDvMTPySeASKUnXldXv Y39fUL3KMVzQCMJcBl2CdiZlQlt5vklG7RjeNsUoWc6ci0jHf4XEjkooF0ZE1NQbR42qgZeRSdE UxePNhtcW7yI1OuieeSDjKFsEoFRhGxIhn42ugCv6BwxsfRkTlFAtkm7suJPp9C/JwLvFcyMp6h siVuVkMdNfITflZ0LJS/pyYYf5fhoZ2d6KUZiwHLCMMPMBsBTHgBJrlWEdVlHEOeJm9/goJOdeH 1wHqthPHdTz+nel5IITIDupXHVoFxxe9Rh6C/UI51HiLeJTkYkH9cS3drGG6vQwHqc9Z5Ls0bgO YFcGpNZFkAsvmlaoV X-Received: by 2002:a2e:a58b:0:b0:2fb:36df:3b4 with SMTP id 38308e7fff4ca-2ffa7187eb1mr50418561fa.34.1732313828318; Fri, 22 Nov 2024 14:17:08 -0800 (PST) Received: from dario-ThinkPad-T14s-Gen-2i.homenet.telecomitalia.it (host-82-54-94-193.retail.telecomitalia.it. [82.54.94.193]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa50b52fcebsm148226466b.127.2024.11.22.14.17.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Nov 2024 14:17:08 -0800 (PST) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: linux-amarula@amarulasolutions.com, Dario Binacchi , "David S. Miller" , Marc Kleine-Budde , Sebastian Haas , Vincent Mailhol , Wolfgang Grandegger , linux-can@vger.kernel.org Subject: [PATCH v2 11/12] can: ems_usb: fix {rx,tx}_errors statistics Date: Fri, 22 Nov 2024 23:15:52 +0100 Message-ID: <20241122221650.633981-12-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241122221650.633981-1-dario.binacchi@amarulasolutions.com> References: <20241122221650.633981-1-dario.binacchi@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: dario.binacchi@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=NDdUyw0x; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=pass header.i=@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The ems_usb_rx_err() function only incremented the receive error counter and never the transmit error counter, even if the ECC_DIR flag reported that an error had occurred during transmission. Increment the receive/transmit error counter based on the value of the ECC_DIR flag. Fixes: 702171adeed3 ("ems_usb: Added support for EMS CPC-USB/ARM7 CAN/USB interface") Signed-off-by: Dario Binacchi --- Changes in v2: - Update statistics even if skb allocation fails drivers/net/can/usb/ems_usb.c | 58 ++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/drivers/net/can/usb/ems_usb.c b/drivers/net/can/usb/ems_usb.c index 050c0b49938a..5355bac4dccb 100644 --- a/drivers/net/can/usb/ems_usb.c +++ b/drivers/net/can/usb/ems_usb.c @@ -335,15 +335,14 @@ static void ems_usb_rx_err(struct ems_usb *dev, struct ems_cpc_msg *msg) struct net_device_stats *stats = &dev->netdev->stats; skb = alloc_can_err_skb(dev->netdev, &cf); - if (skb == NULL) - return; if (msg->type == CPC_MSG_TYPE_CAN_STATE) { u8 state = msg->msg.can_state; if (state & SJA1000_SR_BS) { dev->can.state = CAN_STATE_BUS_OFF; - cf->can_id |= CAN_ERR_BUSOFF; + if (skb) + cf->can_id |= CAN_ERR_BUSOFF; dev->can.can_stats.bus_off++; can_bus_off(dev->netdev); @@ -361,44 +360,53 @@ static void ems_usb_rx_err(struct ems_usb *dev, struct ems_cpc_msg *msg) /* bus error interrupt */ dev->can.can_stats.bus_error++; - stats->rx_errors++; - cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR; + if (skb) { + cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR; - switch (ecc & SJA1000_ECC_MASK) { - case SJA1000_ECC_BIT: - cf->data[2] |= CAN_ERR_PROT_BIT; - break; - case SJA1000_ECC_FORM: - cf->data[2] |= CAN_ERR_PROT_FORM; - break; - case SJA1000_ECC_STUFF: - cf->data[2] |= CAN_ERR_PROT_STUFF; - break; - default: - cf->data[3] = ecc & SJA1000_ECC_SEG; - break; + switch (ecc & SJA1000_ECC_MASK) { + case SJA1000_ECC_BIT: + cf->data[2] |= CAN_ERR_PROT_BIT; + break; + case SJA1000_ECC_FORM: + cf->data[2] |= CAN_ERR_PROT_FORM; + break; + case SJA1000_ECC_STUFF: + cf->data[2] |= CAN_ERR_PROT_STUFF; + break; + default: + cf->data[3] = ecc & SJA1000_ECC_SEG; + break; + } } /* Error occurred during transmission? */ - if ((ecc & SJA1000_ECC_DIR) == 0) - cf->data[2] |= CAN_ERR_PROT_TX; + if ((ecc & SJA1000_ECC_DIR) == 0) { + stats->tx_errors++; + if (skb) + cf->data[2] |= CAN_ERR_PROT_TX; + } else { + stats->rx_errors++; + } - if (dev->can.state == CAN_STATE_ERROR_WARNING || - dev->can.state == CAN_STATE_ERROR_PASSIVE) { + if (skb && (dev->can.state == CAN_STATE_ERROR_WARNING || + dev->can.state == CAN_STATE_ERROR_PASSIVE)) { cf->can_id |= CAN_ERR_CRTL; cf->data[1] = (txerr > rxerr) ? CAN_ERR_CRTL_TX_PASSIVE : CAN_ERR_CRTL_RX_PASSIVE; } } else if (msg->type == CPC_MSG_TYPE_OVERRUN) { - cf->can_id |= CAN_ERR_CRTL; - cf->data[1] = CAN_ERR_CRTL_RX_OVERFLOW; + if (skb) { + cf->can_id |= CAN_ERR_CRTL; + cf->data[1] = CAN_ERR_CRTL_RX_OVERFLOW; + } stats->rx_over_errors++; stats->rx_errors++; } - netif_rx(skb); + if (skb) + netif_rx(skb); } /*