All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH] soc/qcom: use struct_size over open coded arithmetic
@ 2022-02-16 15:41 Nathan Chancellor
  0 siblings, 0 replies; 4+ messages in thread
From: Nathan Chancellor @ 2022-02-16 15:41 UTC (permalink / raw)
  To: cgel.zte
  Cc: agross, bjorn.andersson, linux-arm-msm, linux-kernel, chi.minghao

Hi,

I am forwarding along this build report from the kernel test robot due
to a bug in their system. As I am sure you will figure out soon enough,
this patch was not even build tested.

Cheers,
Nathan

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] soc/qcom: use struct_size over open coded arithmetic
  2022-02-16  3:07 cgel.zte
@ 2022-02-16  7:53   ` kernel test robot
  0 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2022-02-16  7:53 UTC (permalink / raw)
  To: cgel.zte; +Cc: llvm, kbuild-all

Hi,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v5.17-rc4 next-20220215]
[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/soc-qcom-use-struct_size-over-open-coded-arithmetic/20220216-111200
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git c5d9ae265b105d9a67575fb67bd4650a6fc08e25
config: hexagon-randconfig-r045-20220216 (https://download.01.org/0day-ci/archive/20220216/202202161548.Pvcgszt3-lkp@intel.com/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 0e628a783b935c70c80815db6c061ec84f884af5)
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
        # https://github.com/0day-ci/linux/commit/51dde142db132ac922a62df2932acb6f27528e99
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review cgel-zte-gmail-com/soc-qcom-use-struct_size-over-open-coded-arithmetic/20220216-111200
        git checkout 51dde142db132ac922a62df2932acb6f27528e99
        # save the config file to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash drivers/soc/qcom/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All error/warnings (new ones prefixed by >>):

>> drivers/soc/qcom/apr.c:174:18: warning: ignoring return value of function declared with 'warn_unused_result' attribute [-Wunused-result]
           abuf = kzalloc((struct_size(abuf, buf, len), GFP_ATOMIC);
                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/overflow.h:193:2: note: expanded from macro 'struct_size'
           __ab_c_size(count,                                              \
           ^~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/soc/qcom/apr.c:174:58: error: expected ')'
           abuf = kzalloc((struct_size(abuf, buf, len), GFP_ATOMIC);
                                                                   ^
   drivers/soc/qcom/apr.c:174:16: note: to match this '('
           abuf = kzalloc((struct_size(abuf, buf, len), GFP_ATOMIC);
                         ^
   1 warning and 1 error generated.


vim +174 drivers/soc/qcom/apr.c

   160	
   161	static int apr_callback(struct rpmsg_device *rpdev, void *buf,
   162					  int len, void *priv, u32 addr)
   163	{
   164		struct packet_router *apr = dev_get_drvdata(&rpdev->dev);
   165		struct apr_rx_buf *abuf;
   166		unsigned long flags;
   167	
   168		if (len <= APR_HDR_SIZE) {
   169			dev_err(apr->dev, "APR: Improper apr pkt received:%p %d\n",
   170				buf, len);
   171			return -EINVAL;
   172		}
   173	
 > 174		abuf = kzalloc((struct_size(abuf, buf, len), GFP_ATOMIC);
   175		if (!abuf)
   176			return -ENOMEM;
   177	
   178		abuf->len = len;
   179		memcpy(abuf->buf, buf, len);
   180	
   181		spin_lock_irqsave(&apr->rx_lock, flags);
   182		list_add_tail(&abuf->node, &apr->rx_list);
   183		spin_unlock_irqrestore(&apr->rx_lock, flags);
   184	
   185		queue_work(apr->rxwq, &apr->rx_work);
   186	
   187		return 0;
   188	}
   189	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] soc/qcom: use struct_size over open coded arithmetic
@ 2022-02-16  7:53   ` kernel test robot
  0 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2022-02-16  7:53 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 3700 bytes --]

