From patchwork Sat Feb 13 22:37:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12087043 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 56139C433E6 for ; Sat, 13 Feb 2021 22:39:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1BBD464DDA for ; Sat, 13 Feb 2021 22:39:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229777AbhBMWjK (ORCPT ); Sat, 13 Feb 2021 17:39:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229730AbhBMWjD (ORCPT ); Sat, 13 Feb 2021 17:39:03 -0500 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE2C9C061786 for ; Sat, 13 Feb 2021 14:38:22 -0800 (PST) Received: by mail-ej1-x629.google.com with SMTP id u18so3313625ejf.6 for ; Sat, 13 Feb 2021 14:38:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NrkdpwjIRrQpuX6I+2ZUgjz0j4ZIZC+ylH1m8HiwDWM=; b=q4kqSO0oL/ln7e2TyQdkfCQSmU3HFqNv899hIgMOWCJQo+BUtyZn5bjeI3JyNyvqZv 99ds94QmzrZwsmhzr5+5adFdbtcn6X3Tigga73l1WSm52yUg/pFA0zkwLJcEBV2jBNvS TBi4k1NPsimixblRq/Ehb5Azmxsy/6ZmQpn+R/7ZQH53/IEhg59CLoksdZIbfTTGEMF7 2AMHmqzW7fjUY977yg2XzLAN76HJxkF/YHmaLELdwE6ZLqOgtLpUfw+puSd7RUVkX2WH cfdgoONCId0p2TOVMjrwq5nD5dfAnVUrZxf+u+yeWQmz0mY/vfWgEdPL8XZIiRW2l4YR jVUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NrkdpwjIRrQpuX6I+2ZUgjz0j4ZIZC+ylH1m8HiwDWM=; b=pjv1kyzpKKbQew36G7KtbywFhfCYTpZHxrjx3kSLtydrKglZSWOBPY2fJhkvJlvom4 V+43ckNN/rcwv4BPL4L/plwLN9nZTGwM/ONjbDaojhpeaZlLkBXgaXriyepOIA1BaA8t Pc16jBkLpRxiAq7DZLZgKnuziy7473cb9yELwK4/yU4BOtZxT8yNE2L7yw4daWLI0kJL sFCWdwo59oHUO/qvmSUYqk/8UQxWZCzHHdm0uipclckPZz0jCzK3m/5M9gLmRWNFYg5j 1B1KAVdyPFMEL0VRcTVUS3EF08lBip6NJ9aD5NU2M4Wi14FJn7xey5HAH/RvUnUu3ZaM ogeg== X-Gm-Message-State: AOAM532EsqX2/ga/DHeqIqVWr4hBP9Lp661EPg7uV0ieJ0WHfy06VUgW ZI6OMQ0kaaFHPkG0D0lKhDE= X-Google-Smtp-Source: ABdhPJwO1kD41b0tlG6btNGTSemfIXAAqh99R0L0rWQMFfkX89XSBfjfDXXvhrq1YFYs/5KWh6IQgw== X-Received: by 2002:a17:906:e18:: with SMTP id l24mr8919052eji.500.1613255901678; Sat, 13 Feb 2021 14:38:21 -0800 (PST) Received: from localhost.localdomain (5-12-227-87.residential.rdsnet.ro. [5.12.227.87]) by smtp.gmail.com with ESMTPSA id h3sm7662582edw.18.2021.02.13.14.38.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Feb 2021 14:38:21 -0800 (PST) From: Vladimir Oltean To: "David S . Miller" , Jakub Kicinski , netdev@vger.kernel.org Cc: Andrew Lunn , Florian Fainelli , Vivien Didelot , Richard Cochran , Claudiu Manoil , Alexandre Belloni , Vladimir Oltean , Maxim Kochetkov , UNGLinuxDriver@microchip.com Subject: [PATCH v2 net-next 03/12] net: mscc: ocelot: better error handling in ocelot_xtr_irq_handler Date: Sun, 14 Feb 2021 00:37:52 +0200 Message-Id: <20210213223801.1334216-4-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210213223801.1334216-1-olteanv@gmail.com> References: <20210213223801.1334216-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Vladimir Oltean The ocelot_rx_frame_word() function can return a negative error code, however this isn't being checked for consistently. Errors being ignored have not been seen in practice though. Also, some constructs can be simplified by using "goto" instead of repeated "break" statements. Signed-off-by: Vladimir Oltean Reviewed-by: Florian Fainelli --- Changes in v2: None. drivers/net/ethernet/mscc/ocelot_vsc7514.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/mscc/ocelot_vsc7514.c b/drivers/net/ethernet/mscc/ocelot_vsc7514.c index d19efbe6ffd3..b075dc13354a 100644 --- a/drivers/net/ethernet/mscc/ocelot_vsc7514.c +++ b/drivers/net/ethernet/mscc/ocelot_vsc7514.c @@ -619,12 +619,9 @@ static irqreturn_t ocelot_xtr_irq_handler(int irq, void *arg) for (i = 0; i < OCELOT_TAG_LEN / 4; i++) { err = ocelot_rx_frame_word(ocelot, grp, true, &ifh[i]); if (err != 4) - break; + goto out; } - if (err != 4) - break; - /* At this point the IFH was read correctly, so it is safe to * presume that there is no error. The err needs to be reset * otherwise a frame could come in CPU queue between the while @@ -645,7 +642,7 @@ static irqreturn_t ocelot_xtr_irq_handler(int irq, void *arg) if (unlikely(!skb)) { netdev_err(dev, "Unable to allocate sk_buff\n"); err = -ENOMEM; - break; + goto out; } buf_len = info.len - ETH_FCS_LEN; buf = (u32 *)skb_put(skb, buf_len); @@ -653,12 +650,21 @@ static irqreturn_t ocelot_xtr_irq_handler(int irq, void *arg) len = 0; do { sz = ocelot_rx_frame_word(ocelot, grp, false, &val); + if (sz < 0) { + err = sz; + goto out; + } *buf++ = val; len += sz; } while (len < buf_len); /* Read the FCS */ sz = ocelot_rx_frame_word(ocelot, grp, false, &val); + if (sz < 0) { + err = sz; + goto out; + } + /* Update the statistics if part of the FCS was read before */ len -= ETH_FCS_LEN - sz; @@ -667,11 +673,6 @@ static irqreturn_t ocelot_xtr_irq_handler(int irq, void *arg) *buf = val; } - if (sz < 0) { - err = sz; - break; - } - if (ocelot->ptp) { ocelot_ptp_gettime64(&ocelot->ptp_info, &ts); @@ -701,6 +702,7 @@ static irqreturn_t ocelot_xtr_irq_handler(int irq, void *arg) dev->stats.rx_packets++; } +out: if (err < 0) while (ocelot_read(ocelot, QS_XTR_DATA_PRESENT) & BIT(grp)) ocelot_read_rix(ocelot, QS_XTR_RD, grp);