From patchwork Fri Sep 18 01:07:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 260683 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=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 1B739C43464 for ; Fri, 18 Sep 2020 01:07:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C4C082072E for ; Fri, 18 Sep 2020 01:07:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="rdWj32tL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726148AbgIRBHk (ORCPT ); Thu, 17 Sep 2020 21:07:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725987AbgIRBHi (ORCPT ); Thu, 17 Sep 2020 21:07:38 -0400 Received: from mail-ej1-x643.google.com (mail-ej1-x643.google.com [IPv6:2a00:1450:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B202C06174A for ; Thu, 17 Sep 2020 18:07:38 -0700 (PDT) Received: by mail-ej1-x643.google.com with SMTP id r7so5780860ejs.11 for ; Thu, 17 Sep 2020 18:07:38 -0700 (PDT) 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=+kWCR6aUEJm2UH9U9WnCYeVYUUyNOBgXHiL7tHQV/g0=; b=rdWj32tLSyQ8XfssA+jsfNQVWmRTg//l6qn8HWQFYnOXrPZ6Bty9VxCwSLhuHJEtej 23GXai+euyGfS1UUuianpJjverGFniDh0Si63gW4sO4iAtpw53hHoQatAFAHzh33QzeQ tZS/91WPAeX1x1128wcajjjn4F+pLBrkzsgWZG/ooQO/OrCOSjITC2okvnqekxoxe0ci w0CEvAi4XiGM3XLx5lr2a8/3/ODFVJbCbqU6IgD4zPzQhZ5Z4RG4lOjRbHuzSQvCZscI ZTVeXccZKfdPjzE5pvQxeMpQ+1p0mRihhhSMmlDM7HbNUgDLE5B3QNwbnEwig+DvVABm 0ZuQ== 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=+kWCR6aUEJm2UH9U9WnCYeVYUUyNOBgXHiL7tHQV/g0=; b=aF/bUNnYg1m582K5cthkgWF4qc/w8aat2XuzAOOdnQMyS5ykgHFfxzbd6rAYRDIr5o 2FdDRVwqYp+CTdjrjFzNzDYWmIqpKUMz9lz11mU493HQcQ5YMSMaHfNpMFWCue4UbSw1 9iUUJhjj6BNe93djjz/rlZQhp/Kcx8GyLoRkCtlVPXufKgufgVFYNyVGpwLyuEgjo6aQ G1zatDg9l7EXBHgbnX1fz/JXzz0ih+5IPPQIKsXrZcGWxFsifh2KVq3uUVYQAePf1e+w fixFHhOyyLH25G828tMwDXXQz4IerqPnXzCxsfr6qD1F+VUuH6tniw8ujk0uPbFigEXk uzQA== X-Gm-Message-State: AOAM533E+2Krs2lZnMxmp0dA95zJI5DmJSKGLfADgLNtgv4m2jpFtsBq xgJb692pYxEGd83K5gNCuCBCrXt2YrI= X-Google-Smtp-Source: ABdhPJy4DFXG9vjRvk6CQ8RqWm+QGjSQZqJ80h3Gl0FedcA5wHFbSAud9tI/NDpeOU3SR1BVuOvmxA== X-Received: by 2002:a17:906:7c82:: with SMTP id w2mr32873346ejo.87.1600391256731; Thu, 17 Sep 2020 18:07:36 -0700 (PDT) Received: from localhost.localdomain ([188.25.217.212]) by smtp.gmail.com with ESMTPSA id g20sm1068591ejx.12.2020.09.17.18.07.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2020 18:07:36 -0700 (PDT) From: Vladimir Oltean To: davem@davemloft.net, netdev@vger.kernel.org Cc: yangbo.lu@nxp.com, xiaoliang.yang_1@nxp.com, UNGLinuxDriver@microchip.com, claudiu.manoil@nxp.com, alexandre.belloni@bootlin.com, andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, kuba@kernel.org Subject: [PATCH v2 net 1/8] net: mscc: ocelot: fix race condition with TX timestamping Date: Fri, 18 Sep 2020 04:07:23 +0300 Message-Id: <20200918010730.2911234-2-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918010730.2911234-1-olteanv@gmail.com> References: <20200918010730.2911234-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean The TX-timestampable skb is added late to the ocelot_port->tx_skbs. It is in a race with the TX timestamp IRQ, which checks that queue trying to match the timestamp with the skb by the ts_id. The skb should be added to the queue before the IRQ can fire. Fixes: 4e3b0468e6d7 ("net: mscc: PTP Hardware Clock (PHC) support") Signed-off-by: Vladimir Oltean Reviewed-by: Horatiu Vultur --- Changes in v2: None. drivers/net/ethernet/mscc/ocelot_net.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/mscc/ocelot_net.c b/drivers/net/ethernet/mscc/ocelot_net.c index 0668d23cdbfa..cacabc23215a 100644 --- a/drivers/net/ethernet/mscc/ocelot_net.c +++ b/drivers/net/ethernet/mscc/ocelot_net.c @@ -330,6 +330,7 @@ static int ocelot_port_xmit(struct sk_buff *skb, struct net_device *dev) u8 grp = 0; /* Send everything on CPU group 0 */ unsigned int i, count, last; int port = priv->chip_port; + bool do_tstamp; val = ocelot_read(ocelot, QS_INJ_STATUS); if (!(val & QS_INJ_STATUS_FIFO_RDY(BIT(grp))) || @@ -344,10 +345,14 @@ static int ocelot_port_xmit(struct sk_buff *skb, struct net_device *dev) info.vid = skb_vlan_tag_get(skb); /* Check if timestamping is needed */ + do_tstamp = (ocelot_port_add_txtstamp_skb(ocelot_port, skb) == 0); + if (ocelot->ptp && shinfo->tx_flags & SKBTX_HW_TSTAMP) { info.rew_op = ocelot_port->ptp_cmd; - if (ocelot_port->ptp_cmd == IFH_REW_OP_TWO_STEP_PTP) + if (ocelot_port->ptp_cmd == IFH_REW_OP_TWO_STEP_PTP) { info.rew_op |= (ocelot_port->ts_id % 4) << 3; + ocelot_port->ts_id++; + } } ocelot_gen_ifh(ifh, &info); @@ -380,12 +385,9 @@ static int ocelot_port_xmit(struct sk_buff *skb, struct net_device *dev) dev->stats.tx_packets++; dev->stats.tx_bytes += skb->len; - if (!ocelot_port_add_txtstamp_skb(ocelot_port, skb)) { - ocelot_port->ts_id++; - return NETDEV_TX_OK; - } + if (!do_tstamp) + dev_kfree_skb_any(skb); - dev_kfree_skb_any(skb); return NETDEV_TX_OK; } From patchwork Fri Sep 18 01:07:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 260684 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=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 0AC99C43464 for ; Fri, 18 Sep 2020 01:07:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B98FD208DB for ; Fri, 18 Sep 2020 01:07:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jHWhDRDE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726185AbgIRBHl (ORCPT ); Thu, 17 Sep 2020 21:07:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726093AbgIRBHj (ORCPT ); Thu, 17 Sep 2020 21:07:39 -0400 Received: from mail-ej1-x644.google.com (mail-ej1-x644.google.com [IPv6:2a00:1450:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AE44C061756 for ; Thu, 17 Sep 2020 18:07:39 -0700 (PDT) Received: by mail-ej1-x644.google.com with SMTP id q13so5796036ejo.9 for ; Thu, 17 Sep 2020 18:07:39 -0700 (PDT) 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=gMnn+3ijzX9xUjpcQpFh+UbI23b8gpkZfS877nin950=; b=jHWhDRDEhnjyqlonIiGsyJJnu+iLgcSfCLV7/8QnqGkxULYDbrAQTDl+iPRvmN340h 4ZmLpWN5iFXMamgEWT40Pjr+iVqOFWV54leFCq4Gt7tozlVr6uqaIqS7G4IpyxQjFJnB 0173b5imWUEAkQBOkVQ9SJWmWhi2A2XBYh1+kIC1wdD38pfsYAE/1skcRCM9HkxuxZ7+ rjkSowm34Olb2VuR0mEDVSVFQjvi+roOL/eyeKBoz9w7fnupb9KMhngpxxWCLiHtTBCg vO93uWlpZoaM/yE/lTnxL1eu0SIA/O+4YZJa7da7glOGmuWZ5rSXyKwk0J6UStsiv0j/ 8zCg== 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=gMnn+3ijzX9xUjpcQpFh+UbI23b8gpkZfS877nin950=; b=WFC77QhhQc2tAhcu26gp/3/BqOhw0BnsY5+Be9RrlJr+BmHuWyKsHu6ZOtIxa8ySQo YLRgbCeCDxOQtF3C6eDfdzfpOyCPdJg/vGSLsBShTiyMxCDM5xv8ELk7rIrFapyQI0QI HrwtRj5cKkRUNgfoWga/ETgn9TfYpbW7kDgPhVFxlEM4ZfVqCD9xiVXyHIVcaMAz6sst oOjdRSXKPhf3quXQHOkTubLkdfb8g3X1HyzwcH6oI5kXdOqjrAOyYD/kFJBqmV6c7cad cHVNOAYzmesIq6nO08jYsq3m+F3HWov07oS/GQ50aKhGc9Hq0w0UWxF5/glv6bymwOUE wOmg== X-Gm-Message-State: AOAM53054qMUx6LtWsU9+KHw0cVtTlnxj3l/xfbcrN7TaA9wsLWCPe/k UrGH01m1PEE0d0HbIOuc2WQ= X-Google-Smtp-Source: ABdhPJynxj89yr59WS1v5qc2Mq9TDC5yJcE9iU5/Wyd4cV6YXyw0Wd3lZmPmfD6amrsgfaug7hY7ng== X-Received: by 2002:a17:907:aa9:: with SMTP id bz9mr32563451ejc.421.1600391257900; Thu, 17 Sep 2020 18:07:37 -0700 (PDT) Received: from localhost.localdomain ([188.25.217.212]) by smtp.gmail.com with ESMTPSA id g20sm1068591ejx.12.2020.09.17.18.07.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2020 18:07:37 -0700 (PDT) From: Vladimir Oltean To: davem@davemloft.net, netdev@vger.kernel.org Cc: yangbo.lu@nxp.com, xiaoliang.yang_1@nxp.com, UNGLinuxDriver@microchip.com, claudiu.manoil@nxp.com, alexandre.belloni@bootlin.com, andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, kuba@kernel.org Subject: [PATCH v2 net 2/8] net: mscc: ocelot: add locking for the port TX timestamp ID Date: Fri, 18 Sep 2020 04:07:24 +0300 Message-Id: <20200918010730.2911234-3-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918010730.2911234-1-olteanv@gmail.com> References: <20200918010730.2911234-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean The ocelot_port->ts_id is used to: (a) populate skb->cb[0] for matching the TX timestamp in the PTP IRQ with an skb. (b) populate the REW_OP from the injection header of the ongoing skb. Only then is ocelot_port->ts_id incremented. This is a problem because, at least theoretically, another timestampable skb might use the same ocelot_port->ts_id before that is incremented. Normally all transmit calls are serialized by the netdev transmit spinlock, but in this case, ocelot_port_add_txtstamp_skb() is also called by DSA, which has started declaring the NETIF_F_LLTX feature since commit 2b86cb829976 ("net: dsa: declare lockless TX feature for slave ports"). So the logic of using and incrementing the timestamp id should be atomic per port. The solution is to use the global ocelot_port->ts_id only while protected by the associated ocelot_port->ts_id_lock. That's where we populate skb->cb[0]. Note that for ocelot, ocelot_port_add_txtstamp_skb is called for the actual skb, but for felix, it is called for the skb's clone. That is something which will also be changed in the future. Signed-off-by: Vladimir Oltean Reviewed-by: Horatiu Vultur Reviewed-by: Florian Fainelli Tested-by: Alexandre Belloni Reviewed-by: Alexandre Belloni --- Changes in v2: Added an extra explanation about NETIF_F_LLTX in commit message. drivers/net/ethernet/mscc/ocelot.c | 8 +++++++- drivers/net/ethernet/mscc/ocelot_net.c | 6 ++---- include/soc/mscc/ocelot.h | 1 + net/dsa/tag_ocelot.c | 11 +++++++---- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/mscc/ocelot.c b/drivers/net/ethernet/mscc/ocelot.c index 5abb7d2b0a9e..83eb7c325061 100644 --- a/drivers/net/ethernet/mscc/ocelot.c +++ b/drivers/net/ethernet/mscc/ocelot.c @@ -421,10 +421,15 @@ int ocelot_port_add_txtstamp_skb(struct ocelot_port *ocelot_port, if (ocelot->ptp && shinfo->tx_flags & SKBTX_HW_TSTAMP && ocelot_port->ptp_cmd == IFH_REW_OP_TWO_STEP_PTP) { + spin_lock(&ocelot_port->ts_id_lock); + shinfo->tx_flags |= SKBTX_IN_PROGRESS; /* Store timestamp ID in cb[0] of sk_buff */ - skb->cb[0] = ocelot_port->ts_id % 4; + skb->cb[0] = ocelot_port->ts_id; + ocelot_port->ts_id = (ocelot_port->ts_id + 1) % 4; skb_queue_tail(&ocelot_port->tx_skbs, skb); + + spin_unlock(&ocelot_port->ts_id_lock); return 0; } return -ENODATA; @@ -1300,6 +1305,7 @@ void ocelot_init_port(struct ocelot *ocelot, int port) struct ocelot_port *ocelot_port = ocelot->ports[port]; skb_queue_head_init(&ocelot_port->tx_skbs); + spin_lock_init(&ocelot_port->ts_id_lock); /* Basic L2 initialization */ diff --git a/drivers/net/ethernet/mscc/ocelot_net.c b/drivers/net/ethernet/mscc/ocelot_net.c index cacabc23215a..8490e42e9e2d 100644 --- a/drivers/net/ethernet/mscc/ocelot_net.c +++ b/drivers/net/ethernet/mscc/ocelot_net.c @@ -349,10 +349,8 @@ static int ocelot_port_xmit(struct sk_buff *skb, struct net_device *dev) if (ocelot->ptp && shinfo->tx_flags & SKBTX_HW_TSTAMP) { info.rew_op = ocelot_port->ptp_cmd; - if (ocelot_port->ptp_cmd == IFH_REW_OP_TWO_STEP_PTP) { - info.rew_op |= (ocelot_port->ts_id % 4) << 3; - ocelot_port->ts_id++; - } + if (ocelot_port->ptp_cmd == IFH_REW_OP_TWO_STEP_PTP) + info.rew_op |= skb->cb[0] << 3; } ocelot_gen_ifh(ifh, &info); diff --git a/include/soc/mscc/ocelot.h b/include/soc/mscc/ocelot.h index da369b12005f..4521dd602ddc 100644 --- a/include/soc/mscc/ocelot.h +++ b/include/soc/mscc/ocelot.h @@ -566,6 +566,7 @@ struct ocelot_port { u8 ptp_cmd; struct sk_buff_head tx_skbs; u8 ts_id; + spinlock_t ts_id_lock; phy_interface_t phy_mode; diff --git a/net/dsa/tag_ocelot.c b/net/dsa/tag_ocelot.c index 42f327c06dca..b4fc05cafaa6 100644 --- a/net/dsa/tag_ocelot.c +++ b/net/dsa/tag_ocelot.c @@ -160,11 +160,14 @@ static struct sk_buff *ocelot_xmit(struct sk_buff *skb, packing(injection, &qos_class, 19, 17, OCELOT_TAG_LEN, PACK, 0); if (ocelot->ptp && (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) { + struct sk_buff *clone = DSA_SKB_CB(skb)->clone; + rew_op = ocelot_port->ptp_cmd; - if (ocelot_port->ptp_cmd == IFH_REW_OP_TWO_STEP_PTP) { - rew_op |= (ocelot_port->ts_id % 4) << 3; - ocelot_port->ts_id++; - } + /* Retrieve timestamp ID populated inside skb->cb[0] of the + * clone by ocelot_port_add_txtstamp_skb + */ + if (ocelot_port->ptp_cmd == IFH_REW_OP_TWO_STEP_PTP) + rew_op |= clone->cb[0] << 3; packing(injection, &rew_op, 125, 117, OCELOT_TAG_LEN, PACK, 0); } From patchwork Fri Sep 18 01:07:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 260681 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=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 3731FC43463 for ; Fri, 18 Sep 2020 01:07:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EED202085B for ; Fri, 18 Sep 2020 01:07:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="C9ATBbyM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726280AbgIRBHx (ORCPT ); Thu, 17 Sep 2020 21:07:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726102AbgIRBHl (ORCPT ); Thu, 17 Sep 2020 21:07:41 -0400 Received: from mail-ej1-x641.google.com (mail-ej1-x641.google.com [IPv6:2a00:1450:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70577C06174A for ; Thu, 17 Sep 2020 18:07:41 -0700 (PDT) Received: by mail-ej1-x641.google.com with SMTP id i22so5844451eja.5 for ; Thu, 17 Sep 2020 18:07:41 -0700 (PDT) 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=JhTFGyHSOYaDmD7ZbQ4GySgnyfZ0q7Iyo42XR1Uixhs=; b=C9ATBbyM3A7zv712Gcu8I7X04taxbRcI8OrjDckjme0y9CQJeg1jMdvxCVDGfgkFEw yw/PqvcrWs0+c2mcl1qKPtDmdPExKhjqCgD/MwDpxeYcqUQnXP5nejINyIJ1D/uijUrH z2UyclUGNmGZaWwYEPm0b5HDYeO871CRDDYEbvKRI6K384xv/9BaFOQOcW6JestISB75 qyO+PgLeww3MGsBMbUvq2nAQ+Vjw5njUq9RYg7QumLuNbm40zy8UgtDbHRUaXMp8twWb UsHgR25gZGJEFsJsngQMlI6JbiCIa5Mkiyt27JxY4+EKaxmtHcu8OMqOrVXqUpbIKGz5 yurA== 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=JhTFGyHSOYaDmD7ZbQ4GySgnyfZ0q7Iyo42XR1Uixhs=; b=Jr56hknDXb0IyoVZxiSFKmRnp0AczxqHkZvpLBuQEj4A/ohCegMV0BBI7SfzO+Kzgu uUM8nAwRQgPOALkKcAEQVJjZKCqnh3Jx/x8IAzASAVoluKh0XgJ9G64n8SuyWvxVq37+ rZwu2/3y63IFs9Y2QdS3tMnvd9R+UgTK2PwEQP6Z7TnV8on+YBN0XOUAhoWYxlmKp4nY YT/Vwb/6Pw2nphHB2m8tTjlo4F7MNLoybx371IdV9bP2pmgC91nV2mO5zj4szJ7Ul7Sa NwuujYPwxaDU3z83Vnc3KdyKQNGl8YkA85Serjz1F2oE7hH1af24RIaZpp6NlJP5QiXa aE4w== X-Gm-Message-State: AOAM530Z7mbgoRybtrV6sIug9iHk8s1t4MmUtJLo2K3nR/mq5G55dGqP E5vC0Xhj6F9EBUKShTGUv30= X-Google-Smtp-Source: ABdhPJyIkDROlfwHurVgSb6o5vfY6bOFuGWY7PcfanmLZiFR52yEzZeKQzI52Lf1vSxUdLdtzcWLzg== X-Received: by 2002:a17:906:4819:: with SMTP id w25mr33283093ejq.300.1600391260092; Thu, 17 Sep 2020 18:07:40 -0700 (PDT) Received: from localhost.localdomain ([188.25.217.212]) by smtp.gmail.com with ESMTPSA id g20sm1068591ejx.12.2020.09.17.18.07.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2020 18:07:39 -0700 (PDT) From: Vladimir Oltean To: davem@davemloft.net, netdev@vger.kernel.org Cc: yangbo.lu@nxp.com, xiaoliang.yang_1@nxp.com, UNGLinuxDriver@microchip.com, claudiu.manoil@nxp.com, alexandre.belloni@bootlin.com, andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, kuba@kernel.org Subject: [PATCH v2 net 4/8] net: mscc: ocelot: check for errors on memory allocation of ports Date: Fri, 18 Sep 2020 04:07:26 +0300 Message-Id: <20200918010730.2911234-5-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918010730.2911234-1-olteanv@gmail.com> References: <20200918010730.2911234-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean Do not proceed probing if we couldn't allocate memory for the ports array, just error out. Signed-off-by: Vladimir Oltean Reviewed-by: Horatiu Vultur Reviewed-by: Florian Fainelli Tested-by: Alexandre Belloni Reviewed-by: Alexandre Belloni --- Changes in v2: Stopped leaking the 'ports' OF node. drivers/net/ethernet/mscc/ocelot_vsc7514.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/ethernet/mscc/ocelot_vsc7514.c b/drivers/net/ethernet/mscc/ocelot_vsc7514.c index 65408bc994c4..904ea299a5e8 100644 --- a/drivers/net/ethernet/mscc/ocelot_vsc7514.c +++ b/drivers/net/ethernet/mscc/ocelot_vsc7514.c @@ -993,6 +993,10 @@ static int mscc_ocelot_probe(struct platform_device *pdev) ocelot->ports = devm_kcalloc(&pdev->dev, ocelot->num_phys_ports, sizeof(struct ocelot_port *), GFP_KERNEL); + if (!ocelot->ports) { + err = -ENOMEM; + goto out_put_ports; + } ocelot->vcap_is2_keys = vsc7514_vcap_is2_keys; ocelot->vcap_is2_actions = vsc7514_vcap_is2_actions; From patchwork Fri Sep 18 01:07:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 260682 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=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 E87C3C43465 for ; Fri, 18 Sep 2020 01:07:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 97C142085B for ; Fri, 18 Sep 2020 01:07:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TzauTAOV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726249AbgIRBHs (ORCPT ); Thu, 17 Sep 2020 21:07:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726219AbgIRBHp (ORCPT ); Thu, 17 Sep 2020 21:07:45 -0400 Received: from mail-ed1-x541.google.com (mail-ed1-x541.google.com [IPv6:2a00:1450:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8408C06178A for ; Thu, 17 Sep 2020 18:07:44 -0700 (PDT) Received: by mail-ed1-x541.google.com with SMTP id ay8so4367544edb.8 for ; Thu, 17 Sep 2020 18:07:44 -0700 (PDT) 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=UXyJVTLZgb57NxbzPrOGCROeLHJYT91XwtzL9vJNF84=; b=TzauTAOVqWipnHgtaXburYrL3Rj7386MCos1BoK2Ur7s9q+n7pDdcPTpbl7b0f7aS4 WLt2gTnf6Xnsw7hhcyJe1FfPEAWgc0VETrLQA4MZjhvK9jWnY02SSSW15Wg2SzM2ppfN 66KWF9q4OKkV7Y757TK56vf5abDCbquWzeMy2zXbAENn8txLKIB1B9xGJ6JUfV/j5xB7 tXy9AaO+RH08NqwcCMKVvo6hmRaH4cIqtT2+1iJk9QOTkaEn2plWuzDbXkgOCZdJY3rS 2FqYRdplI504nJq0Mk9P6iyp2rg6OI2VUB16lUINMGeHSdiZ4PgzVuY8fX9r0Z7zSEJ9 OwHg== 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=UXyJVTLZgb57NxbzPrOGCROeLHJYT91XwtzL9vJNF84=; b=th5jchm+b7nyd+Mm1KEqsf0ti+0mltIks3prfwrXwTuCKwuXt7i4bEQ4jVlBISA+zs dUBjk1FDut0ankG68tEIPo4pSDwtXnRFaBS4uChts2yeeMv7+Jtv+mrZfM4aPixLGhPg v3SCv+NYywvN5L+B/MnzU9IwgbLND2C0/nus7632JRH8tmfsUqjlvgpStGcO4WBQXlNz aZXWS2CJHOJ/TXop3w48257OfONq1Jmlwv4rboxVXxzESUWcO669t/1klF0TU51nPU7U QTlGqLxiUQ4JVuhOhcpc1MGpbpB6qRUsyHEl+r1gjaa88QASctQmYRvGCy7TZyRrQAA3 OoGw== X-Gm-Message-State: AOAM531XKGlB+TFWvoA6ZXBxz8yuxbP75Z39pyxi1SRe9fJ1Udf+OyAZ +htscqbjqSjQxW2sfVn6820= X-Google-Smtp-Source: ABdhPJxOob0ifZk+gH7lJcTo94wF4TjEsP6o7d+6g7cOsLW+19cYBcWRdzyiyzGA6JSG0XqwVVllaA== X-Received: by 2002:a05:6402:cb4:: with SMTP id cn20mr36242278edb.369.1600391263424; Thu, 17 Sep 2020 18:07:43 -0700 (PDT) Received: from localhost.localdomain ([188.25.217.212]) by smtp.gmail.com with ESMTPSA id g20sm1068591ejx.12.2020.09.17.18.07.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2020 18:07:43 -0700 (PDT) From: Vladimir Oltean To: davem@davemloft.net, netdev@vger.kernel.org Cc: yangbo.lu@nxp.com, xiaoliang.yang_1@nxp.com, UNGLinuxDriver@microchip.com, claudiu.manoil@nxp.com, alexandre.belloni@bootlin.com, andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, kuba@kernel.org Subject: [PATCH v2 net 7/8] net: mscc: ocelot: unregister net devices on unbind Date: Fri, 18 Sep 2020 04:07:29 +0300 Message-Id: <20200918010730.2911234-8-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918010730.2911234-1-olteanv@gmail.com> References: <20200918010730.2911234-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean This driver was not unregistering its network interfaces on unbind. Now it is. Signed-off-by: Vladimir Oltean Reviewed-by: Horatiu Vultur Reviewed-by: Florian Fainelli Tested-by: Alexandre Belloni Reviewed-by: Alexandre Belloni --- Changes in v2: No longer call mscc_ocelot_release_ports from the regular exit path of mscc_ocelot_init_ports, which was incorrect. drivers/net/ethernet/mscc/ocelot_vsc7514.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/net/ethernet/mscc/ocelot_vsc7514.c b/drivers/net/ethernet/mscc/ocelot_vsc7514.c index ff4a01424953..252c49b5f22b 100644 --- a/drivers/net/ethernet/mscc/ocelot_vsc7514.c +++ b/drivers/net/ethernet/mscc/ocelot_vsc7514.c @@ -896,6 +896,26 @@ static struct ptp_clock_info ocelot_ptp_clock_info = { .enable = ocelot_ptp_enable, }; +static void mscc_ocelot_release_ports(struct ocelot *ocelot) +{ + int port; + + for (port = 0; port < ocelot->num_phys_ports; port++) { + struct ocelot_port_private *priv; + struct ocelot_port *ocelot_port; + + ocelot_port = ocelot->ports[port]; + if (!ocelot_port) + continue; + + priv = container_of(ocelot_port, struct ocelot_port_private, + port); + + unregister_netdev(priv->dev); + free_netdev(priv->dev); + } +} + static int mscc_ocelot_init_ports(struct platform_device *pdev, struct device_node *ports) { @@ -1132,6 +1152,7 @@ static int mscc_ocelot_remove(struct platform_device *pdev) struct ocelot *ocelot = platform_get_drvdata(pdev); ocelot_deinit_timestamp(ocelot); + mscc_ocelot_release_ports(ocelot); ocelot_deinit(ocelot); unregister_switchdev_blocking_notifier(&ocelot_switchdev_blocking_nb); unregister_switchdev_notifier(&ocelot_switchdev_nb);