Hi,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v5.17-rc4 next-20220215]
[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/soc-qcom-use-struct_size-over-open-coded-arithmetic/20220216-111200
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git c5d9ae265b105d9a67575fb67bd4650a6fc08e25
config: hexagon-randconfig-r045-20220216 (https://download.01.org/0day-ci/archive/20220216/202202161548.Pvcgszt3-lkp(a)intel.com/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 0e628a783b935c70c80815db6c061ec84f884af5)
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
        # https://github.com/0day-ci/linux/commit/51dde142db132ac922a62df2932acb6f27528e99
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review cgel-zte-gmail-com/soc-qcom-use-struct_size-over-open-coded-arithmetic/20220216-111200
        git checkout 51dde142db132ac922a62df2932acb6f27528e99
        # save the config file to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash drivers/soc/qcom/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All error/warnings (new ones prefixed by >>):

>> drivers/soc/qcom/apr.c:174:18: warning: ignoring return value of function declared with 'warn_unused_result' attribute [-Wunused-result]
           abuf = kzalloc((struct_size(abuf, buf, len), GFP_ATOMIC);
                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/overflow.h:193:2: note: expanded from macro 'struct_size'
           __ab_c_size(count,                                              \
           ^~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/soc/qcom/apr.c:174:58: error: expected ')'
           abuf = kzalloc((struct_size(abuf, buf, len), GFP_ATOMIC);
                                                                   ^
   drivers/soc/qcom/apr.c:174:16: note: to match this '('
           abuf = kzalloc((struct_size(abuf, buf, len), GFP_ATOMIC);
                         ^
   1 warning and 1 error generated.


vim +174 drivers/soc/qcom/apr.c

   160	
   161	static int apr_callback(struct rpmsg_device *rpdev, void *buf,
   162					  int len, void *priv, u32 addr)
   163	{
   164		struct packet_router *apr = dev_get_drvdata(&rpdev->dev);
   165		struct apr_rx_buf *abuf;
   166		unsigned long flags;
   167	
   168		if (len <= APR_HDR_SIZE) {
   169			dev_err(apr->dev, "APR: Improper apr pkt received:%p %d\n",
   170				buf, len);
   171			return -EINVAL;
   172		}
   173	
 > 174		abuf = kzalloc((struct_size(abuf, buf, len), GFP_ATOMIC);
   175		if (!abuf)
   176			return -ENOMEM;
   177	
   178		abuf->len = len;
   179		memcpy(abuf->buf, buf, len);
   180	
   181		spin_lock_irqsave(&apr->rx_lock, flags);
   182		list_add_tail(&abuf->node, &apr->rx_list);
   183		spin_unlock_irqrestore(&apr->rx_lock, flags);
   184	
   185		queue_work(apr->rxwq, &apr->rx_work);
   186	
   187		return 0;
   188	}
   189	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] soc/qcom: use struct_size over open coded arithmetic
@ 2022-02-16  3:07 cgel.zte
  2022-02-16  7:53   ` kernel test robot
  0 siblings, 1 reply; 4+ messages in thread
From: cgel.zte @ 2022-02-16  3:07 UTC (permalink / raw)
  To: agross
  Cc: bjorn.andersson, linux-arm-msm, linux-kernel,
	Minghao Chi (CGEL ZTE),
	Zeal Robot

From: "Minghao Chi (CGEL ZTE)" <chi.minghao@zte.com.cn>

Replace zero-length array with flexible-array member and make use
of the struct_size() helper in kzalloc(). For example:

struct apr_rx_buf {
	struct list_head node;
	int len;
	uint8_t buf[];
};

Make use of the struct_size() helper instead of an open-coded version
in order to avoid any potential type mistakes.

Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Minghao Chi (CGEL ZTE) <chi.minghao@zte.com.cn>
---
 drivers/soc/qcom/apr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/soc/qcom/apr.c b/drivers/soc/qcom/apr.c
index 82ca12c9328a..0813dbc5e462 100644
--- a/drivers/soc/qcom/apr.c
+++ b/drivers/soc/qcom/apr.c
@@ -171,7 +171,7 @@ static int apr_callback(struct rpmsg_device *rpdev, void *buf,
 		return -EINVAL;
 	}
 
-	abuf = kzalloc(sizeof(*abuf) + len, GFP_ATOMIC);
+	abuf = kzalloc((struct_size(abuf, buf, len), GFP_ATOMIC);
 	if (!abuf)
 		return -ENOMEM;
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-02-16 15:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-16 15:41 [PATCH] soc/qcom: use struct_size over open coded arithmetic Nathan Chancellor
  -- strict thread matches above, loose matches on Subject: below --
2022-02-16  3:07 cgel.zte
2022-02-16  7:53 ` kernel test robot
2022-02-16  7:53   ` kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.