From patchwork Fri Nov 22 22:15:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 3652 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id C6A863F9F7 for ; Fri, 22 Nov 2024 23:17:03 +0100 (CET) Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4315dd8fe7fsf22507025e9.3 for ; Fri, 22 Nov 2024 14:17:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1732313823; cv=pass; d=google.com; s=arc-20240605; b=TdSJb2jgccAi8lj6wQTjngd4uKE6Vy7TPajk50ok94+HPqxVzztaQH36jcLdsi7cC+ kkWgHkZcMlBKePTNgHxhZNOCpwbRD3gW+IECcDkvk83qVXPl2K/3VYKfQQVrrlVP5anf 4tYOOmowi4WC2Ood09Ikr8HADBPsZJi9VkaTM7aIRsnq1S6KeAE+Gm6ZVuLs9rF1TSYh /d5D59gcePn/mjcgOlv4+0/0Pvl8X7rvi8coUGnJ/ifrKGNN17S/IoMklVsyCaRDjmk0 w2zPcC22+0fMWx57Y0f7I1V/JXS+faIYWciNF8ZKNBlqPMBJu1Xhuu+34GbsZ+uhA0m/ oYeQ== 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=kfVOR2PCdtETaGxcQMrMk4jYZfkuMRw1TgrcdTbiOBE=; fh=VJC3HnIf1Sx471o5MCmndGnDTQCQxHiuQffi6cPl+r8=; b=ACO/51sgp9Tx9oQlW8D0wUmVTC9MTxKURkGAEhEKfLIMLE0xHcdJdyne54OLiJM54Q cWEOBizdvyKtIndUFAmrTaDUC6iGzoRrMMbqh9Wwy7cragryTT9Aj06/Rio2E/r2TOUp tEoIIZ9QRnIpoVPFHsdCUX/H8XQnE8AOb4RVNBS8pm3hDdycW3dSY1/CzgV2k3nGJ7gr NzjXDeox3nDd3jy+Nwy7xa71nI4YAwr7+i0nWT3LbgBmNGk5/rnRtQA9XQD9aSIbDe7C /hBRE8ds1a/Tp5KG7QSZ8CA3nCyvthrJ1us9f60DRvfYeuAfzgi0RXdQBmgkn+0u8MVL /tJA==; darn=patchwork.amarulasolutions.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=DfEDuHtB; 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=1732313823; x=1732918623; 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=kfVOR2PCdtETaGxcQMrMk4jYZfkuMRw1TgrcdTbiOBE=; b=G0tYgoHgGWHRh/97oPbWOe0zdAa4NsGj5MJHq2f0pB2mO31c6BBV5Y45D7xisARm5E wYl7DUxen7xAtqXBJD5CtfnnNtjCABRHjKQDtvRFmSHcJgYaxZoweNjtBR2zFJV93sVa Ydzsg1N5d6RZx8L91ovXWCWdzmcak3D+u8968= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732313823; x=1732918623; 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=kfVOR2PCdtETaGxcQMrMk4jYZfkuMRw1TgrcdTbiOBE=; b=CAamH2VYPpUdWhONErkrdQZKCou4LetB0I7kPQdHdYXRUkJ+M2qTp66Z8rR3FzXL0U V72LcWfEPJvR/F3DOMXGMUuGa/93t34wRWAfYZY4uWIgkUJ4oXt3p/xCSMmqbZfWjNFt aFz3Iae0jkw7eCLYmfBBCnAimfy60nkyV0P+ewVj3V4/2cG4NGyzuZ8fK3cXxWSbkDY9 Kp60ikmqHKHi6br54vsTzUTX+54KJC0llk4Tic3j41v/8EoKap+TXS4We4Lq8zKffTrL u4asTY0n/dWV+svjHjjcloWbTPsBFEEGqmMXmDy5gO+wW79b+IrywLIy6pMily3Nlxch i98A== X-Forwarded-Encrypted: i=2; AJvYcCXUnNZow/vfXFkHuQh+IiE5wTLXiNTHfrvjcV1lU8OGSMqwOvoSRXKLYRNQRI8xbqqtY5WOfmPCPhM5kaGt@patchwork.amarulasolutions.com X-Gm-Message-State: AOJu0Yz5t7A8jBD/xFyAJdbMQz+sycYOZzlhRPUtMW5MhJFOhM0HIPx7 PKJ8b2ViYJHN6+YNd/tdeieaykUbDSiFfb89MJPZG0aHZI5Q9KVHAcjbYzw4zSyOUw== X-Google-Smtp-Source: AGHT+IEgA+6O8Y//Y8o88c3FqNEaoe8XINcFl9pF5dvxspfgkGAdYy+icERBulxcq2OwZJoSREp/UQ== X-Received: by 2002:a05:600c:4704:b0:426:59fe:ac27 with SMTP id 5b1f17b1804b1-433ce48fd61mr39405075e9.26.1732313823387; Fri, 22 Nov 2024 14:17:03 -0800 (PST) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:600c:4f44:b0:42c:af5b:fac1 with SMTP id 5b1f17b1804b1-433c5df5104ls16794965e9.1.-pod-prod-05-eu; Fri, 22 Nov 2024 14:17:02 -0800 (PST) X-Received: by 2002:a05:600c:3ac3:b0:431:4b88:d407 with SMTP id 5b1f17b1804b1-433ce410255mr42693175e9.5.1732313821602; Fri, 22 Nov 2024 14:17:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1732313821; cv=none; d=google.com; s=arc-20240605; b=eU8JvpERSONUQXUcsKeptNJN83mW817zscg+pcPHkWl++G7BTaxOtyqfJMCJ8z4Sco c/t+G6JGK12Ka3oDgqyPhmJ+GfAZju95ML15ZuemHKyq/Qz5TGu98l+f7ccdBhQ6GmaD hLEraiGNPHwJOdXOy1h3SeWfA6NVdIf4OWr4gu1XyeQ/BixNzJfwdC2BdnYxU7SZ45hr LpeFYqb8PTUt3uhLoPrcTZpsgdGBlkGvhdh56HlTKXF5NfM/iqpQxREF40gJoVVbuCRz PHETSkUbY/aWIxUx0U7glqOkGxq7rOMjtgIEeAosE7boMtzdIKDkK6y8MaqZDwLD0XVr zs+w== 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=RX04a1ntmZvpkxNuR7+A/BvpYp1w7zMI7wCHavx9c7Q=; fh=nWJlPYMhwdWw+bQDuOxuihlZNxl/SL585p0KRUhQI9Q=; b=JOUfdIewSZ379D4H/68lY5Y7ltYdMnC2K2P6AeBeqXrKyzsrjrYSsh5e7scuzfvlRS N3yBH8IJ/pP0FNDTo/CvHRDGXxw66GD6leHjEu17xQlNUyxIzEy7zuAFdZEAbJWJ6Ez4 iMh/uSOviYc1B+ClSi+DCjHJX28ogc5jy3smHZQssjDQLDs3ed94PxOSq91rIWwduc+j oSplCPCmo8P93Z0xZo9KTENB8bf53+5GmzOSFeOXbDzRCKPwtfq5T+QvSnsbX5KM3JfO tnsX2Bakv9UddN0raiYno1WSfEcBRqDhvqGND7mkj7XhoVqMTlFVnCvXHpjdkXHCgoey iwdw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=DfEDuHtB; 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 5b1f17b1804b1-433cd881fdbsor15315635e9.10.2024.11.22.14.17.01 for (Google Transport Security); Fri, 22 Nov 2024 14:17:01 -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: ASbGncsxGuDd4FYnYulR4hdFuBXieeyblfjBkAH4DFfJBPOcxnt1S7KiLakbE5nILjD Fg2dsamQKQbpF5p8MtxUHUiUrE1Z3q+7+cZ77CxTMG/a5XPB9FhTHdmsDuyXQ089LQLWs9oNQXo XFoLl8vAu1cnvSBHXgjVHpG68ittKTk2B0SXzWb7JdsaUJGZoBZr0/U01C34oDWQnDiPqxFb4Ih ByN7bJtl9G+26eopT0HoY/oj2r24ugx46/840OMKhW41+kTPMUX4Tw0MOezSStgUNeakdYsugdB rJjEN8+F6Ho+bgOfdKVBOjSURi5qshWbT1foEBQriWkv+OaKkOnLgubq/mdWImaQ5tsTYZSepFH 0ZZ3aobyAPoZWFTKV X-Received: by 2002:a05:6000:1788:b0:382:51d7:a2e0 with SMTP id ffacd0b85a97d-38260b61f45mr4102854f8f.27.1732313821142; Fri, 22 Nov 2024 14:17:01 -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.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Nov 2024 14:17:00 -0800 (PST) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: linux-amarula@amarulasolutions.com, Dario Binacchi , Chandrasekar Ramakrishnan , Dong Aisheng , Fengguang Wu , Marc Kleine-Budde , Varka Bhadram , Vincent Mailhol , linux-can@vger.kernel.org Subject: [PATCH v2 06/12] can: m_can: fix {rx,tx}_errors statistics Date: Fri, 22 Nov 2024 23:15:47 +0100 Message-ID: <20241122221650.633981-7-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=DfEDuHtB; 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 m_can_handle_lec_err() function was incorrectly incrementing only the receive error counter, even in cases of bit or acknowledgment errors that occur during transmission. The patch fixes the issue by incrementing the appropriate counter based on the type of error. Fixes: e0d1f4816f2a ("can: m_can: add Bosch M_CAN controller support") Signed-off-by: Dario Binacchi --- Changes in v2: - Update statistics even if skb allocation fails drivers/net/can/m_can/m_can.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index 16e9e7d7527d..533bcb77c9f9 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -695,47 +695,60 @@ static int m_can_handle_lec_err(struct net_device *dev, u32 timestamp = 0; cdev->can.can_stats.bus_error++; - stats->rx_errors++; /* propagate the error condition to the CAN stack */ skb = alloc_can_err_skb(dev, &cf); - if (unlikely(!skb)) - return 0; /* check for 'last error code' which tells us the * type of the last error to occur on the CAN bus */ - cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR; + if (likely(skb)) + cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR; switch (lec_type) { case LEC_STUFF_ERROR: netdev_dbg(dev, "stuff error\n"); - cf->data[2] |= CAN_ERR_PROT_STUFF; + stats->rx_errors++; + if (likely(skb)) + cf->data[2] |= CAN_ERR_PROT_STUFF; break; case LEC_FORM_ERROR: netdev_dbg(dev, "form error\n"); - cf->data[2] |= CAN_ERR_PROT_FORM; + stats->rx_errors++; + if (likely(skb)) + cf->data[2] |= CAN_ERR_PROT_FORM; break; case LEC_ACK_ERROR: netdev_dbg(dev, "ack error\n"); - cf->data[3] = CAN_ERR_PROT_LOC_ACK; + stats->tx_errors++; + if (likely(skb)) + cf->data[3] = CAN_ERR_PROT_LOC_ACK; break; case LEC_BIT1_ERROR: netdev_dbg(dev, "bit1 error\n"); - cf->data[2] |= CAN_ERR_PROT_BIT1; + stats->tx_errors++; + if (likely(skb)) + cf->data[2] |= CAN_ERR_PROT_BIT1; break; case LEC_BIT0_ERROR: netdev_dbg(dev, "bit0 error\n"); - cf->data[2] |= CAN_ERR_PROT_BIT0; + stats->tx_errors++; + if (likely(skb)) + cf->data[2] |= CAN_ERR_PROT_BIT0; break; case LEC_CRC_ERROR: netdev_dbg(dev, "CRC error\n"); - cf->data[3] = CAN_ERR_PROT_LOC_CRC_SEQ; + stats->rx_errors++; + if (likely(skb)) + cf->data[3] = CAN_ERR_PROT_LOC_CRC_SEQ; break; default: break; } + if (unlikely(!skb)) + return 0; + if (cdev->is_peripheral) timestamp = m_can_get_timestamp(cdev);