When a pin callback fails in the frequency, embedded sync, reference sync or phase adjust set path, the DPLL core sets its own generic message: "unable to get ..." after the get callback and e.g. "frequency set failed for dpll_id:N" after the set callback. Both NL_SET_ERR_MSG() and NL_SET_ERR_MSG_FMT() replace any message set by the driver, so userspace never sees why the driver rejected the request, e.g. the zl3073x reasons for an invalid output frequency or reference sync pair, the ice admin queue status or "PF reset in progress" from the ice get callbacks. Add NL_SET_ERR_MSG_FMT_WEAK(), a formatted variant of NL_SET_ERR_MSG_WEAK() that sets the message only if none is set yet, and use the weak variants for these generic messages. The other set callbacks already return the driver error without a message of their own, and no driver sets a message in the get callbacks of the device set paths. Discovered by an AI code review agent (Sashiko) and confirmed by code inspection. Tested on a GNR-D system with a ZL80132B DPLL by setting the P-pin of an N-div output to 1 Hz, which leaves no valid frequency for its N-pin: the reply carried "frequency set failed for dpll_id:12" before the fix and "OUT8N freq must be at most half of OUT8P freq" with it. The get paths were not triggered on hardware, ice sets its message there only during a PF reset. The new macro was also checked in a userspace test built from the netlink.h macros: a message set before is kept, otherwise the generic one is set. Fixes: d7fbc0b7e846 ("dpll: netlink/core: add support for pin-dpll signal phase offset/adjust") Fixes: 20f6677234d8 ("dpll: netlink/core: change pin frequency set behavior") Fixes: cda1fba15cb2 ("dpll: add Embedded SYNC feature for a pin") Fixes: 58256a26bfb3 ("dpll: add reference sync get/set") Reported-by: Sashiko Closes: https://sashiko.dev/#/bug/linux-06bba4c1-85c2-43b9-9d63-a2d615540f64 Reviewed-by: Vadim Fedorenko Signed-off-by: Ivan Vecera --- Changes in v2: - keep the driver message also when the get callback fails in the four pin set paths, ice sets one during a PF reset (Sashiko) v1: https://lore.kernel.org/r/20261204155246.425636-1-ivecera@redhat.com --- drivers/dpll/dpll_netlink.c | 36 ++++++++++++++++++++---------------- include/linux/netlink.h | 7 +++++++ 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/drivers/dpll/dpll_netlink.c b/drivers/dpll/dpll_netlink.c index e5380d95f238b3..ae8d6b2262e9fb 100644 --- a/drivers/dpll/dpll_netlink.c +++ b/drivers/dpll/dpll_netlink.c @@ -1123,7 +1123,8 @@ dpll_pin_freq_set(struct dpll_pin *pin, struct nlattr *a, ret = ops->frequency_get(pin, dpll_pin_on_dpll_priv(dpll, pin), dpll, dpll_priv(dpll), &old_freq, extack); if (ret) { - NL_SET_ERR_MSG(extack, "unable to get old frequency value"); + NL_SET_ERR_MSG_WEAK(extack, + "unable to get old frequency value"); return ret; } if (freq == old_freq) @@ -1132,9 +1133,9 @@ dpll_pin_freq_set(struct dpll_pin *pin, struct nlattr *a, ret = ops->frequency_set(pin, dpll_pin_on_dpll_priv(dpll, pin), dpll, dpll_priv(dpll), freq, extack); if (ret) { - NL_SET_ERR_MSG_FMT(extack, - "frequency set failed for dpll_id:%u", - dpll->id); + NL_SET_ERR_MSG_FMT_WEAK(extack, + "frequency set failed for dpll_id:%u", + dpll->id); return ret; } __dpll_pin_change_ntf(pin); @@ -1169,7 +1170,8 @@ dpll_pin_esync_set(struct dpll_pin *pin, struct nlattr *a, ret = ops->esync_get(pin, dpll_pin_on_dpll_priv(dpll, pin), dpll, dpll_priv(dpll), &esync, extack); if (ret) { - NL_SET_ERR_MSG(extack, "unable to get current embedded sync frequency value"); + NL_SET_ERR_MSG_WEAK(extack, + "unable to get current embedded sync frequency value"); return ret; } if (freq == esync.freq) @@ -1186,9 +1188,9 @@ dpll_pin_esync_set(struct dpll_pin *pin, struct nlattr *a, ret = ops->esync_set(pin, dpll_pin_on_dpll_priv(dpll, pin), dpll, dpll_priv(dpll), freq, extack); if (ret) { - NL_SET_ERR_MSG_FMT(extack, - "embedded sync frequency set failed for dpll_id: %u", - dpll->id); + NL_SET_ERR_MSG_FMT_WEAK(extack, + "embedded sync frequency set failed for dpll_id: %u", + dpll->id); return ret; } __dpll_pin_change_ntf(pin); @@ -1241,7 +1243,8 @@ dpll_pin_ref_sync_state_set(struct dpll_pin *pin, ret = ops->ref_sync_get(pin, pin_priv, ref_sync_pin, ref_sync_pin_priv, &old_state, extack); if (ret) { - NL_SET_ERR_MSG(extack, "unable to get old reference sync state"); + NL_SET_ERR_MSG_WEAK(extack, + "unable to get old reference sync state"); return ret; } if (state == old_state) @@ -1250,9 +1253,9 @@ dpll_pin_ref_sync_state_set(struct dpll_pin *pin, ret = ops->ref_sync_set(pin, pin_priv, ref_sync_pin, ref_sync_pin_priv, state, extack); if (ret) { - NL_SET_ERR_MSG_FMT(extack, - "reference sync set failed for dpll_id:%u", - dpll->id); + NL_SET_ERR_MSG_FMT_WEAK(extack, + "reference sync set failed for dpll_id:%u", + dpll->id); return ret; } __dpll_pin_change_ntf(pin); @@ -1453,7 +1456,8 @@ dpll_pin_phase_adj_set(struct dpll_pin *pin, struct nlattr *phase_adj_attr, dpll, dpll_priv(dpll), &old_phase_adj, extack); if (ret) { - NL_SET_ERR_MSG(extack, "unable to get old phase adjust value"); + NL_SET_ERR_MSG_WEAK(extack, + "unable to get old phase adjust value"); return ret; } if (phase_adj == old_phase_adj) @@ -1462,9 +1466,9 @@ dpll_pin_phase_adj_set(struct dpll_pin *pin, struct nlattr *phase_adj_attr, ret = ops->phase_adjust_set(pin, dpll_pin_on_dpll_priv(dpll, pin), dpll, dpll_priv(dpll), phase_adj, extack); if (ret) { - NL_SET_ERR_MSG_FMT(extack, - "phase adjust set failed for dpll_id:%u", - dpll->id); + NL_SET_ERR_MSG_FMT_WEAK(extack, + "phase adjust set failed for dpll_id:%u", + dpll->id); return ret; } __dpll_pin_change_ntf(pin); diff --git a/include/linux/netlink.h b/include/linux/netlink.h index b4eb873850e752..18e05f81e33e0b 100644 --- a/include/linux/netlink.h +++ b/include/linux/netlink.h @@ -143,6 +143,13 @@ struct netlink_ext_ack { NL_SET_ERR_MSG_MOD((extack), msg); \ } while (0) +#define NL_SET_ERR_MSG_FMT_WEAK(extack, fmt, args...) do { \ + struct netlink_ext_ack *__extack_weak = (extack); \ + \ + if (__extack_weak && !__extack_weak->_msg) \ + NL_SET_ERR_MSG_FMT(__extack_weak, fmt, ##args); \ +} while (0) + #define NL_SET_BAD_ATTR_POLICY(extack, attr, pol) do { \ if ((extack)) { \ (extack)->bad_attr = (attr); \ base-commit: 6902a2bb708c4075d3de6ec18ab6a5864c4c1aa2 -- 2.56.1