* [PATCH] ice: use min() to make code cleaner in ice_gnss
@ 2022-03-18 9:46 Wan Jiabing
2022-03-18 20:19 ` Tony Nguyen
0 siblings, 1 reply; 6+ messages in thread
From: Wan Jiabing @ 2022-03-18 9:46 UTC (permalink / raw)
To: Jesse Brandeburg, Tony Nguyen, David S. Miller, Jakub Kicinski,
Paolo Abeni, intel-wired-lan, netdev, linux-kernel
Cc: Wan Jiabing
Fix the following coccicheck warning:
./drivers/net/ethernet/intel/ice/ice_gnss.c:79:26-27: WARNING opportunity for min()
Use min() to make code cleaner.
Signed-off-by: Wan Jiabing <wanjiabing@vivo.com>
---
drivers/net/ethernet/intel/ice/ice_gnss.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/intel/ice/ice_gnss.c b/drivers/net/ethernet/intel/ice/ice_gnss.c
index 35579cf4283f..00fd22e813c0 100644
--- a/drivers/net/ethernet/intel/ice/ice_gnss.c
+++ b/drivers/net/ethernet/intel/ice/ice_gnss.c
@@ -76,8 +76,7 @@ static void ice_gnss_read(struct kthread_work *work)
for (i = 0; i < data_len; i += bytes_read) {
u16 bytes_left = data_len - i;
- bytes_read = bytes_left < ICE_MAX_I2C_DATA_SIZE ? bytes_left :
- ICE_MAX_I2C_DATA_SIZE;
+ bytes_read = min(bytes_left, ICE_MAX_I2C_DATA_SIZE);
err = ice_aq_read_i2c(hw, link_topo, ICE_GNSS_UBX_I2C_BUS_ADDR,
cpu_to_le16(ICE_GNSS_UBX_EMPTY_DATA),
--
2.35.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] ice: use min() to make code cleaner in ice_gnss
2022-03-18 9:46 [PATCH] ice: use min() to make code cleaner in ice_gnss Wan Jiabing
@ 2022-03-18 20:19 ` Tony Nguyen
2022-03-19 4:24 ` Wan Jiabing
2022-03-21 11:54 ` [Intel-wired-lan] " Alexander Lobakin
0 siblings, 2 replies; 6+ messages in thread
From: Tony Nguyen @ 2022-03-18 20:19 UTC (permalink / raw)
To: Wan Jiabing, Jesse Brandeburg, David S. Miller, Jakub Kicinski,
Paolo Abeni, intel-wired-lan, netdev, linux-kernel
On 3/18/2022 2:46 AM, Wan Jiabing wrote:
> Fix the following coccicheck warning:
> ./drivers/net/ethernet/intel/ice/ice_gnss.c:79:26-27: WARNING opportunity for min()
>
> Use min() to make code cleaner.
>
> Signed-off-by: Wan Jiabing <wanjiabing@vivo.com>
There are build issues with this patch:
In file included from ./include/linux/kernel.h:26,
from drivers/net/ethernet/intel/ice/ice.h:9,
from drivers/net/ethernet/intel/ice/ice_gnss.c:4:
drivers/net/ethernet/intel/ice/ice_gnss.c: In function ‘ice_gnss_read’:
./include/linux/minmax.h:20:35: error: comparison of distinct pointer
types lacks a cast [-Werror]
20 | (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
| ^~
./include/linux/minmax.h:26:18: note: in expansion of macro ‘__typecheck’
26 | (__typecheck(x, y) && __no_side_effects(x, y))
| ^~~~~~~~~~~
./include/linux/minmax.h:36:31: note: in expansion of macro ‘__safe_cmp’
36 | __builtin_choose_expr(__safe_cmp(x, y), \
| ^~~~~~~~~~
./include/linux/minmax.h:45:25: note: in expansion of macro ‘__careful_cmp’
45 | #define min(x, y) __careful_cmp(x, y, <)
| ^~~~~~~~~~~~~
drivers/net/ethernet/intel/ice/ice_gnss.c:79:30: note: in expansion of
macro ‘min’
79 | bytes_read = min(bytes_left,
ICE_MAX_I2C_DATA_SIZE);
| ^~~
cc1: all warnings being treated as errors
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] ice: use min() to make code cleaner in ice_gnss
2022-03-18 20:19 ` Tony Nguyen
@ 2022-03-19 4:24 ` Wan Jiabing
2022-03-21 11:54 ` [Intel-wired-lan] " Alexander Lobakin
1 sibling, 0 replies; 6+ messages in thread
From: Wan Jiabing @ 2022-03-19 4:24 UTC (permalink / raw)
To: Tony Nguyen
Cc: Jesse Brandeburg, David S. Miller, Jakub Kicinski, Paolo Abeni,
intel-wired-lan, netdev, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 2101 bytes --]
On Fri, Mar 18, 2022 at 01:19:26PM -0700, Tony Nguyen wrote:
>
> On 3/18/2022 2:46 AM, Wan Jiabing wrote:
> > Fix the following coccicheck warning:
> > ./drivers/net/ethernet/intel/ice/ice_gnss.c:79:26-27: WARNING opportunity for min()
> >
> > Use min() to make code cleaner.
> >
> > Signed-off-by: Wan Jiabing <wanjiabing@vivo.com>
>
> There are build issues with this patch:
>
> In file included from ./include/linux/kernel.h:26,
> from drivers/net/ethernet/intel/ice/ice.h:9,
> from drivers/net/ethernet/intel/ice/ice_gnss.c:4:
> drivers/net/ethernet/intel/ice/ice_gnss.c: In function ‘ice_gnss_read’:
> ./include/linux/minmax.h:20:35: error: comparison of distinct pointer types
> lacks a cast [-Werror]
> 20 | (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
> | ^~
> ./include/linux/minmax.h:26:18: note: in expansion of macro ‘__typecheck’
> 26 | (__typecheck(x, y) && __no_side_effects(x, y))
> | ^~~~~~~~~~~
> ./include/linux/minmax.h:36:31: note: in expansion of macro ‘__safe_cmp’
> 36 | __builtin_choose_expr(__safe_cmp(x, y), \
> | ^~~~~~~~~~
> ./include/linux/minmax.h:45:25: note: in expansion of macro ‘__careful_cmp’
> 45 | #define min(x, y) __careful_cmp(x, y, <)
> | ^~~~~~~~~~~~~
> drivers/net/ethernet/intel/ice/ice_gnss.c:79:30: note: in expansion of macro
> ‘min’
> 79 | bytes_read = min(bytes_left, ICE_MAX_I2C_DATA_SIZE);
> | ^~~
> cc1: all warnings being treated as errors
>
Yes, sorry for the warning.
After check minmax.h, it's better to use min_t and there are no warnings.
Please check the new patch, thanks!
Wan Jiabing
[-- Attachment #2: 0001-ice-use-min_t-to-make-code-cleaner-in-ice_gnss.patch --]
[-- Type: text/plain, Size: 1171 bytes --]
From 43118a4f14393816054a41e4861106cdb623b3d9 Mon Sep 17 00:00:00 2001
From: Wan Jiabing <wanjiabing@vivo.com>
Date: Sat, 19 Mar 2022 12:01:29 +0800
Subject: [PATCH] ice: use min_t() to make code cleaner in ice_gnss
Fix the following coccicheck warning:
./drivers/net/ethernet/intel/ice/ice_gnss.c:79:26-27: WARNING opportunity for min()
Signed-off-by: Wan Jiabing <wanjiabing@vivo.com>
---
drivers/net/ethernet/intel/ice/ice_gnss.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/intel/ice/ice_gnss.c b/drivers/net/ethernet/intel/ice/ice_gnss.c
index 35579cf4283f..85ceb7018781 100644
--- a/drivers/net/ethernet/intel/ice/ice_gnss.c
+++ b/drivers/net/ethernet/intel/ice/ice_gnss.c
@@ -76,8 +76,7 @@ static void ice_gnss_read(struct kthread_work *work)
for (i = 0; i < data_len; i += bytes_read) {
u16 bytes_left = data_len - i;
- bytes_read = bytes_left < ICE_MAX_I2C_DATA_SIZE ? bytes_left :
- ICE_MAX_I2C_DATA_SIZE;
+ bytes_read = min_t(u8, bytes_left, ICE_MAX_I2C_DATA_SIZE);
err = ice_aq_read_i2c(hw, link_topo, ICE_GNSS_UBX_I2C_BUS_ADDR,
cpu_to_le16(ICE_GNSS_UBX_EMPTY_DATA),
--
2.35.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [Intel-wired-lan] [PATCH] ice: use min() to make code cleaner in ice_gnss
2022-03-18 20:19 ` Tony Nguyen
2022-03-19 4:24 ` Wan Jiabing
@ 2022-03-21 11:54 ` Alexander Lobakin
2022-03-21 12:02 ` Jiabing Wan
2022-03-21 15:47 ` David Laight
1 sibling, 2 replies; 6+ messages in thread
From: Alexander Lobakin @ 2022-03-21 11:54 UTC (permalink / raw)
To: Wan Jiabing
Cc: Alexander Lobakin, Tony Nguyen, Jesse Brandeburg,
David S. Miller, Jakub Kicinski, Paolo Abeni, intel-wired-lan,
netdev, linux-kernel
From: Tony Nguyen <anthony.l.nguyen@intel.com>
Date: Fri, 18 Mar 2022 13:19:26 -0700
> On 3/18/2022 2:46 AM, Wan Jiabing wrote:
Hey Wan,
> > Fix the following coccicheck warning:
> > ./drivers/net/ethernet/intel/ice/ice_gnss.c:79:26-27: WARNING opportunity for min()
> >
> > Use min() to make code cleaner.
> >
> > Signed-off-by: Wan Jiabing <wanjiabing@vivo.com>
>
> There are build issues with this patch:
>
> In file included from ./include/linux/kernel.h:26,
> from drivers/net/ethernet/intel/ice/ice.h:9,
> from drivers/net/ethernet/intel/ice/ice_gnss.c:4:
> drivers/net/ethernet/intel/ice/ice_gnss.c: In function 'ice_gnss_read':
> ./include/linux/minmax.h:20:35: error: comparison of distinct pointer types lacks a cast [-Werror]
> 20 | (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
> | ^~
> ./include/linux/minmax.h:26:18: note: in expansion of macro '__typecheck'
> 26 | (__typecheck(x, y) && __no_side_effects(x, y))
> | ^~~~~~~~~~~
> ./include/linux/minmax.h:36:31: note: in expansion of macro '__safe_cmp'
> 36 | __builtin_choose_expr(__safe_cmp(x, y), \
> | ^~~~~~~~~~
> ./include/linux/minmax.h:45:25: note: in expansion of macro '__careful_cmp'
> 45 | #define min(x, y) __careful_cmp(x, y, <)
> | ^~~~~~~~~~~~~
> drivers/net/ethernet/intel/ice/ice_gnss.c:79:30: note: in expansion of macro 'min'
> 79 | bytes_read = min(bytes_left, ICE_MAX_I2C_DATA_SIZE);
> | ^~~
Use `min_t(typeof(bytes_left), ICE_MAX_I2C_DATA_SIZE)` to avoid
this. Plain definitions are usually treated as `unsigned long`
unless there's a suffix (u, ull etc.).
> cc1: all warnings being treated as errors
Thanks,
Al
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Intel-wired-lan] [PATCH] ice: use min() to make code cleaner in ice_gnss
2022-03-21 11:54 ` [Intel-wired-lan] " Alexander Lobakin
@ 2022-03-21 12:02 ` Jiabing Wan
2022-03-21 15:47 ` David Laight
1 sibling, 0 replies; 6+ messages in thread
From: Jiabing Wan @ 2022-03-21 12:02 UTC (permalink / raw)
To: Alexander Lobakin
Cc: Tony Nguyen, Jesse Brandeburg, David S. Miller, Jakub Kicinski,
Paolo Abeni, intel-wired-lan, netdev, linux-kernel
On 2022/3/21 19:54, Alexander Lobakin wrote:
> From: Tony Nguyen <anthony.l.nguyen@intel.com>
> Date: Fri, 18 Mar 2022 13:19:26 -0700
>
>> On 3/18/2022 2:46 AM, Wan Jiabing wrote:
> Hey Wan,
>
>>> Fix the following coccicheck warning:
>>> ./drivers/net/ethernet/intel/ice/ice_gnss.c:79:26-27: WARNING opportunity for min()
>>>
>>> Use min() to make code cleaner.
>>>
>>> Signed-off-by: Wan Jiabing <wanjiabing@vivo.com>
>> There are build issues with this patch:
>>
>> In file included from ./include/linux/kernel.h:26,
>> from drivers/net/ethernet/intel/ice/ice.h:9,
>> from drivers/net/ethernet/intel/ice/ice_gnss.c:4:
>> drivers/net/ethernet/intel/ice/ice_gnss.c: In function 'ice_gnss_read':
>> ./include/linux/minmax.h:20:35: error: comparison of distinct pointer types lacks a cast [-Werror]
>> 20 | (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
>> | ^~
>> ./include/linux/minmax.h:26:18: note: in expansion of macro '__typecheck'
>> 26 | (__typecheck(x, y) && __no_side_effects(x, y))
>> | ^~~~~~~~~~~
>> ./include/linux/minmax.h:36:31: note: in expansion of macro '__safe_cmp'
>> 36 | __builtin_choose_expr(__safe_cmp(x, y), \
>> | ^~~~~~~~~~
>> ./include/linux/minmax.h:45:25: note: in expansion of macro '__careful_cmp'
>> 45 | #define min(x, y) __careful_cmp(x, y, <)
>> | ^~~~~~~~~~~~~
>> drivers/net/ethernet/intel/ice/ice_gnss.c:79:30: note: in expansion of macro 'min'
>> 79 | bytes_read = min(bytes_left, ICE_MAX_I2C_DATA_SIZE);
>> | ^~~
> Use `min_t(typeof(bytes_left), ICE_MAX_I2C_DATA_SIZE)` to avoid
> this. Plain definitions are usually treated as `unsigned long`
> unless there's a suffix (u, ull etc.).
>
>> cc1: all warnings being treated as errors
> Thanks,
> Al
OK, I'll fix it in v2.
Thanks,
Wan Jiabing
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [Intel-wired-lan] [PATCH] ice: use min() to make code cleaner in ice_gnss
2022-03-21 11:54 ` [Intel-wired-lan] " Alexander Lobakin
2022-03-21 12:02 ` Jiabing Wan
@ 2022-03-21 15:47 ` David Laight
1 sibling, 0 replies; 6+ messages in thread
From: David Laight @ 2022-03-21 15:47 UTC (permalink / raw)
To: 'Alexander Lobakin', Wan Jiabing
Cc: Tony Nguyen, Jesse Brandeburg, David S. Miller, Jakub Kicinski,
Paolo Abeni, intel-wired-lan, netdev, linux-kernel
> Use `min_t(typeof(bytes_left), ICE_MAX_I2C_DATA_SIZE)` to avoid
> this. Plain definitions are usually treated as `unsigned long`
> unless there's a suffix (u, ull etc.).
I suspect they are 'int'.
And the compiler will convert to 'unsigned int' in any
arithmetic.
And the 'signed v unsigned' compare warning is supressed
to integer constants.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-03-21 15:47 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-18 9:46 [PATCH] ice: use min() to make code cleaner in ice_gnss Wan Jiabing
2022-03-18 20:19 ` Tony Nguyen
2022-03-19 4:24 ` Wan Jiabing
2022-03-21 11:54 ` [Intel-wired-lan] " Alexander Lobakin
2022-03-21 12:02 ` Jiabing Wan
2022-03-21 15:47 ` David Laight
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).