From patchwork Mon Jun 20 16:03:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vivien Didelot X-Patchwork-Id: 638108 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3rYGCf5VYyz9rvt for ; Tue, 21 Jun 2016 02:14:54 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755000AbcFTQOw (ORCPT ); Mon, 20 Jun 2016 12:14:52 -0400 Received: from mail.savoirfairelinux.com ([208.88.110.44]:46002 "EHLO mail.savoirfairelinux.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752888AbcFTQOt (ORCPT ); Mon, 20 Jun 2016 12:14:49 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id AD6CE620EF6; Mon, 20 Jun 2016 12:03:46 -0400 (EDT) Received: from mail.savoirfairelinux.com ([127.0.0.1]) by localhost (mail.savoirfairelinux.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id n3mYUqw-YEV9; Mon, 20 Jun 2016 12:03:45 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id 5D2CE620EF1; Mon, 20 Jun 2016 12:03:44 -0400 (EDT) X-Virus-Scanned: amavisd-new at mail.savoirfairelinux.com Received: from mail.savoirfairelinux.com ([127.0.0.1]) by localhost (mail.savoirfairelinux.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id B7rJpYq-az6e; Mon, 20 Jun 2016 12:03:44 -0400 (EDT) Received: from ketchup.mtl.sfl (unknown [192.168.48.170]) by mail.savoirfairelinux.com (Postfix) with ESMTPSA id 03C97620EEE; Mon, 20 Jun 2016 12:03:44 -0400 (EDT) From: Vivien Didelot To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel@savoirfairelinux.com, "David S. Miller" , Andrew Lunn , Florian Fainelli , Ben Dooks , Sergei Shtylyov , Vivien Didelot Subject: [PATCH v4 net-next v4 05/14] net: dsa: mv88e6xxx: add switch register helpers Date: Mon, 20 Jun 2016 12:03:28 -0400 Message-Id: <20160620160337.2934-6-vivien.didelot@savoirfairelinux.com> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160620160337.2934-1-vivien.didelot@savoirfairelinux.com> References: <20160620160337.2934-1-vivien.didelot@savoirfairelinux.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The mixed assignments, allocations and registrations in the probe code make it hard to follow the logic and figure out what is DSA or chip specific. Extract the struct dsa_switch related code in a simple mv88e6xxx_register_switch helper function. For symmetry in the code, add a mv88e6xxx_unregister_switch function. Signed-off-by: Vivien Didelot Reviewed-by: Andrew Lunn --- drivers/net/dsa/mv88e6xxx.c | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/drivers/net/dsa/mv88e6xxx.c b/drivers/net/dsa/mv88e6xxx.c index 4b4bffc..ad7735d 100644 --- a/drivers/net/dsa/mv88e6xxx.c +++ b/drivers/net/dsa/mv88e6xxx.c @@ -3690,30 +3690,48 @@ static struct dsa_switch_driver mv88e6xxx_switch_driver = { .port_fdb_dump = mv88e6xxx_port_fdb_dump, }; +static int mv88e6xxx_register_switch(struct mv88e6xxx_priv_state *ps, + struct device_node *np) +{ + struct device *dev = ps->dev; + struct dsa_switch *ds; + + ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL); + if (!ds) + return -ENOMEM; + + ds->dev = dev; + ds->priv = ps; + ds->drv = &mv88e6xxx_switch_driver; + + dev_set_drvdata(dev, ds); + + return dsa_register_switch(ds, np); +} + +static void mv88e6xxx_unregister_switch(struct mv88e6xxx_priv_state *ps) +{ + dsa_unregister_switch(ps->ds); +} + static int mv88e6xxx_probe(struct mdio_device *mdiodev) { struct device *dev = &mdiodev->dev; struct device_node *np = dev->of_node; struct mv88e6xxx_priv_state *ps; int id, prod_num, rev; - struct dsa_switch *ds; u32 eeprom_len; int err; - ds = devm_kzalloc(dev, sizeof(*ds) + sizeof(*ps), GFP_KERNEL); - if (!ds) + ps = devm_kzalloc(dev, sizeof(*ps), GFP_KERNEL); + if (!ps) return -ENOMEM; - ps = (struct mv88e6xxx_priv_state *)(ds + 1); - ds->priv = ps; - ds->dev = dev; ps->dev = dev; ps->bus = mdiodev->bus; ps->sw_addr = mdiodev->addr; mutex_init(&ps->smi_mutex); - ds->drv = &mv88e6xxx_switch_driver; - id = mv88e6xxx_reg_read(ps, REG_PORT(0), PORT_SWITCH_ID); if (id < 0) return id; @@ -3745,9 +3763,7 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev) if (err) return err; - dev_set_drvdata(dev, ds); - - err = dsa_register_switch(ds, np); + err = mv88e6xxx_register_switch(ps, np); if (err) { mv88e6xxx_mdio_unregister(ps); return err; @@ -3764,8 +3780,7 @@ static void mv88e6xxx_remove(struct mdio_device *mdiodev) struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev); struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); - dsa_unregister_switch(ds); - + mv88e6xxx_unregister_switch(ps); mv88e6xxx_mdio_unregister(ps); }