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(a)intel.com>
Reported-by: Dan Carpenter <dan.carpenter(a)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...
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@lists.01.org