From: Martino Dell'Ambrogio <tillo@tillo.ch>
To: netdev@vger.kernel.org
Cc: Russell King <linux@armlinux.org.uk>,
Andrew Lunn <andrew@lunn.ch>,
Heiner Kallweit <hkallweit1@gmail.com>,
"David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
linux-kernel@vger.kernel.org,
Martino Dell'Ambrogio <tillo@tillo.ch>
Subject: [PATCH net-next 1/2] net: sfp: allow prefix matching in quirk lookup
Date: Sun, 5 Jul 2026 20:54:38 +0200 [thread overview]
Message-ID: <20260705185440.136496-2-tillo@tillo.ch> (raw)
In-Reply-To: <20260705185440.136496-1-tillo@tillo.ch>
Some clone SFP modules (notably XGS-PON ONT sticks) ship malformed
EEPROMs where the vendor PN field is filled with non-printable garbage
past the trailing legitimate characters instead of SFF-8472 mandated
space padding. The current sfp_match() requires an exact full-field
length match: sfp_strlen() returns 16 (no trailing spaces or NULs to
strip), but strlen() of the quirk string is shorter, so the length
comparison rejects the entry before strncmp() is even called and the
quirk silently never applies. The kernel then honors the module's
spurious TX_FAULT signal and the SFP state machine eventually disables
the module.
Add a prefix_match flag to struct sfp_quirk and a SFP_QUIRK_F_PREFIX
macro. When set, sfp_match() compares only strlen() leading bytes of
the quirk string, ignoring trailing field bytes. Existing exact-match
quirks are unaffected (prefix_match defaults to false via zero-init in
the existing SFP_QUIRK macros).
Signed-off-by: Martino Dell'Ambrogio <tillo@tillo.ch>
---
drivers/net/phy/sfp.c | 22 +++++++++++++++++-----
drivers/net/phy/sfp.h | 1 +
2 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c
index f520206..e7ba642 100644
--- a/drivers/net/phy/sfp.c
+++ b/drivers/net/phy/sfp.c
@@ -516,6 +516,13 @@ static void sfp_quirk_ubnt_uf_instant(const struct sfp_eeprom_id *id,
{ .vendor = _v, .part = _p, .support = _s, .fixup = _f, }
#define SFP_QUIRK_S(_v, _p, _s) SFP_QUIRK(_v, _p, _s, NULL)
#define SFP_QUIRK_F(_v, _p, _f) SFP_QUIRK(_v, _p, NULL, _f)
+/* Like SFP_QUIRK_F, but matches as a prefix. Use for clone modules
+ * that fill EEPROM trailing bytes with garbage instead of the
+ * SFF-8472-mandated space padding, so sfp_strlen can't trim the
+ * field down to the legitimate length.
+ */
+#define SFP_QUIRK_F_PREFIX(_v, _p, _f) \
+ { .vendor = _v, .part = _p, .support = NULL, .fixup = _f, .prefix_match = true }
static const struct sfp_quirk sfp_quirks[] = {
// Alcatel Lucent G-010S-P can operate at 2500base-X, but incorrectly
@@ -626,13 +633,16 @@ static size_t sfp_strlen(const char *str, size_t maxlen)
return size;
}
-static bool sfp_match(const char *qs, const char *str, size_t len)
+static bool sfp_match(const char *qs, const char *str, size_t len, bool prefix)
{
+ size_t qs_len;
+
if (!qs)
return true;
- if (strlen(qs) != len)
+ qs_len = strlen(qs);
+ if (prefix ? qs_len > len : qs_len != len)
return false;
- return !strncmp(qs, str, len);
+ return !strncmp(qs, str, qs_len);
}
static const struct sfp_quirk *sfp_lookup_quirk(const struct sfp_eeprom_id *id)
@@ -645,8 +655,10 @@ static const struct sfp_quirk *sfp_lookup_quirk(const struct sfp_eeprom_id *id)
ps = sfp_strlen(id->base.vendor_pn, ARRAY_SIZE(id->base.vendor_pn));
for (i = 0, q = sfp_quirks; i < ARRAY_SIZE(sfp_quirks); i++, q++)
- if (sfp_match(q->vendor, id->base.vendor_name, vs) &&
- sfp_match(q->part, id->base.vendor_pn, ps))
+ if (sfp_match(q->vendor, id->base.vendor_name, vs,
+ q->prefix_match) &&
+ sfp_match(q->part, id->base.vendor_pn, ps,
+ q->prefix_match))
return q;
return NULL;
diff --git a/drivers/net/phy/sfp.h b/drivers/net/phy/sfp.h
index 879dff7..867e45e 100644
--- a/drivers/net/phy/sfp.h
+++ b/drivers/net/phy/sfp.h
@@ -12,6 +12,7 @@ struct sfp_quirk {
void (*support)(const struct sfp_eeprom_id *id,
struct sfp_module_caps *caps);
void (*fixup)(struct sfp *sfp);
+ bool prefix_match;
};
struct sfp_socket_ops {
--
2.47.3
next prev parent reply other threads:[~2026-07-05 19:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-05 18:54 [PATCH net-next 0/2] net: sfp: quirk support for XGS-PON ONT sticks with unclean EEPROMs Martino Dell'Ambrogio
2026-07-05 18:54 ` Martino Dell'Ambrogio [this message]
2026-07-06 7:28 ` [PATCH net-next 1/2] net: sfp: allow prefix matching in quirk lookup Maxime Chevallier
2026-07-05 18:54 ` [PATCH net-next 2/2] net: sfp: add quirks for OEM XGSPONST2001 and FS XGS-SFP-ONT-MACI Martino Dell'Ambrogio
2026-07-06 7:29 ` Maxime Chevallier
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=20260705185440.136496-2-tillo@tillo.ch \
--to=tillo@tillo.ch \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hkallweit1@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox