* [PATCH -next] hinic: Use ARRAY_SIZE for nic_vf_cmd_msg_handler
@ 2020-04-29 3:15 Zou Wei
2020-04-29 3:23 ` Joe Perches
0 siblings, 1 reply; 3+ messages in thread
From: Zou Wei @ 2020-04-29 3:15 UTC (permalink / raw)
To: aviad.krawczyk, davem; +Cc: netdev, linux-kernel, Zou Wei
fix coccinelle warning, use ARRAY_SIZE
drivers/net/ethernet/huawei/hinic/hinic_sriov.c:713:43-44: WARNING: Use ARRAY_SIZE
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Zou Wei <zou_wei@huawei.com>
---
drivers/net/ethernet/huawei/hinic/hinic_sriov.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/huawei/hinic/hinic_sriov.c b/drivers/net/ethernet/huawei/hinic/hinic_sriov.c
index b24788e..ac12725 100644
--- a/drivers/net/ethernet/huawei/hinic/hinic_sriov.c
+++ b/drivers/net/ethernet/huawei/hinic/hinic_sriov.c
@@ -710,8 +710,7 @@ int nic_pf_mbox_handler(void *hwdev, u16 vf_id, u8 cmd, void *buf_in,
if (!hwdev)
return -EFAULT;
- cmd_number = sizeof(nic_vf_cmd_msg_handler) /
- sizeof(struct vf_cmd_msg_handle);
+ cmd_number = ARRAY_SIZE(nic_vf_cmd_msg_handler);
pfhwdev = container_of(dev, struct hinic_pfhwdev, hwdev);
nic_io = &dev->func_to_io;
for (i = 0; i < cmd_number; i++) {
--
2.6.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH -next] hinic: Use ARRAY_SIZE for nic_vf_cmd_msg_handler
2020-04-29 3:15 [PATCH -next] hinic: Use ARRAY_SIZE for nic_vf_cmd_msg_handler Zou Wei
@ 2020-04-29 3:23 ` Joe Perches
2020-04-29 3:50 ` Samuel Zou
0 siblings, 1 reply; 3+ messages in thread
From: Joe Perches @ 2020-04-29 3:23 UTC (permalink / raw)
To: Zou Wei, aviad.krawczyk, davem; +Cc: netdev, linux-kernel
On Wed, 2020-04-29 at 11:15 +0800, Zou Wei wrote:
> fix coccinelle warning, use ARRAY_SIZE
>
> drivers/net/ethernet/huawei/hinic/hinic_sriov.c:713:43-44: WARNING: Use ARRAY_SIZE
>
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Zou Wei <zou_wei@huawei.com>
> ---
> drivers/net/ethernet/huawei/hinic/hinic_sriov.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/huawei/hinic/hinic_sriov.c b/drivers/net/ethernet/huawei/hinic/hinic_sriov.c
> index b24788e..ac12725 100644
> --- a/drivers/net/ethernet/huawei/hinic/hinic_sriov.c
> +++ b/drivers/net/ethernet/huawei/hinic/hinic_sriov.c
> @@ -710,8 +710,7 @@ int nic_pf_mbox_handler(void *hwdev, u16 vf_id, u8 cmd, void *buf_in,
> if (!hwdev)
> return -EFAULT;
>
> - cmd_number = sizeof(nic_vf_cmd_msg_handler) /
> - sizeof(struct vf_cmd_msg_handle);
> + cmd_number = ARRAY_SIZE(nic_vf_cmd_msg_handler);
> pfhwdev = container_of(dev, struct hinic_pfhwdev, hwdev);
> nic_io = &dev->func_to_io;
> for (i = 0; i < cmd_number; i++) {
Probably better to remove cmd_number altogether
---
drivers/net/ethernet/huawei/hinic/hinic_sriov.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/drivers/net/ethernet/huawei/hinic/hinic_sriov.c b/drivers/net/ethernet/huawei/hinic/hinic_sriov.c
index b24788..af70cc 100644
--- a/drivers/net/ethernet/huawei/hinic/hinic_sriov.c
+++ b/drivers/net/ethernet/huawei/hinic/hinic_sriov.c
@@ -704,17 +704,15 @@ int nic_pf_mbox_handler(void *hwdev, u16 vf_id, u8 cmd, void *buf_in,
struct hinic_hwdev *dev = hwdev;
struct hinic_func_to_io *nic_io;
struct hinic_pfhwdev *pfhwdev;
- u32 i, cmd_number;
+ u32 i;
int err = 0;
if (!hwdev)
return -EFAULT;
- cmd_number = sizeof(nic_vf_cmd_msg_handler) /
- sizeof(struct vf_cmd_msg_handle);
pfhwdev = container_of(dev, struct hinic_pfhwdev, hwdev);
nic_io = &dev->func_to_io;
- for (i = 0; i < cmd_number; i++) {
+ for (i = 0; i < ARRAY_SIZE(nic_vf_cmd_msg_handler); i++) {
vf_msg_handle = &nic_vf_cmd_msg_handler[i];
if (cmd == vf_msg_handle->cmd &&
vf_msg_handle->cmd_msg_handler) {
@@ -725,7 +723,7 @@ int nic_pf_mbox_handler(void *hwdev, u16 vf_id, u8 cmd, void *buf_in,
break;
}
}
- if (i == cmd_number)
+ if (i == ARRAY_SIZE(nic_vf_cmd_msg_handler))
err = hinic_msg_to_mgmt(&pfhwdev->pf_to_mgmt, HINIC_MOD_L2NIC,
cmd, buf_in, in_size, buf_out,
out_size, HINIC_MGMT_MSG_SYNC);
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH -next] hinic: Use ARRAY_SIZE for nic_vf_cmd_msg_handler
2020-04-29 3:23 ` Joe Perches
@ 2020-04-29 3:50 ` Samuel Zou
0 siblings, 0 replies; 3+ messages in thread
From: Samuel Zou @ 2020-04-29 3:50 UTC (permalink / raw)
To: Joe Perches, davem; +Cc: netdev, linux-kernel
Hi Joe,
Thanks for your comments, I will modify and send the v2
On 2020/4/29 11:23, Joe Perches wrote:
> On Wed, 2020-04-29 at 11:15 +0800, Zou Wei wrote:
>> fix coccinelle warning, use ARRAY_SIZE
>>
>> drivers/net/ethernet/huawei/hinic/hinic_sriov.c:713:43-44: WARNING: Use ARRAY_SIZE
>>
>> Reported-by: Hulk Robot <hulkci@huawei.com>
>> Signed-off-by: Zou Wei <zou_wei@huawei.com>
>> ---
>> drivers/net/ethernet/huawei/hinic/hinic_sriov.c | 3 +--
>> 1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/huawei/hinic/hinic_sriov.c b/drivers/net/ethernet/huawei/hinic/hinic_sriov.c
>> index b24788e..ac12725 100644
>> --- a/drivers/net/ethernet/huawei/hinic/hinic_sriov.c
>> +++ b/drivers/net/ethernet/huawei/hinic/hinic_sriov.c
>> @@ -710,8 +710,7 @@ int nic_pf_mbox_handler(void *hwdev, u16 vf_id, u8 cmd, void *buf_in,
>> if (!hwdev)
>> return -EFAULT;
>>
>> - cmd_number = sizeof(nic_vf_cmd_msg_handler) /
>> - sizeof(struct vf_cmd_msg_handle);
>> + cmd_number = ARRAY_SIZE(nic_vf_cmd_msg_handler);
>> pfhwdev = container_of(dev, struct hinic_pfhwdev, hwdev);
>> nic_io = &dev->func_to_io;
>> for (i = 0; i < cmd_number; i++) {
>
> Probably better to remove cmd_number altogether
> ---
> drivers/net/ethernet/huawei/hinic/hinic_sriov.c | 8 +++-----
> 1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/net/ethernet/huawei/hinic/hinic_sriov.c b/drivers/net/ethernet/huawei/hinic/hinic_sriov.c
> index b24788..af70cc 100644
> --- a/drivers/net/ethernet/huawei/hinic/hinic_sriov.c
> +++ b/drivers/net/ethernet/huawei/hinic/hinic_sriov.c
> @@ -704,17 +704,15 @@ int nic_pf_mbox_handler(void *hwdev, u16 vf_id, u8 cmd, void *buf_in,
> struct hinic_hwdev *dev = hwdev;
> struct hinic_func_to_io *nic_io;
> struct hinic_pfhwdev *pfhwdev;
> - u32 i, cmd_number;
> + u32 i;
> int err = 0;
>
> if (!hwdev)
> return -EFAULT;
>
> - cmd_number = sizeof(nic_vf_cmd_msg_handler) /
> - sizeof(struct vf_cmd_msg_handle);
> pfhwdev = container_of(dev, struct hinic_pfhwdev, hwdev);
> nic_io = &dev->func_to_io;
> - for (i = 0; i < cmd_number; i++) {
> + for (i = 0; i < ARRAY_SIZE(nic_vf_cmd_msg_handler); i++) {
> vf_msg_handle = &nic_vf_cmd_msg_handler[i];
> if (cmd == vf_msg_handle->cmd &&
> vf_msg_handle->cmd_msg_handler) {
> @@ -725,7 +723,7 @@ int nic_pf_mbox_handler(void *hwdev, u16 vf_id, u8 cmd, void *buf_in,
> break;
> }
> }
> - if (i == cmd_number)
> + if (i == ARRAY_SIZE(nic_vf_cmd_msg_handler))
> err = hinic_msg_to_mgmt(&pfhwdev->pf_to_mgmt, HINIC_MOD_L2NIC,
> cmd, buf_in, in_size, buf_out,
> out_size, HINIC_MGMT_MSG_SYNC);
>
>
>
> .
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-04-29 3:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-29 3:15 [PATCH -next] hinic: Use ARRAY_SIZE for nic_vf_cmd_msg_handler Zou Wei
2020-04-29 3:23 ` Joe Perches
2020-04-29 3:50 ` Samuel Zou
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).