All of lore.kernel.org
 help / color / mirror / Atom feed
* [lpieralisi-pci:pci/rcar 8/11] drivers/pci/endpoint/pci-epc-mem.c:65 pci_epc_multi_mem_init() warn: double check that we're allocating correct size: 4 vs 112
@ 2020-05-19 13:37 ` Dan Carpenter
  0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2020-05-19 13:37 UTC (permalink / raw)
  To: kbuild

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

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/lpieralisi/pci.git pci/rcar
head:   3aecbd9786b5e91d7d4819434b20db7dcf71761b
commit: ecbae8715e31504a6ca2f596ed5322a78bb971cb [8/11] PCI: endpoint: Add support to handle multiple base for mapping outbound memory

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

smatch warnings:
drivers/pci/endpoint/pci-epc-mem.c:65 pci_epc_multi_mem_init() warn: double check that we're allocating correct size: 4 vs 112

# https://git.kernel.org/pub/scm/linux/kernel/git/lpieralisi/pci.git/commit/?id=ecbae8715e31504a6ca2f596ed5322a78bb971cb
git remote add lpieralisi-pci https://git.kernel.org/pub/scm/linux/kernel/git/lpieralisi/pci.git
git remote update lpieralisi-pci
git checkout ecbae8715e31504a6ca2f596ed5322a78bb971cb
vim +65 drivers/pci/endpoint/pci-epc-mem.c

ecbae8715e31504 Lad Prabhakar          2020-05-07   47  int pci_epc_multi_mem_init(struct pci_epc *epc,
ecbae8715e31504 Lad Prabhakar          2020-05-07   48  			   struct pci_epc_mem_window *windows,
ecbae8715e31504 Lad Prabhakar          2020-05-07   49  			   unsigned int num_windows)
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10   50  {
ecbae8715e31504 Lad Prabhakar          2020-05-07   51  	struct pci_epc_mem *mem = NULL;
ecbae8715e31504 Lad Prabhakar          2020-05-07   52  	unsigned long *bitmap = NULL;
52c9285d47459cf Kishon Vijay Abraham I 2017-08-18   53  	unsigned int page_shift;
ecbae8715e31504 Lad Prabhakar          2020-05-07   54  	size_t page_size;
52c9285d47459cf Kishon Vijay Abraham I 2017-08-18   55  	int bitmap_size;
ecbae8715e31504 Lad Prabhakar          2020-05-07   56  	int pages;
ecbae8715e31504 Lad Prabhakar          2020-05-07   57  	int ret;
ecbae8715e31504 Lad Prabhakar          2020-05-07   58  	int i;
ecbae8715e31504 Lad Prabhakar          2020-05-07   59  
ecbae8715e31504 Lad Prabhakar          2020-05-07   60  	epc->num_windows = 0;
ecbae8715e31504 Lad Prabhakar          2020-05-07   61  
ecbae8715e31504 Lad Prabhakar          2020-05-07   62  	if (!windows || !num_windows)
ecbae8715e31504 Lad Prabhakar          2020-05-07   63  		return -EINVAL;
52c9285d47459cf Kishon Vijay Abraham I 2017-08-18   64  
ecbae8715e31504 Lad Prabhakar          2020-05-07  @65  	epc->windows = kcalloc(num_windows, sizeof(*mem), GFP_KERNEL);
                                                                                                    ^^^^^^^^^^^^
Wrong sizeof().  It should be sizeof(*epc->windows).  I haven't looked
at the size difference but presumably Smatch is correct.

ecbae8715e31504 Lad Prabhakar          2020-05-07   66  	if (!epc->windows)
ecbae8715e31504 Lad Prabhakar          2020-05-07   67  		return -ENOMEM;
ecbae8715e31504 Lad Prabhakar          2020-05-07   68  
ecbae8715e31504 Lad Prabhakar          2020-05-07   69  	for (i = 0; i < num_windows; i++) {
ecbae8715e31504 Lad Prabhakar          2020-05-07   70  		page_size = windows[i].page_size;
52c9285d47459cf Kishon Vijay Abraham I 2017-08-18   71  		if (page_size < PAGE_SIZE)
52c9285d47459cf Kishon Vijay Abraham I 2017-08-18   72  			page_size = PAGE_SIZE;
52c9285d47459cf Kishon Vijay Abraham I 2017-08-18   73  		page_shift = ilog2(page_size);
ecbae8715e31504 Lad Prabhakar          2020-05-07   74  		pages = windows[i].size >> page_shift;
52c9285d47459cf Kishon Vijay Abraham I 2017-08-18   75  		bitmap_size = BITS_TO_LONGS(pages) * sizeof(long);
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10   76  
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10   77  		mem = kzalloc(sizeof(*mem), GFP_KERNEL);
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10   78  		if (!mem) {
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10   79  			ret = -ENOMEM;
ecbae8715e31504 Lad Prabhakar          2020-05-07   80  			i--;
ecbae8715e31504 Lad Prabhakar          2020-05-07   81  			goto err_mem;
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10   82  		}
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10   83  
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10   84  		bitmap = kzalloc(bitmap_size, GFP_KERNEL);
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10   85  		if (!bitmap) {
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10   86  			ret = -ENOMEM;
ecbae8715e31504 Lad Prabhakar          2020-05-07   87  			kfree(mem);
ecbae8715e31504 Lad Prabhakar          2020-05-07   88  			i--;
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10   89  			goto err_mem;
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10   90  		}
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10   91  
ecbae8715e31504 Lad Prabhakar          2020-05-07   92  		mem->window.phys_base = windows[i].phys_base;
ecbae8715e31504 Lad Prabhakar          2020-05-07   93  		mem->window.size = windows[i].size;
ecbae8715e31504 Lad Prabhakar          2020-05-07   94  		mem->window.page_size = page_size;
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10   95  		mem->bitmap = bitmap;
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10   96  		mem->pages = pages;
04e046ca57ebed3 Kishon Vijay Abraham I 2020-02-24   97  		mutex_init(&mem->lock);
ecbae8715e31504 Lad Prabhakar          2020-05-07   98  		epc->windows[i] = mem;
ecbae8715e31504 Lad Prabhakar          2020-05-07   99  	}
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10  100  
ecbae8715e31504 Lad Prabhakar          2020-05-07  101  	epc->mem = epc->windows[0];
ecbae8715e31504 Lad Prabhakar          2020-05-07  102  	epc->num_windows = num_windows;
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10  103  
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10  104  	return 0;
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10  105  
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10  106  err_mem:
ecbae8715e31504 Lad Prabhakar          2020-05-07  107  	for (; i >= 0; i--) {
ecbae8715e31504 Lad Prabhakar          2020-05-07  108  		mem = epc->windows[i];
ecbae8715e31504 Lad Prabhakar          2020-05-07  109  		kfree(mem->bitmap);
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10  110  		kfree(mem);
ecbae8715e31504 Lad Prabhakar          2020-05-07  111  	}
ecbae8715e31504 Lad Prabhakar          2020-05-07  112  	kfree(epc->windows);
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10  113  
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10  114  	return ret;
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10  115  }

---
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] 3+ messages in thread
* [lpieralisi-pci:pci/rcar 8/11] drivers/pci/endpoint/pci-epc-mem.c:65 pci_epc_multi_mem_init() warn: double check that we're allocating correct size: 4 vs 112
@ 2020-05-14  6:43 kbuild test robot
  0 siblings, 0 replies; 3+ messages in thread
From: kbuild test robot @ 2020-05-14  6:43 UTC (permalink / raw)
  To: kbuild

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

CC: kbuild-all(a)lists.01.org
CC: Bjorn Helgaas <helgaas@kernel.org>
TO: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
CC: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
CC: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/lpieralisi/pci.git pci/rcar
head:   3aecbd9786b5e91d7d4819434b20db7dcf71761b
commit: ecbae8715e31504a6ca2f596ed5322a78bb971cb [8/11] PCI: endpoint: Add support to handle multiple base for mapping outbound memory
:::::: branch date: 3 days ago
:::::: commit date: 3 days ago

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

smatch warnings:
drivers/pci/endpoint/pci-epc-mem.c:65 pci_epc_multi_mem_init() warn: double check that we're allocating correct size: 4 vs 112

# https://git.kernel.org/pub/scm/linux/kernel/git/lpieralisi/pci.git/commit/?id=ecbae8715e31504a6ca2f596ed5322a78bb971cb
git remote add lpieralisi-pci https://git.kernel.org/pub/scm/linux/kernel/git/lpieralisi/pci.git
git remote update lpieralisi-pci
git checkout ecbae8715e31504a6ca2f596ed5322a78bb971cb
vim +65 drivers/pci/endpoint/pci-epc-mem.c

52c9285d47459cf Kishon Vijay Abraham I 2017-08-18   37  
52c9285d47459cf Kishon Vijay Abraham I 2017-08-18   38  /**
ecbae8715e31504 Lad Prabhakar          2020-05-07   39   * pci_epc_multi_mem_init() - initialize the pci_epc_mem structure
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10   40   * @epc: the EPC device that invoked pci_epc_mem_init
ecbae8715e31504 Lad Prabhakar          2020-05-07   41   * @windows: pointer to windows supported by the device
ecbae8715e31504 Lad Prabhakar          2020-05-07   42   * @num_windows: number of windows device supports
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10   43   *
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10   44   * Invoke to initialize the pci_epc_mem structure used by the
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10   45   * endpoint functions to allocate mapped PCI address.
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10   46   */
ecbae8715e31504 Lad Prabhakar          2020-05-07   47  int pci_epc_multi_mem_init(struct pci_epc *epc,
ecbae8715e31504 Lad Prabhakar          2020-05-07   48  			   struct pci_epc_mem_window *windows,
ecbae8715e31504 Lad Prabhakar          2020-05-07   49  			   unsigned int num_windows)
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10   50  {
ecbae8715e31504 Lad Prabhakar          2020-05-07   51  	struct pci_epc_mem *mem = NULL;
ecbae8715e31504 Lad Prabhakar          2020-05-07   52  	unsigned long *bitmap = NULL;
52c9285d47459cf Kishon Vijay Abraham I 2017-08-18   53  	unsigned int page_shift;
ecbae8715e31504 Lad Prabhakar          2020-05-07   54  	size_t page_size;
52c9285d47459cf Kishon Vijay Abraham I 2017-08-18   55  	int bitmap_size;
ecbae8715e31504 Lad Prabhakar          2020-05-07   56  	int pages;
ecbae8715e31504 Lad Prabhakar          2020-05-07   57  	int ret;
ecbae8715e31504 Lad Prabhakar          2020-05-07   58  	int i;
ecbae8715e31504 Lad Prabhakar          2020-05-07   59  
ecbae8715e31504 Lad Prabhakar          2020-05-07   60  	epc->num_windows = 0;
ecbae8715e31504 Lad Prabhakar          2020-05-07   61  
ecbae8715e31504 Lad Prabhakar          2020-05-07   62  	if (!windows || !num_windows)
ecbae8715e31504 Lad Prabhakar          2020-05-07   63  		return -EINVAL;
52c9285d47459cf Kishon Vijay Abraham I 2017-08-18   64  
ecbae8715e31504 Lad Prabhakar          2020-05-07  @65  	epc->windows = kcalloc(num_windows, sizeof(*mem), GFP_KERNEL);
ecbae8715e31504 Lad Prabhakar          2020-05-07   66  	if (!epc->windows)
ecbae8715e31504 Lad Prabhakar          2020-05-07   67  		return -ENOMEM;
ecbae8715e31504 Lad Prabhakar          2020-05-07   68  
ecbae8715e31504 Lad Prabhakar          2020-05-07   69  	for (i = 0; i < num_windows; i++) {
ecbae8715e31504 Lad Prabhakar          2020-05-07   70  		page_size = windows[i].page_size;
52c9285d47459cf Kishon Vijay Abraham I 2017-08-18   71  		if (page_size < PAGE_SIZE)
52c9285d47459cf Kishon Vijay Abraham I 2017-08-18   72  			page_size = PAGE_SIZE;
52c9285d47459cf Kishon Vijay Abraham I 2017-08-18   73  		page_shift = ilog2(page_size);
ecbae8715e31504 Lad Prabhakar          2020-05-07   74  		pages = windows[i].size >> page_shift;
52c9285d47459cf Kishon Vijay Abraham I 2017-08-18   75  		bitmap_size = BITS_TO_LONGS(pages) * sizeof(long);
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10   76  
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10   77  		mem = kzalloc(sizeof(*mem), GFP_KERNEL);
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10   78  		if (!mem) {
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10   79  			ret = -ENOMEM;
ecbae8715e31504 Lad Prabhakar          2020-05-07   80  			i--;
ecbae8715e31504 Lad Prabhakar          2020-05-07   81  			goto err_mem;
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10   82  		}
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10   83  
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10   84  		bitmap = kzalloc(bitmap_size, GFP_KERNEL);
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10   85  		if (!bitmap) {
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10   86  			ret = -ENOMEM;
ecbae8715e31504 Lad Prabhakar          2020-05-07   87  			kfree(mem);
ecbae8715e31504 Lad Prabhakar          2020-05-07   88  			i--;
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10   89  			goto err_mem;
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10   90  		}
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10   91  
ecbae8715e31504 Lad Prabhakar          2020-05-07   92  		mem->window.phys_base = windows[i].phys_base;
ecbae8715e31504 Lad Prabhakar          2020-05-07   93  		mem->window.size = windows[i].size;
ecbae8715e31504 Lad Prabhakar          2020-05-07   94  		mem->window.page_size = page_size;
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10   95  		mem->bitmap = bitmap;
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10   96  		mem->pages = pages;
04e046ca57ebed3 Kishon Vijay Abraham I 2020-02-24   97  		mutex_init(&mem->lock);
ecbae8715e31504 Lad Prabhakar          2020-05-07   98  		epc->windows[i] = mem;
ecbae8715e31504 Lad Prabhakar          2020-05-07   99  	}
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10  100  
ecbae8715e31504 Lad Prabhakar          2020-05-07  101  	epc->mem = epc->windows[0];
ecbae8715e31504 Lad Prabhakar          2020-05-07  102  	epc->num_windows = num_windows;
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10  103  
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10  104  	return 0;
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10  105  
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10  106  err_mem:
ecbae8715e31504 Lad Prabhakar          2020-05-07  107  	for (; i >= 0; i--) {
ecbae8715e31504 Lad Prabhakar          2020-05-07  108  		mem = epc->windows[i];
ecbae8715e31504 Lad Prabhakar          2020-05-07  109  		kfree(mem->bitmap);
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10  110  		kfree(mem);
ecbae8715e31504 Lad Prabhakar          2020-05-07  111  	}
ecbae8715e31504 Lad Prabhakar          2020-05-07  112  	kfree(epc->windows);
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10  113  
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10  114  	return ret;
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10  115  }
ecbae8715e31504 Lad Prabhakar          2020-05-07  116  EXPORT_SYMBOL_GPL(pci_epc_multi_mem_init);
5e8cb4033807e39 Kishon Vijay Abraham I 2017-04-10  117  

---
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] 3+ messages in thread

end of thread, other threads:[~2020-05-19 13:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-05-19 13:37 [lpieralisi-pci:pci/rcar 8/11] drivers/pci/endpoint/pci-epc-mem.c:65 pci_epc_multi_mem_init() warn: double check that we're allocating correct size: 4 vs 112 Dan Carpenter
2020-05-19 13:37 ` Dan Carpenter
  -- strict thread matches above, loose matches on Subject: below --
2020-05-14  6:43 kbuild 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.