From: Andrey Volkov <andrey.volkov@nexvision.fr>
To: Florian Fainelli <f.fainelli@gmail.com>, netdev@vger.kernel.org
Subject: [PATCH v2 1/1] net: dsa: replacing the hard-coded sized array "dsa_switch" by dynamic one
Date: Thu, 04 Dec 2014 16:54:32 +0100 [thread overview]
Message-ID: <548083B8.5090900@nexvision.fr> (raw)
In-Reply-To: <547E23C1.2040007@gmail.com>
Replacing the hard-coded sized array "dsa_switch" by dynamic one
and remove useless DSA_MAX_SWITCHES define.
This patch also make dsa_switch_tree scalable from the "usual"
1-2 up to 10th switches configuration.
Signed-off-by: Andrey Volkov <andrey.volkov@nexvision.fr>
---
include/net/dsa.h | 3 +--
net/dsa/dsa.c | 7 +++----
2 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/include/net/dsa.h b/include/net/dsa.h
index ed3c34b..733db2e 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -28,7 +28,6 @@ enum dsa_tag_protocol {
DSA_TAG_PROTO_BRCM,
};
-#define DSA_MAX_SWITCHES 4
#define DSA_MAX_PORTS 12
struct dsa_chip_data {
@@ -117,7 +116,7 @@ struct dsa_switch_tree {
/*
* Data for the individual switch chips.
*/
- struct dsa_switch *ds[DSA_MAX_SWITCHES];
+ struct dsa_switch *ds[];
};
struct dsa_switch {
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index 322c778..c081a19 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -604,8 +604,6 @@ static int dsa_of_probe(struct platform_device *pdev)
pdev->dev.platform_data = pd;
pd->netdev = ðernet_dev->dev;
pd->nr_chips = of_get_child_count(np);
- if (pd->nr_chips > DSA_MAX_SWITCHES)
- pd->nr_chips = DSA_MAX_SWITCHES;
pd->chip = kcalloc(pd->nr_chips, sizeof(struct dsa_chip_data),
GFP_KERNEL);
@@ -717,7 +715,7 @@ static int dsa_probe(struct platform_device *pdev)
pd = pdev->dev.platform_data;
}
- if (pd == NULL || pd->netdev == NULL)
+ if (pd == NULL || pd->netdev == NULL || pd->nr_chips == 0)
return -EINVAL;
dev = dev_to_net_device(pd->netdev);
@@ -732,7 +730,8 @@ static int dsa_probe(struct platform_device *pdev)
goto out;
}
- dst = kzalloc(sizeof(*dst), GFP_KERNEL);
+ dst = kzalloc(sizeof(*dst) +
+ sizeof(struct dsa_switch *) * pd->nr_chips, GFP_KERNEL);
if (dst == NULL) {
dev_put(dev);
ret = -ENOMEM;
next prev parent reply other threads:[~2014-12-04 17:10 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-02 14:50 [PATCH 1/1] net: dsa: replacing the hard-coded sized array "dsa_switch" by dynamic one Andrey Volkov
2014-12-02 20:40 ` Florian Fainelli
2014-12-04 15:54 ` Andrey Volkov [this message]
2014-12-09 19:45 ` [PATCH v2 " David Miller
2014-12-04 17:29 ` [PATCH " Andrey Volkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=548083B8.5090900@nexvision.fr \
--to=andrey.volkov@nexvision.fr \
--cc=f.fainelli@gmail.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.