From: Zhu Ling <redacted>
can_pwm_fill_info() emits the PWM capability limits whenever pwm_const is
present, regardless of whether TMS is enabled. In contrast,
can_pwm_get_size() currently returns 0 when TMS is disabled. It
therefore underestimates the required netlink message size by the nested
attribute header and 6 u32 attributes.
Always account for the PWM capability attributes when pwm_const is present,
and account for the 3 runtime PWM values only when TMS is enabled.
Fixes: 46552323fa67 ("can: netlink: add PWM netlink interface")
Cc: <redacted>
Signed-off-by: Zhu Ling <redacted>
Link: https://patch.msgid.link/tencent_9A525E0656A4F7D4CA9CFA1AB1A4BFC6D706@qq.com (local)
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/bug/linux-3924d490-baed-49dc-880a-6fd1163cf08d
Reviewed-by: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/dev/netlink.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/drivers/net/can/dev/netlink.c b/drivers/net/can/dev/netlink.c
index 10e7ccaf40fb..7f597c975c6f 100644
--- a/drivers/net/can/dev/netlink.c
+++ b/drivers/net/can/dev/netlink.c
@@ -791,7 +791,7 @@ static size_t can_pwm_get_size(const struct can_pwm_const *pwm_const,
{
size_t size;
- if (!pwm_const || !pwm_on)
+ if (!pwm_const)
return 0;
size = nla_total_size(0); /* nest IFLA_CAN_PWM */@@ -803,9 +803,11 @@ static size_t can_pwm_get_size(const struct can_pwm_const *pwm_const,
size += nla_total_size(sizeof(u32)); /* IFLA_CAN_PWM_PWMO_MIN */
size += nla_total_size(sizeof(u32)); /* IFLA_CAN_PWM_PWMO_MAX */
- size += nla_total_size(sizeof(u32)); /* IFLA_CAN_PWM_PWMS */
- size += nla_total_size(sizeof(u32)); /* IFLA_CAN_PWM_PWML */
- size += nla_total_size(sizeof(u32)); /* IFLA_CAN_PWM_PWMO */
+ if (pwm_on) {
+ size += nla_total_size(sizeof(u32)); /* IFLA_CAN_PWM_PWMS */
+ size += nla_total_size(sizeof(u32)); /* IFLA_CAN_PWM_PWML */
+ size += nla_total_size(sizeof(u32)); /* IFLA_CAN_PWM_PWMO */
+ }
return size;
}--
2.53.0