* [PATCH] devlink: use min() to make code cleaner
@ 2021-11-25 7:14 cgel.zte
2021-11-26 6:23 ` kernel test robot
2021-11-26 23:22 ` kernel test robot
0 siblings, 2 replies; 3+ messages in thread
From: cgel.zte @ 2021-11-25 7:14 UTC (permalink / raw)
To: jiri; +Cc: davem, kuba, netdev, linux-kernel, Lv Ruyi, Zeal Robot
From: Lv Ruyi <lv.ruyi@zte.com.cn>
Use the macro 'min()' defined in 'include/linux/minmax.h' to avoid
opencoding it.
Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Lv Ruyi <lv.ruyi@zte.com.cn>
---
net/core/devlink.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/net/core/devlink.c b/net/core/devlink.c
index d144a62cbf73..6ffbbb02fb91 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -9,6 +9,7 @@
#include <linux/kernel.h>
#include <linux/module.h>
+#include <linux/minmax.h>
#include <linux/types.h>
#include <linux/slab.h>
#include <linux/gfp.h>
@@ -5763,10 +5764,7 @@ static int devlink_nl_region_read_snapshot_fill(struct sk_buff *skb,
u32 data_size;
u8 *data;
- if (end_offset - curr_offset < DEVLINK_REGION_READ_CHUNK_SIZE)
- data_size = end_offset - curr_offset;
- else
- data_size = DEVLINK_REGION_READ_CHUNK_SIZE;
+ data_size = min(end_offset - curr_offset, DEVLINK_REGION_READ_CHUNK_SIZE);
data = &snapshot->data[curr_offset];
err = devlink_nl_cmd_region_read_chunk_fill(skb, devlink,
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] devlink: use min() to make code cleaner
2021-11-25 7:14 [PATCH] devlink: use min() to make code cleaner cgel.zte
@ 2021-11-26 6:23 ` kernel test robot
2021-11-26 23:22 ` kernel test robot
1 sibling, 0 replies; 3+ messages in thread
From: kernel test robot @ 2021-11-26 6:23 UTC (permalink / raw)
To: cgel.zte, jiri
Cc: llvm, kbuild-all, davem, kuba, netdev, linux-kernel, Lv Ruyi, Zeal Robot
Hi,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on linus/master]
[also build test WARNING on v5.16-rc2 next-20211125]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/cgel-zte-gmail-com/devlink-use-min-to-make-code-cleaner/20211125-151715
base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 5f53fa508db098c9d372423a6dac31c8a5679cdf
config: riscv-buildonly-randconfig-r002-20211125 (https://download.01.org/0day-ci/archive/20211126/202111261406.iXRaBqLo-lkp@intel.com/config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 0332d105b9ad7f1f0ffca7e78b71de8b3a48f158)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install riscv cross compiling tool for clang build
# apt-get install binutils-riscv64-linux-gnu
# https://github.com/0day-ci/linux/commit/836e00794d541adc38bfd77e1714579f2223a231
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review cgel-zte-gmail-com/devlink-use-min-to-make-code-cleaner/20211125-151715
git checkout 836e00794d541adc38bfd77e1714579f2223a231
# save the config file to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 ARCH=riscv
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
All warnings (new ones prefixed by >>):
>> net/core/devlink.c:5762:15: warning: comparison of distinct pointer types ('typeof (end_offset - curr_offset) *' (aka 'unsigned long long *') and 'typeof (256) *' (aka 'int *')) [-Wcompare-distinct-pointer-types]
data_size = min(end_offset - curr_offset, DEVLINK_REGION_READ_CHUNK_SIZE);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/minmax.h:45:19: note: expanded from macro 'min'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~~~~~~~~~~
include/linux/minmax.h:36:24: note: expanded from macro '__careful_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~~~~~~~
include/linux/minmax.h:26:4: note: expanded from macro '__safe_cmp'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~~~~~~~
include/linux/minmax.h:20:28: note: expanded from macro '__typecheck'
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~
1 warning generated.
vim +5762 net/core/devlink.c
5737
5738 static int devlink_nl_region_read_snapshot_fill(struct sk_buff *skb,
5739 struct devlink *devlink,
5740 struct devlink_region *region,
5741 struct nlattr **attrs,
5742 u64 start_offset,
5743 u64 end_offset,
5744 u64 *new_offset)
5745 {
5746 struct devlink_snapshot *snapshot;
5747 u64 curr_offset = start_offset;
5748 u32 snapshot_id;
5749 int err = 0;
5750
5751 *new_offset = start_offset;
5752
5753 snapshot_id = nla_get_u32(attrs[DEVLINK_ATTR_REGION_SNAPSHOT_ID]);
5754 snapshot = devlink_region_snapshot_get_by_id(region, snapshot_id);
5755 if (!snapshot)
5756 return -EINVAL;
5757
5758 while (curr_offset < end_offset) {
5759 u32 data_size;
5760 u8 *data;
5761
> 5762 data_size = min(end_offset - curr_offset, DEVLINK_REGION_READ_CHUNK_SIZE);
5763
5764 data = &snapshot->data[curr_offset];
5765 err = devlink_nl_cmd_region_read_chunk_fill(skb, devlink,
5766 data, data_size,
5767 curr_offset);
5768 if (err)
5769 break;
5770
5771 curr_offset += data_size;
5772 }
5773 *new_offset = curr_offset;
5774
5775 return err;
5776 }
5777
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] devlink: use min() to make code cleaner
2021-11-25 7:14 [PATCH] devlink: use min() to make code cleaner cgel.zte
2021-11-26 6:23 ` kernel test robot
@ 2021-11-26 23:22 ` kernel test robot
1 sibling, 0 replies; 3+ messages in thread
From: kernel test robot @ 2021-11-26 23:22 UTC (permalink / raw)
To: cgel.zte, jiri
Cc: kbuild-all, davem, kuba, netdev, linux-kernel, Lv Ruyi, Zeal Robot
Hi,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on linus/master]
[also build test WARNING on v5.16-rc2 next-20211126]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/cgel-zte-gmail-com/devlink-use-min-to-make-code-cleaner/20211125-151715
base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 5f53fa508db098c9d372423a6dac31c8a5679cdf
config: x86_64-randconfig-s022-20211126 (https://download.01.org/0day-ci/archive/20211127/202111270712.SjCO9Kz9-lkp@intel.com/config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce:
# apt-get install sparse
# sparse version: v0.6.4-dirty
# https://github.com/0day-ci/linux/commit/836e00794d541adc38bfd77e1714579f2223a231
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review cgel-zte-gmail-com/devlink-use-min-to-make-code-cleaner/20211125-151715
git checkout 836e00794d541adc38bfd77e1714579f2223a231
# save the config file to linux build tree
make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=x86_64 SHELL=/bin/bash net/core/
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
sparse warnings: (new ones prefixed by >>)
>> net/core/devlink.c:5762:29: sparse: sparse: incompatible types in comparison expression (different type sizes):
>> net/core/devlink.c:5762:29: sparse: unsigned long long *
>> net/core/devlink.c:5762:29: sparse: int *
vim +5762 net/core/devlink.c
5737
5738 static int devlink_nl_region_read_snapshot_fill(struct sk_buff *skb,
5739 struct devlink *devlink,
5740 struct devlink_region *region,
5741 struct nlattr **attrs,
5742 u64 start_offset,
5743 u64 end_offset,
5744 u64 *new_offset)
5745 {
5746 struct devlink_snapshot *snapshot;
5747 u64 curr_offset = start_offset;
5748 u32 snapshot_id;
5749 int err = 0;
5750
5751 *new_offset = start_offset;
5752
5753 snapshot_id = nla_get_u32(attrs[DEVLINK_ATTR_REGION_SNAPSHOT_ID]);
5754 snapshot = devlink_region_snapshot_get_by_id(region, snapshot_id);
5755 if (!snapshot)
5756 return -EINVAL;
5757
5758 while (curr_offset < end_offset) {
5759 u32 data_size;
5760 u8 *data;
5761
> 5762 data_size = min(end_offset - curr_offset, DEVLINK_REGION_READ_CHUNK_SIZE);
5763
5764 data = &snapshot->data[curr_offset];
5765 err = devlink_nl_cmd_region_read_chunk_fill(skb, devlink,
5766 data, data_size,
5767 curr_offset);
5768 if (err)
5769 break;
5770
5771 curr_offset += data_size;
5772 }
5773 *new_offset = curr_offset;
5774
5775 return err;
5776 }
5777
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-11-26 23:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-25 7:14 [PATCH] devlink: use min() to make code cleaner cgel.zte
2021-11-26 6:23 ` kernel test robot
2021-11-26 23:22 ` kernel test robot
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).