All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: kbuild@lists.01.org
Subject: [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
Date: Tue, 19 May 2020 16:37:51 +0300	[thread overview]
Message-ID: <20200519133751.GO2078@kadam> (raw)

[-- 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

WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: kbuild-all@lists.01.org
Subject: [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
Date: Tue, 19 May 2020 16:37:51 +0300	[thread overview]
Message-ID: <20200519133751.GO2078@kadam> (raw)

[-- 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

             reply	other threads:[~2020-05-19 13:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-19 13:37 Dan Carpenter [this message]
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
  -- strict thread matches above, loose matches on Subject: below --
2020-05-14  6:43 kbuild test robot

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=20200519133751.GO2078@kadam \
    --to=dan.carpenter@oracle.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.