All of lore.kernel.org
 help / color / mirror / Atom feed
From: kernel test robot <lkp@intel.com>
To: kbuild@lists.01.org
Subject: [linux-next:master 3084/3449] drivers/edac/edac_device.c:72 edac_device_alloc_ctl_info() warn: Please consider using kcalloc instead
Date: Wed, 13 Apr 2022 01:59:49 +0800	[thread overview]
Message-ID: <202204130153.Ax6BiCzO-lkp@intel.com> (raw)

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

CC: kbuild-all(a)lists.01.org
BCC: lkp(a)intel.com
CC: Linux Memory Management List <linux-mm@kvack.org>
TO: Borislav Petkov <bp@suse.de>

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head:   d0c745e7b2d6ce8bcc768b32361ab8ef520821ee
commit: 9fb9ce392aae0c6654efc42c80e2f6bab88d5fe3 [3084/3449] EDAC/device: Get rid of the silly one-shot memory allocation in edac_device_alloc_ctl_info()
:::::: branch date: 12 hours ago
:::::: commit date: 32 hours ago
config: i386-randconfig-m021-20220411 (https://download.01.org/0day-ci/archive/20220413/202204130153.Ax6BiCzO-lkp(a)intel.com/config)
compiler: gcc-11 (Debian 11.2.0-19) 11.2.0

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

New smatch warnings:
drivers/edac/edac_device.c:72 edac_device_alloc_ctl_info() warn: Please consider using kcalloc instead

Old smatch warnings:
drivers/edac/edac_device.c:80 edac_device_alloc_ctl_info() warn: Please consider using kcalloc instead
drivers/edac/edac_device.c:89 edac_device_alloc_ctl_info() warn: Please consider using kcalloc instead

vim +72 drivers/edac/edac_device.c

e27e3dac651771f Douglas Thompson      2007-07-19   49  
e27e3dac651771f Douglas Thompson      2007-07-19   50  struct edac_device_ctl_info *edac_device_alloc_ctl_info(
e27e3dac651771f Douglas Thompson      2007-07-19   51  	unsigned sz_private,
52490c8d07680a7 Douglas Thompson      2007-07-19   52  	char *edac_device_name, unsigned nr_instances,
52490c8d07680a7 Douglas Thompson      2007-07-19   53  	char *edac_block_name, unsigned nr_blocks,
52490c8d07680a7 Douglas Thompson      2007-07-19   54  	unsigned offset_value,		/* zero, 1, or other based offset */
d45e7823baf655c Doug Thompson         2007-07-19   55  	struct edac_dev_sysfs_block_attribute *attrib_spec, unsigned nr_attrib,
d45e7823baf655c Doug Thompson         2007-07-19   56  	int device_index)
e27e3dac651771f Douglas Thompson      2007-07-19   57  {
e27e3dac651771f Douglas Thompson      2007-07-19   58  	struct edac_device_ctl_info *dev_ctl;
e27e3dac651771f Douglas Thompson      2007-07-19   59  	struct edac_device_instance *dev_inst, *inst;
e27e3dac651771f Douglas Thompson      2007-07-19   60  	struct edac_device_block *dev_blk, *blk_p, *blk;
fd309a9d8e63e91 Douglas Thompson      2007-07-19   61  	struct edac_dev_sysfs_block_attribute *dev_attrib, *attrib_p, *attrib;
e27e3dac651771f Douglas Thompson      2007-07-19   62  	unsigned instance, block, attr;
9fb9ce392aae0c6 Borislav Petkov       2022-03-08   63  	void *pvt;
1c3631ff1f805cb Douglas Thompson      2007-07-19   64  	int err;
e27e3dac651771f Douglas Thompson      2007-07-19   65  
956b9ba156dbfdb Joe Perches           2012-04-29   66  	edac_dbg(4, "instances=%d blocks=%d\n", nr_instances, nr_blocks);
e27e3dac651771f Douglas Thompson      2007-07-19   67  
9fb9ce392aae0c6 Borislav Petkov       2022-03-08   68  	dev_ctl = kzalloc(sizeof(struct edac_device_ctl_info), GFP_KERNEL);
9fb9ce392aae0c6 Borislav Petkov       2022-03-08   69  	if (!dev_ctl)
9fb9ce392aae0c6 Borislav Petkov       2022-03-08   70  		return NULL;
e27e3dac651771f Douglas Thompson      2007-07-19   71  
9fb9ce392aae0c6 Borislav Petkov       2022-03-08  @72  	dev_inst = kmalloc_array(nr_instances,
9fb9ce392aae0c6 Borislav Petkov       2022-03-08   73  				 sizeof(struct edac_device_instance),
9fb9ce392aae0c6 Borislav Petkov       2022-03-08   74  				 GFP_KERNEL | __GFP_ZERO);
9fb9ce392aae0c6 Borislav Petkov       2022-03-08   75  	if (!dev_inst)
9fb9ce392aae0c6 Borislav Petkov       2022-03-08   76  		goto free;
e27e3dac651771f Douglas Thompson      2007-07-19   77  
9fb9ce392aae0c6 Borislav Petkov       2022-03-08   78  	dev_ctl->instances = dev_inst;
e27e3dac651771f Douglas Thompson      2007-07-19   79  
9fb9ce392aae0c6 Borislav Petkov       2022-03-08   80  	dev_blk = kmalloc_array(nr_instances * nr_blocks,
9fb9ce392aae0c6 Borislav Petkov       2022-03-08   81  				sizeof(struct edac_device_block),
9fb9ce392aae0c6 Borislav Petkov       2022-03-08   82  				GFP_KERNEL | __GFP_ZERO);
9fb9ce392aae0c6 Borislav Petkov       2022-03-08   83  	if (!dev_blk)
9fb9ce392aae0c6 Borislav Petkov       2022-03-08   84  		goto free;
e27e3dac651771f Douglas Thompson      2007-07-19   85  
9fb9ce392aae0c6 Borislav Petkov       2022-03-08   86  	dev_ctl->blocks = dev_blk;
fd309a9d8e63e91 Douglas Thompson      2007-07-19   87  
9fb9ce392aae0c6 Borislav Petkov       2022-03-08   88  	if (nr_attrib) {
9fb9ce392aae0c6 Borislav Petkov       2022-03-08   89  		dev_attrib = kmalloc_array(nr_attrib,
9fb9ce392aae0c6 Borislav Petkov       2022-03-08   90  					   sizeof(struct edac_dev_sysfs_block_attribute),
9fb9ce392aae0c6 Borislav Petkov       2022-03-08   91  					   GFP_KERNEL | __GFP_ZERO);
9fb9ce392aae0c6 Borislav Petkov       2022-03-08   92  		if (!dev_attrib)
9fb9ce392aae0c6 Borislav Petkov       2022-03-08   93  			goto free;
e27e3dac651771f Douglas Thompson      2007-07-19   94  
9fb9ce392aae0c6 Borislav Petkov       2022-03-08   95  		dev_ctl->attribs = dev_attrib;
9fb9ce392aae0c6 Borislav Petkov       2022-03-08   96  	}
9fb9ce392aae0c6 Borislav Petkov       2022-03-08   97  
9fb9ce392aae0c6 Borislav Petkov       2022-03-08   98  	if (sz_private) {
9fb9ce392aae0c6 Borislav Petkov       2022-03-08   99  		pvt = kzalloc(sz_private, GFP_KERNEL);
9fb9ce392aae0c6 Borislav Petkov       2022-03-08  100  		if (!pvt)
9fb9ce392aae0c6 Borislav Petkov       2022-03-08  101  			goto free;
9fb9ce392aae0c6 Borislav Petkov       2022-03-08  102  
9fb9ce392aae0c6 Borislav Petkov       2022-03-08  103  		dev_ctl->pvt_info = pvt;
9fb9ce392aae0c6 Borislav Petkov       2022-03-08  104  	}
e27e3dac651771f Douglas Thompson      2007-07-19  105  
d45e7823baf655c Doug Thompson         2007-07-19  106  	dev_ctl->dev_idx	= device_index;
e27e3dac651771f Douglas Thompson      2007-07-19  107  	dev_ctl->nr_instances	= nr_instances;
e27e3dac651771f Douglas Thompson      2007-07-19  108  
56e61a9c5fe7b79 Doug Thompson         2008-02-07  109  	/* Default logging of CEs and UEs */
56e61a9c5fe7b79 Doug Thompson         2008-02-07  110  	dev_ctl->log_ce = 1;
56e61a9c5fe7b79 Doug Thompson         2008-02-07  111  	dev_ctl->log_ue = 1;
56e61a9c5fe7b79 Doug Thompson         2008-02-07  112  
52490c8d07680a7 Douglas Thompson      2007-07-19  113  	/* Name of this edac device */
e27e3dac651771f Douglas Thompson      2007-07-19  114  	snprintf(dev_ctl->name, sizeof(dev_ctl->name),"%s", edac_device_name);
e27e3dac651771f Douglas Thompson      2007-07-19  115  
e27e3dac651771f Douglas Thompson      2007-07-19  116  	/* Initialize every Instance */
e27e3dac651771f Douglas Thompson      2007-07-19  117  	for (instance = 0; instance < nr_instances; instance++) {
e27e3dac651771f Douglas Thompson      2007-07-19  118  		inst = &dev_inst[instance];
e27e3dac651771f Douglas Thompson      2007-07-19  119  		inst->ctl = dev_ctl;
e27e3dac651771f Douglas Thompson      2007-07-19  120  		inst->nr_blocks = nr_blocks;
e27e3dac651771f Douglas Thompson      2007-07-19  121  		blk_p = &dev_blk[instance * nr_blocks];
e27e3dac651771f Douglas Thompson      2007-07-19  122  		inst->blocks = blk_p;
e27e3dac651771f Douglas Thompson      2007-07-19  123  
e27e3dac651771f Douglas Thompson      2007-07-19  124  		/* name of this instance */
e27e3dac651771f Douglas Thompson      2007-07-19  125  		snprintf(inst->name, sizeof(inst->name),
e27e3dac651771f Douglas Thompson      2007-07-19  126  			 "%s%u", edac_device_name, instance);
e27e3dac651771f Douglas Thompson      2007-07-19  127  
e27e3dac651771f Douglas Thompson      2007-07-19  128  		/* Initialize every block in each instance */
079708b9173595b Douglas Thompson      2007-07-19  129  		for (block = 0; block < nr_blocks; block++) {
e27e3dac651771f Douglas Thompson      2007-07-19  130  			blk = &blk_p[block];
e27e3dac651771f Douglas Thompson      2007-07-19  131  			blk->instance = inst;
e27e3dac651771f Douglas Thompson      2007-07-19  132  			snprintf(blk->name, sizeof(blk->name),
d391a7b8147d12b Douglas Thompson      2007-07-19  133  				 "%s%d", edac_block_name, block+offset_value);
e27e3dac651771f Douglas Thompson      2007-07-19  134  
956b9ba156dbfdb Joe Perches           2012-04-29  135  			edac_dbg(4, "instance=%d inst_p=%p block=#%d block_p=%p name='%s'\n",
956b9ba156dbfdb Joe Perches           2012-04-29  136  				 instance, inst, block, blk, blk->name);
e27e3dac651771f Douglas Thompson      2007-07-19  137  
fd309a9d8e63e91 Douglas Thompson      2007-07-19  138  			/* if there are NO attributes OR no attribute pointer
fd309a9d8e63e91 Douglas Thompson      2007-07-19  139  			 * then continue on to next block iteration
e27e3dac651771f Douglas Thompson      2007-07-19  140  			 */
fd309a9d8e63e91 Douglas Thompson      2007-07-19  141  			if ((nr_attrib == 0) || (attrib_spec == NULL))
fd309a9d8e63e91 Douglas Thompson      2007-07-19  142  				continue;
fd309a9d8e63e91 Douglas Thompson      2007-07-19  143  
fd309a9d8e63e91 Douglas Thompson      2007-07-19  144  			/* setup the attribute array for this block */
fd309a9d8e63e91 Douglas Thompson      2007-07-19  145  			blk->nr_attribs = nr_attrib;
fd309a9d8e63e91 Douglas Thompson      2007-07-19  146  			attrib_p = &dev_attrib[block*nr_instances*nr_attrib];
fd309a9d8e63e91 Douglas Thompson      2007-07-19  147  			blk->block_attributes = attrib_p;
fd309a9d8e63e91 Douglas Thompson      2007-07-19  148  
956b9ba156dbfdb Joe Perches           2012-04-29  149  			edac_dbg(4, "THIS BLOCK_ATTRIB=%p\n",
dd23cd6eb1f59ba Mauro Carvalho Chehab 2012-04-29  150  				 blk->block_attributes);
b2a4ac0c2860b27 Doug Thompson         2007-07-19  151  
fd309a9d8e63e91 Douglas Thompson      2007-07-19  152  			/* Initialize every user specified attribute in this
fd309a9d8e63e91 Douglas Thompson      2007-07-19  153  			 * block with the data the caller passed in
b2a4ac0c2860b27 Doug Thompson         2007-07-19  154  			 * Each block gets its own copy of pointers,
b2a4ac0c2860b27 Doug Thompson         2007-07-19  155  			 * and its unique 'value'
fd309a9d8e63e91 Douglas Thompson      2007-07-19  156  			 */
fd309a9d8e63e91 Douglas Thompson      2007-07-19  157  			for (attr = 0; attr < nr_attrib; attr++) {
e27e3dac651771f Douglas Thompson      2007-07-19  158  				attrib = &attrib_p[attr];
e27e3dac651771f Douglas Thompson      2007-07-19  159  
b2a4ac0c2860b27 Doug Thompson         2007-07-19  160  				/* populate the unique per attrib
b2a4ac0c2860b27 Doug Thompson         2007-07-19  161  				 * with the code pointers and info
b2a4ac0c2860b27 Doug Thompson         2007-07-19  162  				 */
b2a4ac0c2860b27 Doug Thompson         2007-07-19  163  				attrib->attr = attrib_spec[attr].attr;
b2a4ac0c2860b27 Doug Thompson         2007-07-19  164  				attrib->show = attrib_spec[attr].show;
b2a4ac0c2860b27 Doug Thompson         2007-07-19  165  				attrib->store = attrib_spec[attr].store;
b2a4ac0c2860b27 Doug Thompson         2007-07-19  166  
b2a4ac0c2860b27 Doug Thompson         2007-07-19  167  				attrib->block = blk;	/* up link */
b2a4ac0c2860b27 Doug Thompson         2007-07-19  168  
956b9ba156dbfdb Joe Perches           2012-04-29  169  				edac_dbg(4, "alloc-attrib=%p attrib_name='%s' attrib-spec=%p spec-name=%s\n",
dd23cd6eb1f59ba Mauro Carvalho Chehab 2012-04-29  170  					 attrib, attrib->attr.name,
b2a4ac0c2860b27 Doug Thompson         2007-07-19  171  					 &attrib_spec[attr],
b2a4ac0c2860b27 Doug Thompson         2007-07-19  172  					 attrib_spec[attr].attr.name
b2a4ac0c2860b27 Doug Thompson         2007-07-19  173  					);
e27e3dac651771f Douglas Thompson      2007-07-19  174  			}
e27e3dac651771f Douglas Thompson      2007-07-19  175  		}
e27e3dac651771f Douglas Thompson      2007-07-19  176  	}
e27e3dac651771f Douglas Thompson      2007-07-19  177  
e27e3dac651771f Douglas Thompson      2007-07-19  178  	/* Mark this instance as merely ALLOCATED */
e27e3dac651771f Douglas Thompson      2007-07-19  179  	dev_ctl->op_state = OP_ALLOC;
e27e3dac651771f Douglas Thompson      2007-07-19  180  
1c3631ff1f805cb Douglas Thompson      2007-07-19  181  	/*
1c3631ff1f805cb Douglas Thompson      2007-07-19  182  	 * Initialize the 'root' kobj for the edac_device controller
1c3631ff1f805cb Douglas Thompson      2007-07-19  183  	 */
1c3631ff1f805cb Douglas Thompson      2007-07-19  184  	err = edac_device_register_sysfs_main_kobj(dev_ctl);
9fb9ce392aae0c6 Borislav Petkov       2022-03-08  185  	if (err)
9fb9ce392aae0c6 Borislav Petkov       2022-03-08  186  		goto free;
1c3631ff1f805cb Douglas Thompson      2007-07-19  187  
1c3631ff1f805cb Douglas Thompson      2007-07-19  188  	/* at this point, the root kobj is valid, and in order to
1c3631ff1f805cb Douglas Thompson      2007-07-19  189  	 * 'free' the object, then the function:
1c3631ff1f805cb Douglas Thompson      2007-07-19  190  	 *	edac_device_unregister_sysfs_main_kobj() must be called
1c3631ff1f805cb Douglas Thompson      2007-07-19  191  	 * which will perform kobj unregistration and the actual free
1c3631ff1f805cb Douglas Thompson      2007-07-19  192  	 * will occur during the kobject callback operation
1c3631ff1f805cb Douglas Thompson      2007-07-19  193  	 */
1c3631ff1f805cb Douglas Thompson      2007-07-19  194  
e27e3dac651771f Douglas Thompson      2007-07-19  195  	return dev_ctl;
9fb9ce392aae0c6 Borislav Petkov       2022-03-08  196  
9fb9ce392aae0c6 Borislav Petkov       2022-03-08  197  free:
9fb9ce392aae0c6 Borislav Petkov       2022-03-08  198  	__edac_device_free_ctl_info(dev_ctl);
9fb9ce392aae0c6 Borislav Petkov       2022-03-08  199  
9fb9ce392aae0c6 Borislav Petkov       2022-03-08  200  	return NULL;
e27e3dac651771f Douglas Thompson      2007-07-19  201  }
e27e3dac651771f Douglas Thompson      2007-07-19  202  EXPORT_SYMBOL_GPL(edac_device_alloc_ctl_info);
e27e3dac651771f Douglas Thompson      2007-07-19  203  

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

                 reply	other threads:[~2022-04-12 17:59 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=202204130153.Ax6BiCzO-lkp@intel.com \
    --to=lkp@intel.com \
    --cc=kbuild@lists.01.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.