Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp1146597ybj; Tue, 5 May 2020 14:05:32 -0700 (PDT) X-Google-Smtp-Source: APiQypI/phsi04V4KU2hhvDPSRbFzxBiuD5YS2J1JqwGEfdyJmVxKGtYy1KMIHboYgOKFWigtzl3 X-Received: by 2002:a17:906:f90d:: with SMTP id lc13mr4289376ejb.367.1588712732208; Tue, 05 May 2020 14:05:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588712732; cv=none; d=google.com; s=arc-20160816; b=v4seniM+YNw6tDD3U082FVFRV+TXr1clPadbzTu3LACg3TYKSW2HMiaJJJyVmUTEhn 5XUeJbrgbjMd2esdyqY5lHpqExJaga2RA96iTPqLyKJTG0t29LONpDBUVlGIHSOC3qGH 5eX5TyhjsSmP3vJET37vhb5kV6R2FWKDu/uNpSqOJnj6sSS4GDllU4rQ3cuTOrhGem9G TBxBrmrfrO5SV9XyiwndCIAv0Y4RA6izSSryvu5y4yeleIV9sOcekaCFFSM26ECg0rEj +pAx8CqdnUo3nHJq7NljdGeCtasK/WyrMVoAHt7xejW0NQRS59ppVUuftYoN4jETKTrB zbcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=I0mJ2TcquxeD51nWsq3E4nLfZAHxaYExvmCD1KmEor4=; b=tyb0FPEIfjX0NsF94d1ztDJgOUP5WuH6NHDNACK7VXiBNJxo7qu41D51Xq80pJlSx7 atFDS+A8gu4NrO+sTjYO7AutvGQ4sdC0UZYoOK171bFAf75vv5uV7FP5heTQ0+H71Won Itwi2kD5q2LIDNSiReptcldif9i6rAj2JUmAK42zUO3sF5NqArm0X0I7+fqVrmV/6NTs dEcnB4f02vhj2mq9pV6akCKoEYD9zZNBZD2qBjEtjvRhIqXr1x7PcjZuZmkokTWnH7ce XGY+c8qqYXmMKFRujP/UWOZ1GwyUzjyYmqe57rms1ljo+ZG+jhgnBLO9PUHFPTnzDc// 7FnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=sCFTVHBE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w7si1757628edr.309.2020.05.05.14.05.07; Tue, 05 May 2020 14:05:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=sCFTVHBE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729227AbgEEVDE (ORCPT + 99 others); Tue, 5 May 2020 17:03:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726350AbgEEVDD (ORCPT ); Tue, 5 May 2020 17:03:03 -0400 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CD13C061A0F; Tue, 5 May 2020 14:03:03 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id 18so1516282pfx.6; Tue, 05 May 2020 14:03:03 -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:mime-version :content-transfer-encoding; bh=I0mJ2TcquxeD51nWsq3E4nLfZAHxaYExvmCD1KmEor4=; b=sCFTVHBEXnXfa1xp6uvtRZEwgsGiCG2yXlzboVYMIi9rGcWn8do+UM6d9a3dAmwkns 3bsgfETPukuOY6/+/YdOSBsXNbhJxoaQK3pZC9C3iDbF3eAX1Pm/8TbTtku1PFE0x6gq O2rK7lV7kHPsgotN/VmJ2xhTWCu0lFjdK0rhJKPv+4DHilTAH6wHVJkCxB1FJlBZd1OF /kkSTU2JUMAwR3+yJx3ZTBt4Qnq4LXiz7qj0hkJAhlAKKF9K0BHvm2Ttlc/Fio4nqxsu qCGQw0yskh9H/m8rJ/bc9dGbUfRLnaxZ0Fa1jZ6KPjTqvr9at+IPe1uVcjJafSgHUpO2 IkPA== 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:mime-version :content-transfer-encoding; bh=I0mJ2TcquxeD51nWsq3E4nLfZAHxaYExvmCD1KmEor4=; b=AoGIdy4TwLbPtdcIFHNBOjPR++MtS7KZnOi6/AFbdhtEolLz1hniihAbq9nC1Vcb4+ StjE/0fCTM5JKvvVdHYoZSOjhUNKlTnRJf1niv76KkscJH/+pcvKLmyjxJeoR4Mrynfh c39zo0S0E6AZMaWwjBifRF/FJPY5sbd1p9Y58aHnaXVzuMUZ4gbxiSrEX8hh5/8GigAg v+hTqamPTBPpLEUvYQuMuMXhfWrIDuErx11Yk913V+860Jbg2YgkZxUYMqCfqyKF+mtn ifFLBCxuNKj8wFIgTQi033SoodVFv3wSGcxyUHM5zLhJqkfbA0vREbQ3uCXcf6ggIPX2 pEQg== X-Gm-Message-State: AGi0PuZzFak2jAYO/RycAzguvdFIMH7vudK831uidzcMguzmF4GmnP0C OgkhVG8XBwGbBr9ZlGiRI3UqkRF+ X-Received: by 2002:a63:5542:: with SMTP id f2mr4186377pgm.384.1588712581832; Tue, 05 May 2020 14:03:01 -0700 (PDT) Received: from bender.lan (ip68-111-84-250.oc.oc.cox.net. [68.111.84.250]) by smtp.gmail.com with ESMTPSA id s199sm2873249pfs.124.2020.05.05.14.03.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2020 14:03:01 -0700 (PDT) From: Florian Fainelli To: netdev@vger.kernel.org Cc: olteanv@gmail.com, Florian Fainelli , Andrew Lunn , Vivien Didelot , "David S. Miller" , Jakub Kicinski , linux-kernel@vger.kernel.org (open list) Subject: [RFC net] net: dsa: Add missing reference counting Date: Tue, 5 May 2020 14:02:53 -0700 Message-Id: <20200505210253.20311-1-f.fainelli@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If we are probed through platform_data we would be intentionally dropping the reference count on master after dev_to_net_device() incremented it. If we are probed through Device Tree, of_find_net_device() does not do a dev_hold() at all. Ensure that the DSA master device is properly reference counted by holding it as soon as the CPU port is successfully initialized and later released during dsa_switch_release_ports(). dsa_get_tag_protocol() does a short de-reference, so we hold and release the master at that time, too. Fixes: 83c0afaec7b7 ("net: dsa: Add new binding implementation") Signed-off-by: Florian Fainelli --- net/dsa/dsa2.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c index d90665b465b8..875231252ada 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c @@ -626,6 +626,7 @@ static enum dsa_tag_protocol dsa_get_tag_protocol(struct dsa_port *dp, * happens the switch driver may want to know if its tagging protocol * is going to work in such a configuration. */ + dev_hold(master); if (dsa_slave_dev_check(master)) { mdp = dsa_slave_to_port(master); mds = mdp->ds; @@ -633,6 +634,7 @@ static enum dsa_tag_protocol dsa_get_tag_protocol(struct dsa_port *dp, tag_protocol = mds->ops->get_tag_protocol(mds, mdp_upstream, DSA_TAG_PROTO_NONE); } + dev_put(master); /* If the master device is not itself a DSA slave in a disjoint DSA * tree, then return immediately. @@ -657,6 +659,7 @@ static int dsa_port_parse_cpu(struct dsa_port *dp, struct net_device *master) return PTR_ERR(tag_ops); } + dev_hold(master); dp->master = master; dp->type = DSA_PORT_TYPE_CPU; dp->filter = tag_ops->filter; @@ -858,6 +861,8 @@ static void dsa_switch_release_ports(struct dsa_switch *ds) if (dp->ds != ds) continue; list_del(&dp->list); + if (dsa_port_is_cpu(dp)) + dev_put(dp->master); kfree(dp); } } -- 2.20.1