diff mbox series

RDMA/rxe: fix the parent sysfs read when the interface has 15 chars

Message ID 20200820041336.24761-1-yi.zhang@redhat.com (mailing list archive)
State Superseded
Delegated to: Jason Gunthorpe
Headers show
Series RDMA/rxe: fix the parent sysfs read when the interface has 15 chars | expand

Commit Message

Yi Zhang Aug. 20, 2020, 4:13 a.m. UTC
parent sysfs reads will yield '\0' bytes when the interface name
has 15 chars, and there will no "\n" output.

reproducer:
Create one interface with 15 chars
[root@test ~]# ip a s enp0s29u1u7u3c2
2: enp0s29u1u7u3c2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
    link/ether 02:21:28:57:47:17 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::ac41:338f:5bcd:c222/64 scope link noprefixroute
       valid_lft forever preferred_lft forever
[root@test ~]# modprobe rdma_rxe
[root@test ~]# echo enp0s29u1u7u3c2 > /sys/module/rdma_rxe/parameters/add
[root@test ~]# cat /sys/class/infiniband/rxe0/parent
enp0s29u1u7u3c2[root@test ~]#
[root@test ~]# f="/sys/class/infiniband/rxe0/parent"
[root@test ~]# echo "$(<"$f")"
-bash: warning: command substitution: ignored null byte in input
enp0s29u1u7u3c2

Signed-off-by: Yi Zhang <yi.zhang@redhat.com>
---
 drivers/infiniband/sw/rxe/rxe_verbs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jason Gunthorpe Aug. 20, 2020, 11:46 a.m. UTC | #1
On Thu, Aug 20, 2020 at 12:13:36PM +0800, Yi Zhang wrote:
> parent sysfs reads will yield '\0' bytes when the interface name
> has 15 chars, and there will no "\n" output.
> 
> reproducer:
> Create one interface with 15 chars
> [root@test ~]# ip a s enp0s29u1u7u3c2
> 2: enp0s29u1u7u3c2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
>     link/ether 02:21:28:57:47:17 brd ff:ff:ff:ff:ff:ff
>     inet6 fe80::ac41:338f:5bcd:c222/64 scope link noprefixroute
>        valid_lft forever preferred_lft forever
> [root@test ~]# modprobe rdma_rxe
> [root@test ~]# echo enp0s29u1u7u3c2 > /sys/module/rdma_rxe/parameters/add
> [root@test ~]# cat /sys/class/infiniband/rxe0/parent
> enp0s29u1u7u3c2[root@test ~]#
> [root@test ~]# f="/sys/class/infiniband/rxe0/parent"
> [root@test ~]# echo "$(<"$f")"
> -bash: warning: command substitution: ignored null byte in input
> enp0s29u1u7u3c2
> 
> Signed-off-by: Yi Zhang <yi.zhang@redhat.com>
>  drivers/infiniband/sw/rxe/rxe_verbs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.c b/drivers/infiniband/sw/rxe/rxe_verbs.c
> index bb61e534e468..91090cb1b08c 100644
> +++ b/drivers/infiniband/sw/rxe/rxe_verbs.c
> @@ -1056,7 +1056,7 @@ static ssize_t parent_show(struct device *device,
>  	struct rxe_dev *rxe =
>  		rdma_device_to_drv_device(device, struct rxe_dev, ib_dev);
>  
> -	return snprintf(buf, 16, "%s\n", rxe_parent_name(rxe, 1));
> +	return snprintf(buf, 17, "%s\n", rxe_parent_name(rxe, 1));
>  }

This should be written as 

  return scnprintf(buf, PAGE_SIZE, "%s\n", rxe_parent_name(rxe, 1));

All places in this file should be changed

Jason
Yi Zhang Aug. 20, 2020, 3:23 p.m. UTC | #2
On 8/20/20 7:46 PM, Jason Gunthorpe wrote:
> On Thu, Aug 20, 2020 at 12:13:36PM +0800, Yi Zhang wrote:
>> parent sysfs reads will yield '\0' bytes when the interface name
>> has 15 chars, and there will no "\n" output.
>>
>> reproducer:
>> Create one interface with 15 chars
>> [root@test ~]# ip a s enp0s29u1u7u3c2
>> 2: enp0s29u1u7u3c2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
>>      link/ether 02:21:28:57:47:17 brd ff:ff:ff:ff:ff:ff
>>      inet6 fe80::ac41:338f:5bcd:c222/64 scope link noprefixroute
>>         valid_lft forever preferred_lft forever
>> [root@test ~]# modprobe rdma_rxe
>> [root@test ~]# echo enp0s29u1u7u3c2 > /sys/module/rdma_rxe/parameters/add
>> [root@test ~]# cat /sys/class/infiniband/rxe0/parent
>> enp0s29u1u7u3c2[root@test ~]#
>> [root@test ~]# f="/sys/class/infiniband/rxe0/parent"
>> [root@test ~]# echo "$(<"$f")"
>> -bash: warning: command substitution: ignored null byte in input
>> enp0s29u1u7u3c2
>>
>> Signed-off-by: Yi Zhang <yi.zhang@redhat.com>
>>   drivers/infiniband/sw/rxe/rxe_verbs.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.c b/drivers/infiniband/sw/rxe/rxe_verbs.c
>> index bb61e534e468..91090cb1b08c 100644
>> +++ b/drivers/infiniband/sw/rxe/rxe_verbs.c
>> @@ -1056,7 +1056,7 @@ static ssize_t parent_show(struct device *device,
>>   	struct rxe_dev *rxe =
>>   		rdma_device_to_drv_device(device, struct rxe_dev, ib_dev);
>>   
>> -	return snprintf(buf, 16, "%s\n", rxe_parent_name(rxe, 1));
>> +	return snprintf(buf, 17, "%s\n", rxe_parent_name(rxe, 1));
>>   }
> This should be written as
>
>    return scnprintf(buf, PAGE_SIZE, "%s\n", rxe_parent_name(rxe, 1));
>
> All places in this file should be changed
Here is the only space use snprintf, will send v2 as you suggested, thanks.
> Jason
>
diff mbox series

Patch

diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.c b/drivers/infiniband/sw/rxe/rxe_verbs.c
index bb61e534e468..91090cb1b08c 100644
--- a/drivers/infiniband/sw/rxe/rxe_verbs.c
+++ b/drivers/infiniband/sw/rxe/rxe_verbs.c
@@ -1056,7 +1056,7 @@  static ssize_t parent_show(struct device *device,
 	struct rxe_dev *rxe =
 		rdma_device_to_drv_device(device, struct rxe_dev, ib_dev);
 
-	return snprintf(buf, 16, "%s\n", rxe_parent_name(rxe, 1));
+	return snprintf(buf, 17, "%s\n", rxe_parent_name(rxe, 1));
 }
 
 static DEVICE_ATTR_RO(parent);