yshigeru / linux-devel

Linux kernel source tree
Other
0 stars 0 forks source link

tipc: Return -EINVAL on error from addr2str() methods #43

Open yshigeru opened 1 month ago

yshigeru commented 1 month ago

addr2str() method returns 1 on error, but it's not descriptive:

/* tipc_udp_addr2str - convert ip/udp address to string */
static int tipc_udp_addr2str(struct tipc_media_addr *a, char *buf, int size)
{
    struct udp_media_addr *ua = (struct udp_media_addr *)&a->value;

    if (ntohs(ua->proto) == ETH_P_IP)
        snprintf(buf, size, "%pI4:%u", &ua->ipv4, ntohs(ua->port));
    else if (ntohs(ua->proto) == ETH_P_IPV6)
        snprintf(buf, size, "%pI6:%u", &ua->ipv6, ntohs(ua->port));
    else {
        pr_err("Invalid UDP media address\n");
        return 1;
    }

    return 0;
}
yshigeru commented 1 month ago

Sent v1 patch: https://lore.kernel.org/all/20241008142442.652219-1-syoshida@redhat.com/