* [asahilinux:bits/090-spi-hid 18/22] drivers/soc/apple/rtkit-helper.c:46 apple_rtkit_helper_shmem_setup() warn: variable dereferenced before check 'helper->sram' (see line 35)
@ 2022-09-19 8:47 Dan Carpenter
0 siblings, 0 replies; only message in thread
From: Dan Carpenter @ 2022-09-19 8:47 UTC (permalink / raw)
To: kbuild, Hector Martin; +Cc: lkp, kbuild-all, linux-kernel
tree: https://github.com/AsahiLinux/linux bits/090-spi-hid
head: ecf1fb81499a2f1724cb90497ca3c1cec831c9b6
commit: 51f1f2b38adcb95f2e04665ae54fe99ba6bd7844 [18/22] soc: apple: Add RTKit helper driver
config: arm-randconfig-m041-20220918
compiler: arm-linux-gnueabi-gcc (GCC) 12.1.0
If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
smatch warnings:
drivers/soc/apple/rtkit-helper.c:46 apple_rtkit_helper_shmem_setup() warn: variable dereferenced before check 'helper->sram' (see line 35)
vim +46 drivers/soc/apple/rtkit-helper.c
51f1f2b38adcb9 Hector Martin 2022-07-03 28 static int apple_rtkit_helper_shmem_setup(void *cookie, struct apple_rtkit_shmem *bfr)
51f1f2b38adcb9 Hector Martin 2022-07-03 29 {
51f1f2b38adcb9 Hector Martin 2022-07-03 30 struct apple_rtkit_helper *helper = cookie;
51f1f2b38adcb9 Hector Martin 2022-07-03 31 struct resource res = {
51f1f2b38adcb9 Hector Martin 2022-07-03 32 .start = bfr->iova,
51f1f2b38adcb9 Hector Martin 2022-07-03 33 .end = bfr->iova + bfr->size - 1,
51f1f2b38adcb9 Hector Martin 2022-07-03 34 .name = "rtkit_map",
51f1f2b38adcb9 Hector Martin 2022-07-03 @35 .flags = helper->sram->flags,
^^^^^^^^^^^^^
Dereference
51f1f2b38adcb9 Hector Martin 2022-07-03 36 };
51f1f2b38adcb9 Hector Martin 2022-07-03 37
51f1f2b38adcb9 Hector Martin 2022-07-03 38 if (!bfr->iova) {
51f1f2b38adcb9 Hector Martin 2022-07-03 39 bfr->buffer = dma_alloc_coherent(helper->dev, bfr->size,
51f1f2b38adcb9 Hector Martin 2022-07-03 40 &bfr->iova, GFP_KERNEL);
51f1f2b38adcb9 Hector Martin 2022-07-03 41 if (!bfr->buffer)
51f1f2b38adcb9 Hector Martin 2022-07-03 42 return -ENOMEM;
51f1f2b38adcb9 Hector Martin 2022-07-03 43 return 0;
51f1f2b38adcb9 Hector Martin 2022-07-03 44 }
51f1f2b38adcb9 Hector Martin 2022-07-03 45
51f1f2b38adcb9 Hector Martin 2022-07-03 @46 if (!helper->sram) {
^^^^^^^^^^^^
Checked too late.
51f1f2b38adcb9 Hector Martin 2022-07-03 47 dev_err(helper->dev,
51f1f2b38adcb9 Hector Martin 2022-07-03 48 "RTKit buffer request with no SRAM region: %pR", &res);
51f1f2b38adcb9 Hector Martin 2022-07-03 49 return -EFAULT;
51f1f2b38adcb9 Hector Martin 2022-07-03 50 }
51f1f2b38adcb9 Hector Martin 2022-07-03 51
51f1f2b38adcb9 Hector Martin 2022-07-03 52 if (res.end < res.start || !resource_contains(helper->sram, &res)) {
51f1f2b38adcb9 Hector Martin 2022-07-03 53 dev_err(helper->dev,
51f1f2b38adcb9 Hector Martin 2022-07-03 54 "RTKit buffer request outside SRAM region: %pR", &res);
51f1f2b38adcb9 Hector Martin 2022-07-03 55 return -EFAULT;
51f1f2b38adcb9 Hector Martin 2022-07-03 56 }
51f1f2b38adcb9 Hector Martin 2022-07-03 57
51f1f2b38adcb9 Hector Martin 2022-07-03 58 bfr->iomem = helper->sram_base + (res.start - helper->sram->start);
51f1f2b38adcb9 Hector Martin 2022-07-03 59 bfr->is_mapped = true;
51f1f2b38adcb9 Hector Martin 2022-07-03 60
51f1f2b38adcb9 Hector Martin 2022-07-03 61 return 0;
51f1f2b38adcb9 Hector Martin 2022-07-03 62 }
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-09-19 8:48 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-19 8:47 [asahilinux:bits/090-spi-hid 18/22] drivers/soc/apple/rtkit-helper.c:46 apple_rtkit_helper_shmem_setup() warn: variable dereferenced before check 'helper->sram' (see line 35) Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®