From patchwork Fri Nov 22 22:15:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 3647 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-lf1-f71.google.com (mail-lf1-f71.google.com [209.85.167.71]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 85E0941386 for ; Fri, 22 Nov 2024 23:16:58 +0100 (CET) Received: by mail-lf1-f71.google.com with SMTP id 2adb3069b0e04-53da36a1447sf1846270e87.1 for ; Fri, 22 Nov 2024 14:16:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1732313818; cv=pass; d=google.com; s=arc-20240605; b=PJUukqm2jGzUyHJTe7ZqPYqlKZpuix9g/DlVqJwAEVuyJfkk06ACbSGK3SLuwLMXpw jYBw4b6OqLkkt3U4u5n+QsVe3hqX8sHVamVVNsxrFrvcQaUEwqQsSpVMWiI4NaI6Lg0A 4w6e+m8OTeNevkvUcfKWuWzOBQa4VCl92Pan3Qs2FzIh/1PKa2/+L5yLEYQfwPkzrhUC AVeEEdy6W3HRzU3JFpZEfzmyg2Y/A7R1cMGQRdoF6OQMxg8SGwdLQy1N7DZPIYI91L7P sfW/JrGnaSN8hfQnYV54H8Pb7g+yN55WLNYSPXocq93KxULv5l/F/OYyCoeddMoj29Ta /qCA== 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=BuIhDtH2J2ogmaY60Y+MZlqQh1fDcFk9fy4QE0p046g=; fh=cyAFoQCzV8uJYWeENtGtyAM8i0h5O6f/UI4CEy/xL5g=; b=Sj9toEJfoqRNeSPGbpP5CJGsQBHTljgZRBxrqLPtnp7ronRj4KLuK9YM22tKGcP2yt ezCq2SHPQcJp0SMnAfEEt5oRA3HDVmomgwtRNeTXaC19ji01e1UwEfvXk6ZVXORT0dTq F7ywP2UJc/zqFk1/GCVI2fGLsRm7yV5tX2/0NA6eM/jqpcuFsZfn+wYqz0A1qQRfKB1F 65iTl148ju8x1WDfi6YyIplp2MNR1lRlF9fkZbBGdvD0n9Mc8H3xRYxjDf/BSjiuTyTK ueJYLN2WWNBvz8yIB0P3qzFMfJi33fxYedK02qlhZsb7488MhPN8A8ZGJQFWdthbPrzF szUQ==; darn=patchwork.amarulasolutions.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=SsMKbMay; 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=1732313818; x=1732918618; 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=BuIhDtH2J2ogmaY60Y+MZlqQh1fDcFk9fy4QE0p046g=; b=myxTz0ATm8dr4rC8aTUuUPgdhHwCOS3KlhuRB1S12joPTV4SlaiplqvFW0q5cvSe+J gjKadHGKGW5sVNGbgN2p3TIYSFYQhHHgXJ24DojR8cGXkkIpWIXDZmm9rH3nIwLE8SxQ fYxgA4FKqbvNXLwHRJSf4aLh9wAOTZXR+oRL4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732313818; x=1732918618; 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=BuIhDtH2J2ogmaY60Y+MZlqQh1fDcFk9fy4QE0p046g=; b=G//x1BtZfjsX/3dV2kiMiESa18Q7+b3olkzG+JWwhrdEMUdfrFkot3KmeXip31vSGe uXwqHLZ83aqjbRgi7EgntjnMSRMy6wLeq9Na1j1UEs/GIMoiMsJ3ltGdfkcPeDHsYiRm HExB1bKNWmJ7xY89IFKE/2BvgwO7yUPoITDorJ0O25QT9HJEODCeIYhkyauCWMvJYv2o VippH9++Ir+Zjn9DGLTL1XQ9ig7QQf0RVHZ9IdCA8wMuilxeA8JApdy6QdWTiUhxTqcR VMzPGNFhZf1+EPHFkDQoZ6wQnRWP5jSOFJlLSNmGbwMUPZ4b9hjz0dwMNLzkEgZOM4Es AK1g== X-Forwarded-Encrypted: i=2; AJvYcCX6u9WhQU2C6j7ZLA0wmHQ5MifKx25YEgorI/E8QJErGdg46CTmuCJRhdPKIupThWr3eKm2Iif9Hgp9lkqM@patchwork.amarulasolutions.com X-Gm-Message-State: AOJu0Yw9lf+ahAEjRTj8oMpfdZ8zyC9z6J8L/syEn1McwEZJXBUPj3wk tZfrjzbQc16wX+Ih7rpQJTHtFEETSVX5YB7WRnL+PqBQCZP2L4nCkl0wxynQfwQBE7R0KmGHuA= = X-Google-Smtp-Source: AGHT+IH5hgdainBN++2S/kjWZRyVfJlLraJxgcMQkkgrc2OxtzGYlxGY65KsssMKfc+xRauQMmvHRA== X-Received: by 2002:a05:6512:3a8d:b0:53d:dbe8:af18 with SMTP id 2adb3069b0e04-53ddbe8af6bmr160897e87.44.1732313817915; Fri, 22 Nov 2024 14:16:57 -0800 (PST) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6512:3d89:b0:53a:7e:bcd3 with SMTP id 2adb3069b0e04-53dc6296ca0ls353974e87.1.-pod-prod-06-eu; Fri, 22 Nov 2024 14:16:56 -0800 (PST) X-Received: by 2002:a05:6512:3c89:b0:53d:d57a:1126 with SMTP id 2adb3069b0e04-53dd57a114emr2517536e87.7.1732313815880; Fri, 22 Nov 2024 14:16:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1732313815; cv=none; d=google.com; s=arc-20240605; b=JZFrorfwly5n2jSKfZlEadQ6U048YLgqy39onAhXIslSh3GlUlb1dQSbYLn248oFQw gUFvy2VjvrPlmjsspCD1zDPMgX9OjGwvRWCVb+XLwcMaSMnsNuSzojDWNcRwYfMsX7/N DDKcXbdpG6McXnIP/4sI5yuKd4m6Yfjd1kh9x+k9zwijc2Lvhss0jw1yS57/2Jyp4ysx hbt+WrGMdnPEpFFEFSd1b8Lr8aV10ovOGs0cvv0ECAELv9MsaGn5LcNsRiEVW202/Gfh NorfskxgBuDxrDKOKHQT9TCF70zXSXXnMAIQKEWzFTqRzHTYr0sHKqz0iQFJVu1o1Hnz 2CUQ== 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=eXl+FSVARqVcRtIxq69Tn4oF98SIhVQqmrh7i+R1ZlE=; fh=ljoFiwPup6gC9YG4NMWOEWNdgUd1CKjWIIwpUvYy39c=; b=UuvJoXTHxEiUpMrvmbaMkGrgnTHZ9gtpAl2u+j9T45/D2hnuB33MeJRuL+YtyTwwmO jJf5Kss8P3b7FJEdFCaseDRPzSvtvZizO/dhR8wQNWKIrLyefbCFprA3hkOZaGOma5vS hZqb/wwkq2LXuSUXKia3HUubLZd1fakpgStYL79sUTD/aVPoXd1ctvQpkl0ClfgjD7H1 l3v6utAJqy951rDBUdFLejSBiVdce7wOZjHds/nbkIsp5D4jNeawwCLexvOOZYPROTo+ hi8RhuiLC6rc1z3/I80Gd63Rgin8CzTMVHRc98X6Fy3HNU5YlXbyKATaCePM0tCOVyA4 adgw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=SsMKbMay; 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 2adb3069b0e04-53dd245191bsor778123e87.11.2024.11.22.14.16.55 for (Google Transport Security); Fri, 22 Nov 2024 14:16:55 -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: ASbGnct8Vx+kBHHH47L8GI5WO8ugkneYiT3nUuIOO2nM/fY7PLrkjiOG50f5K3WaCjh lqdjy0eqh4jnWBWwm7nZHPk+erdNjdx6euuxyv1UYCZaX8Ukxu1fGJZtoO5P2UHdgWPri8CKWuI HSyziDt2EoLv1xJTWnmrZ0pgM+ArxQiGdMUmpm4W7jC8D6JQ30FcN5HJCT3erGWARD30FJSqFOs RDuWnCvmKtQ/iq0pH9JY1qxkOMXFhYhAjW+emA9QLXjsnS6yYW4xjfSTaoERVx7uitmRhG9GXRQ R70yOivFrPAhfrL8/8ZEWWqgKE8TzvqUs3IZeHXI4CeIhqHlj0KZVigolaIdOzF/s+cmIQGM2Io JR4z9yMiOtn5boJol X-Received: by 2002:a05:6512:39c3:b0:53d:d957:9f92 with SMTP id 2adb3069b0e04-53dd9579fd5mr1789697e87.9.1732313815331; Fri, 22 Nov 2024 14:16:55 -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.16.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Nov 2024 14:16:55 -0800 (PST) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: linux-amarula@amarulasolutions.com, Dario Binacchi , Marc Kleine-Budde , Vincent Mailhol , linux-can@vger.kernel.org Subject: [PATCH v2 01/12] can: c_can: update statistics if skb allocation fails Date: Fri, 22 Nov 2024 23:15:42 +0100 Message-ID: <20241122221650.633981-2-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=SsMKbMay; 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: , This patch ensures that the statistics are always updated, even if the skb allocation fails. Fixes: 4d6d26537940 ("can: c_can: fix {rx,tx}_errors statistics") Signed-off-by: Dario Binacchi --- Changes in v2: - Added in v2 drivers/net/can/c_can/c_can_main.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/drivers/net/can/c_can/c_can_main.c b/drivers/net/can/c_can/c_can_main.c index 511615dc3341..cc371d0c9f3c 100644 --- a/drivers/net/can/c_can/c_can_main.c +++ b/drivers/net/can/c_can/c_can_main.c @@ -1014,49 +1014,57 @@ static int c_can_handle_bus_err(struct net_device *dev, /* 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; + if (likely(skb)) + cf->data[2] |= CAN_ERR_PROT_STUFF; stats->rx_errors++; break; case LEC_FORM_ERROR: netdev_dbg(dev, "form error\n"); - cf->data[2] |= CAN_ERR_PROT_FORM; + if (likely(skb)) + cf->data[2] |= CAN_ERR_PROT_FORM; stats->rx_errors++; break; case LEC_ACK_ERROR: netdev_dbg(dev, "ack error\n"); - cf->data[3] = CAN_ERR_PROT_LOC_ACK; + if (likely(skb)) + cf->data[3] = CAN_ERR_PROT_LOC_ACK; stats->tx_errors++; break; case LEC_BIT1_ERROR: netdev_dbg(dev, "bit1 error\n"); - cf->data[2] |= CAN_ERR_PROT_BIT1; + if (likely(skb)) + cf->data[2] |= CAN_ERR_PROT_BIT1; stats->tx_errors++; break; case LEC_BIT0_ERROR: netdev_dbg(dev, "bit0 error\n"); - cf->data[2] |= CAN_ERR_PROT_BIT0; + if (likely(skb)) + cf->data[2] |= CAN_ERR_PROT_BIT0; stats->tx_errors++; break; case LEC_CRC_ERROR: netdev_dbg(dev, "CRC error\n"); - cf->data[3] = CAN_ERR_PROT_LOC_CRC_SEQ; + if (likely(skb)) + cf->data[3] = CAN_ERR_PROT_LOC_CRC_SEQ; stats->rx_errors++; break; default: break; } + if (unlikely(!skb)) + return 0; + netif_receive_skb(skb); return 1; }