The ffs()/fls() guard in ethnl_set_tsconfig() was meant to enforce that the user selects exactly one tx_type (and one rx_filter) at a time (off / none are explicit types with non-zero values). However, both ffs(0) and fls(0) return 0, so the guard passes a zero-valued bitset through. The subsequent ffs(req_tx_type) - 1 would produce -1, if user selected no bit. net_hwtstamp_validate() catches the invalid -1 downstream, but returns a generic error (-ERANGE) without telling the user what went wrong. Return -EINVAL + extack instead. Replace the ffs()/fls() comparison with a hweight32() == 1 check.
Unified · Split
| @@ -359,8 +359,10 @@ static int ethnl_set_tsconfig(struct ethnl_req_info *req_base, · 358 unmodified lines | ||
| 359 | 359 | if (ret < 0) |
| 360 | 360 | goto err_free_hwprov; |
| 361 | 361 | |
| 362 | − /* Select only one tx type at a time */ | |
| 363 | − if (ffs(req_tx_type) != fls(req_tx_type)) { | |
| 362 | + /* Select exactly one tx type at a time */ | |
| 363 | + if (hweight32(req_tx_type) != 1) { | |
| 364 | + NL_SET_BAD_ATTR(info->extack, | |
| 365 | + tb[ETHTOOL_A_TSCONFIG_TX_TYPES]); | |
| 364 | 366 | ret = -EINVAL; |
| 365 | 367 | goto err_free_hwprov; |
| 366 | 368 | } |
| @@ -380,8 +382,10 @@ static int ethnl_set_tsconfig(struct ethnl_req_info *req_base, · 13 unmodified lines | ||
| 380 | 382 | if (ret < 0) |
| 381 | 383 | goto err_free_hwprov; |
| 382 | 384 | |
| 383 | − /* Select only one rx filter at a time */ | |
| 384 | − if (ffs(req_rx_filter) != fls(req_rx_filter)) { | |
| 385 | + /* Select exactly one rx filter at a time */ | |
| 386 | + if (hweight32(req_rx_filter) != 1) { | |
| 387 | + NL_SET_BAD_ATTR(info->extack, | |
| 388 | + tb[ETHTOOL_A_TSCONFIG_RX_FILTERS]); | |
| 385 | 389 | ret = -EINVAL; |
| 386 | 390 | goto err_free_hwprov; |
| 387 | 391 | } |