Re: [PATCH net-next v2] net: dsa: mv88e6xxx: control mdio bus-id truncation for long paths

From: Josua Mayer
Date: Mon Apr 15 2024 - 04:01:39 EST


Am 04.04.24 um 16:29 schrieb Andrew Lunn:
>> + } else if (err >= MII_BUS_ID_SIZE) {
>> + /* If generated bus id is truncated, names in sysfs
>> + * may collide. Insert a special numeric suffix to mark
>> + * truncation and avoid name collisions.
>> + */
>> + err = snprintf(NULL, 0, "...!-%d", trunc);
>> + if (err < 0)
>> + return err;
> It took me a while to figure out what this was doing. Rather than err,
> maybe add a new variable postfix_len, to give a clue that this is used
> to determine how long the post fix is, and so how much needs to be
> truncated from the end of the string to make room for it.
I considered adding a new variable (e.g. busid_len) to capture all results
from snprintf calls. But it is confusing because in some calls it is
length of parts of bus-id only.

Maybe just using a new variable "len" for all snprintf can be readable?