lib: packing: demote truncation error in pack() to a warning in __pack()
authorVladimir Oltean <vladimir.oltean@nxp.com>
Tue, 10 Dec 2024 20:27:11 +0000 (12:27 -0800)
committerJakub Kicinski <kuba@kernel.org>
Thu, 12 Dec 2024 04:12:59 +0000 (20:12 -0800)
commit48c2752785ad1730e08a64507f05d0e5d5bc79b8
tree7f5a9a2dd41464dd700f3e1b64ee1ff06c675b22
parentc4117091d029087abde76e6947d43dca8f1db20b
lib: packing: demote truncation error in pack() to a warning in __pack()

Most of the sanity checks in pack() and unpack() can be covered at
compile time. There is only one exception, and that is truncation of the
uval during a pack() operation.

We'd like the error-less __pack() to catch that condition as well. But
at the same time, it is currently the responsibility of consumer drivers
(currently just sja1105) to print anything at all when this error
occurs, and then discard the return code.

We can just print a loud warning in the library code and continue with
the truncated __pack() operation. In practice, having the warning is
very important, see commit 24deec6b9e4a ("net: dsa: sja1105: disallow
C45 transactions on the BASE-TX MDIO bus") where the bug was caught
exactly by noticing this print.

Add the first print to the packing library, and at the same time remove
the print for the same condition from the sja1105 driver, to avoid
double printing.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Link: https://patch.msgid.link/20241210-packing-pack-fields-and-ice-implementation-v10-2-ee56a47479ac@intel.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/dsa/sja1105/sja1105_static_config.c
lib/packing.c