From 68376f82e8a0b01476498849748a27ea18252298 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Tue, 20 May 2014 09:33:04 +0200 Subject: [PATCH 1/3] mii-tool: Fix string length media_list writes into a static string. Worst case length of this string is 125 bytes, but the function only allocates 100 bytes. Use 256 bytes which is long enough for some extensions. Signed-off-by: Sascha Hauer --- commands/miitool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/miitool.c b/commands/miitool.c index 5a5278d34..48c3c4b8c 100644 --- a/commands/miitool.c +++ b/commands/miitool.c @@ -61,7 +61,7 @@ const struct { static const char *media_list(unsigned mask, unsigned mask2, int best) { - static char buf[100]; + static char buf[256]; int i; *buf = '\0'; From e5a0223b9e6a2661f6ffdb20781aa04f8754984b Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Tue, 20 May 2014 10:13:51 +0200 Subject: [PATCH 2/3] mii-tool: Fix gigabit link test media_list tests for gigabit phys like this: if (mask & BMCR_SPEED1000) mask does not contain the value of the BMCR register though, so the test is completely bogus. Test for mask2 instead which is only nonzero when the phy has gigabit capabilities. Signed-off-by: Sascha Hauer --- commands/miitool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/miitool.c b/commands/miitool.c index 48c3c4b8c..319ae34cc 100644 --- a/commands/miitool.c +++ b/commands/miitool.c @@ -66,7 +66,7 @@ static const char *media_list(unsigned mask, unsigned mask2, int best) *buf = '\0'; - if (mask & BMCR_SPEED1000) { + if (mask2) { if (mask2 & ADVERTISE_1000FULL) { strcat(buf, " "); strcat(buf, "1000baseT-FD"); From 7eb8f2a59cb98e747f621913596364e2db808e27 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Tue, 20 May 2014 11:24:32 +0200 Subject: [PATCH 3/3] mii-tool: Fix gigabit advertise / link partner ability mixup bmcr2 contains the gigabit advertise bits and lpa2 contains the gigabit link partner ability bits, not the other way round. Signed-off-by: Sascha Hauer --- commands/miitool.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commands/miitool.c b/commands/miitool.c index 319ae34cc..b08be9c68 100644 --- a/commands/miitool.c +++ b/commands/miitool.c @@ -209,7 +209,7 @@ static int show_basic_mii(struct mii_bus *mii, struct phy_device *phydev, printf("remote fault, "); printf((bmsr & BMSR_LSTATUS) ? "link ok" : "no link"); printf("\n capabilities:%s", media_list(bmsr >> 6, bmcr2, 0)); - printf("\n advertising: %s", media_list(advert, lpa2 >> 2, 0)); + printf("\n advertising: %s", media_list(advert, bmcr2, 0)); #define LPA_ABILITY_MASK (LPA_10HALF | LPA_10FULL \ | LPA_100HALF | LPA_100FULL \ @@ -217,7 +217,7 @@ static int show_basic_mii(struct mii_bus *mii, struct phy_device *phydev, if (lkpar & LPA_ABILITY_MASK) printf("\n link partner:%s", - media_list(lkpar, bmcr2, 0)); + media_list(lkpar, lpa2 >> 2, 0)); printf("\n"); }