[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20210326082540.GZ1717@kadam>
Date: Fri, 26 Mar 2021 11:25:40 +0300
From: Dan Carpenter <dan.carpenter@...cle.com>
To: kbuild@...ts.01.org, Peter Ujfalusi <peter.ujfalusi@...com>
Cc: lkp@...el.com, kbuild-all@...ts.01.org,
linux-kernel@...r.kernel.org, Vinod Koul <vkoul@...nel.org>
Subject: drivers/dma/ti/k3-udma.c:4236 bcdma_setup_resources() error:
'rm_res' dereferencing possible ERR_PTR()
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 002322402dafd846c424ffa9240a937f49b48c42
commit: 017794739702d444ca48115ff0fcdce19edb5559 dmaengine: ti: k3-udma: Initial support for K3 BCDMA
config: arm64-randconfig-m031-20210325 (attached as .config)
compiler: aarch64-linux-gcc (GCC) 9.3.0
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@...el.com>
Reported-by: Dan Carpenter <dan.carpenter@...cle.com>
New smatch warnings:
drivers/dma/ti/k3-udma.c:4236 bcdma_setup_resources() error: 'rm_res' dereferencing possible ERR_PTR()
Old smatch warnings:
drivers/dma/ti/k3-udma.c:4113 udma_setup_resources() error: 'rm_res' dereferencing possible ERR_PTR()
drivers/dma/ti/k3-udma.c:4126 udma_setup_resources() error: 'rm_res' dereferencing possible ERR_PTR()
drivers/dma/ti/k3-udma.c:4251 bcdma_setup_resources() error: 'rm_res' dereferencing possible ERR_PTR()
drivers/dma/ti/k3-udma.c:4266 bcdma_setup_resources() error: 'rm_res' dereferencing possible ERR_PTR()
vim +/rm_res +4236 drivers/dma/ti/k3-udma.c
017794739702d4 Peter Ujfalusi 2020-12-08 4170 static int bcdma_setup_resources(struct udma_dev *ud)
017794739702d4 Peter Ujfalusi 2020-12-08 4171 {
017794739702d4 Peter Ujfalusi 2020-12-08 4172 int ret, i, j;
017794739702d4 Peter Ujfalusi 2020-12-08 4173 struct device *dev = ud->dev;
017794739702d4 Peter Ujfalusi 2020-12-08 4174 struct ti_sci_resource *rm_res, irq_res;
017794739702d4 Peter Ujfalusi 2020-12-08 4175 struct udma_tisci_rm *tisci_rm = &ud->tisci_rm;
017794739702d4 Peter Ujfalusi 2020-12-08 4176 const struct udma_oes_offsets *oes = &ud->soc_data->oes;
017794739702d4 Peter Ujfalusi 2020-12-08 4177
017794739702d4 Peter Ujfalusi 2020-12-08 4178 ud->bchan_map = devm_kmalloc_array(dev, BITS_TO_LONGS(ud->bchan_cnt),
017794739702d4 Peter Ujfalusi 2020-12-08 4179 sizeof(unsigned long), GFP_KERNEL);
017794739702d4 Peter Ujfalusi 2020-12-08 4180 ud->bchans = devm_kcalloc(dev, ud->bchan_cnt, sizeof(*ud->bchans),
017794739702d4 Peter Ujfalusi 2020-12-08 4181 GFP_KERNEL);
017794739702d4 Peter Ujfalusi 2020-12-08 4182 ud->tchan_map = devm_kmalloc_array(dev, BITS_TO_LONGS(ud->tchan_cnt),
017794739702d4 Peter Ujfalusi 2020-12-08 4183 sizeof(unsigned long), GFP_KERNEL);
017794739702d4 Peter Ujfalusi 2020-12-08 4184 ud->tchans = devm_kcalloc(dev, ud->tchan_cnt, sizeof(*ud->tchans),
017794739702d4 Peter Ujfalusi 2020-12-08 4185 GFP_KERNEL);
017794739702d4 Peter Ujfalusi 2020-12-08 4186 ud->rchan_map = devm_kmalloc_array(dev, BITS_TO_LONGS(ud->rchan_cnt),
017794739702d4 Peter Ujfalusi 2020-12-08 4187 sizeof(unsigned long), GFP_KERNEL);
017794739702d4 Peter Ujfalusi 2020-12-08 4188 ud->rchans = devm_kcalloc(dev, ud->rchan_cnt, sizeof(*ud->rchans),
017794739702d4 Peter Ujfalusi 2020-12-08 4189 GFP_KERNEL);
017794739702d4 Peter Ujfalusi 2020-12-08 4190 /* BCDMA do not really have flows, but the driver expect it */
017794739702d4 Peter Ujfalusi 2020-12-08 4191 ud->rflow_in_use = devm_kcalloc(dev, BITS_TO_LONGS(ud->rchan_cnt),
017794739702d4 Peter Ujfalusi 2020-12-08 4192 sizeof(unsigned long),
017794739702d4 Peter Ujfalusi 2020-12-08 4193 GFP_KERNEL);
017794739702d4 Peter Ujfalusi 2020-12-08 4194 ud->rflows = devm_kcalloc(dev, ud->rchan_cnt, sizeof(*ud->rflows),
017794739702d4 Peter Ujfalusi 2020-12-08 4195 GFP_KERNEL);
017794739702d4 Peter Ujfalusi 2020-12-08 4196
017794739702d4 Peter Ujfalusi 2020-12-08 4197 if (!ud->bchan_map || !ud->tchan_map || !ud->rchan_map ||
017794739702d4 Peter Ujfalusi 2020-12-08 4198 !ud->rflow_in_use || !ud->bchans || !ud->tchans || !ud->rchans ||
017794739702d4 Peter Ujfalusi 2020-12-08 4199 !ud->rflows)
017794739702d4 Peter Ujfalusi 2020-12-08 4200 return -ENOMEM;
017794739702d4 Peter Ujfalusi 2020-12-08 4201
017794739702d4 Peter Ujfalusi 2020-12-08 4202 /* TPL is not yet supported for BCDMA */
017794739702d4 Peter Ujfalusi 2020-12-08 4203 ud->tpl_levels = 1;
017794739702d4 Peter Ujfalusi 2020-12-08 4204
017794739702d4 Peter Ujfalusi 2020-12-08 4205 /* Get resource ranges from tisci */
017794739702d4 Peter Ujfalusi 2020-12-08 4206 for (i = 0; i < RM_RANGE_LAST; i++) {
017794739702d4 Peter Ujfalusi 2020-12-08 4207 if (i == RM_RANGE_RFLOW)
017794739702d4 Peter Ujfalusi 2020-12-08 4208 continue;
017794739702d4 Peter Ujfalusi 2020-12-08 4209 if (i == RM_RANGE_BCHAN && ud->bchan_cnt == 0)
017794739702d4 Peter Ujfalusi 2020-12-08 4210 continue;
017794739702d4 Peter Ujfalusi 2020-12-08 4211 if (i == RM_RANGE_TCHAN && ud->tchan_cnt == 0)
017794739702d4 Peter Ujfalusi 2020-12-08 4212 continue;
017794739702d4 Peter Ujfalusi 2020-12-08 4213 if (i == RM_RANGE_RCHAN && ud->rchan_cnt == 0)
017794739702d4 Peter Ujfalusi 2020-12-08 4214 continue;
017794739702d4 Peter Ujfalusi 2020-12-08 4215
017794739702d4 Peter Ujfalusi 2020-12-08 4216 tisci_rm->rm_ranges[i] =
017794739702d4 Peter Ujfalusi 2020-12-08 4217 devm_ti_sci_get_of_resource(tisci_rm->tisci, dev,
017794739702d4 Peter Ujfalusi 2020-12-08 4218 tisci_rm->tisci_dev_id,
017794739702d4 Peter Ujfalusi 2020-12-08 4219 (char *)range_names[i]);
017794739702d4 Peter Ujfalusi 2020-12-08 4220 }
017794739702d4 Peter Ujfalusi 2020-12-08 4221
017794739702d4 Peter Ujfalusi 2020-12-08 4222 irq_res.sets = 0;
017794739702d4 Peter Ujfalusi 2020-12-08 4223
017794739702d4 Peter Ujfalusi 2020-12-08 4224 /* bchan ranges */
017794739702d4 Peter Ujfalusi 2020-12-08 4225 if (ud->bchan_cnt) {
017794739702d4 Peter Ujfalusi 2020-12-08 4226 rm_res = tisci_rm->rm_ranges[RM_RANGE_BCHAN];
017794739702d4 Peter Ujfalusi 2020-12-08 4227 if (IS_ERR(rm_res)) {
^^^^^^
This is an error pointer
017794739702d4 Peter Ujfalusi 2020-12-08 4228 bitmap_zero(ud->bchan_map, ud->bchan_cnt);
017794739702d4 Peter Ujfalusi 2020-12-08 4229 } else {
017794739702d4 Peter Ujfalusi 2020-12-08 4230 bitmap_fill(ud->bchan_map, ud->bchan_cnt);
017794739702d4 Peter Ujfalusi 2020-12-08 4231 for (i = 0; i < rm_res->sets; i++)
017794739702d4 Peter Ujfalusi 2020-12-08 4232 udma_mark_resource_ranges(ud, ud->bchan_map,
017794739702d4 Peter Ujfalusi 2020-12-08 4233 &rm_res->desc[i],
017794739702d4 Peter Ujfalusi 2020-12-08 4234 "bchan");
017794739702d4 Peter Ujfalusi 2020-12-08 4235 }
017794739702d4 Peter Ujfalusi 2020-12-08 @4236 irq_res.sets += rm_res->sets;
^^^^^^^^^^^^
Boom. dereference.
017794739702d4 Peter Ujfalusi 2020-12-08 4237 }
017794739702d4 Peter Ujfalusi 2020-12-08 4238
017794739702d4 Peter Ujfalusi 2020-12-08 4239 /* tchan ranges */
017794739702d4 Peter Ujfalusi 2020-12-08 4240 if (ud->tchan_cnt) {
017794739702d4 Peter Ujfalusi 2020-12-08 4241 rm_res = tisci_rm->rm_ranges[RM_RANGE_TCHAN];
017794739702d4 Peter Ujfalusi 2020-12-08 4242 if (IS_ERR(rm_res)) {
017794739702d4 Peter Ujfalusi 2020-12-08 4243 bitmap_zero(ud->tchan_map, ud->tchan_cnt);
017794739702d4 Peter Ujfalusi 2020-12-08 4244 } else {
017794739702d4 Peter Ujfalusi 2020-12-08 4245 bitmap_fill(ud->tchan_map, ud->tchan_cnt);
017794739702d4 Peter Ujfalusi 2020-12-08 4246 for (i = 0; i < rm_res->sets; i++)
017794739702d4 Peter Ujfalusi 2020-12-08 4247 udma_mark_resource_ranges(ud, ud->tchan_map,
017794739702d4 Peter Ujfalusi 2020-12-08 4248 &rm_res->desc[i],
017794739702d4 Peter Ujfalusi 2020-12-08 4249 "tchan");
017794739702d4 Peter Ujfalusi 2020-12-08 4250 }
017794739702d4 Peter Ujfalusi 2020-12-08 4251 irq_res.sets += rm_res->sets * 2;
^^^^^^^^^^^^
017794739702d4 Peter Ujfalusi 2020-12-08 4252 }
017794739702d4 Peter Ujfalusi 2020-12-08 4253
017794739702d4 Peter Ujfalusi 2020-12-08 4254 /* rchan ranges */
017794739702d4 Peter Ujfalusi 2020-12-08 4255 if (ud->rchan_cnt) {
017794739702d4 Peter Ujfalusi 2020-12-08 4256 rm_res = tisci_rm->rm_ranges[RM_RANGE_RCHAN];
017794739702d4 Peter Ujfalusi 2020-12-08 4257 if (IS_ERR(rm_res)) {
017794739702d4 Peter Ujfalusi 2020-12-08 4258 bitmap_zero(ud->rchan_map, ud->rchan_cnt);
017794739702d4 Peter Ujfalusi 2020-12-08 4259 } else {
017794739702d4 Peter Ujfalusi 2020-12-08 4260 bitmap_fill(ud->rchan_map, ud->rchan_cnt);
017794739702d4 Peter Ujfalusi 2020-12-08 4261 for (i = 0; i < rm_res->sets; i++)
017794739702d4 Peter Ujfalusi 2020-12-08 4262 udma_mark_resource_ranges(ud, ud->rchan_map,
017794739702d4 Peter Ujfalusi 2020-12-08 4263 &rm_res->desc[i],
017794739702d4 Peter Ujfalusi 2020-12-08 4264 "rchan");
017794739702d4 Peter Ujfalusi 2020-12-08 4265 }
017794739702d4 Peter Ujfalusi 2020-12-08 4266 irq_res.sets += rm_res->sets * 2;
017794739702d4 Peter Ujfalusi 2020-12-08 4267 }
017794739702d4 Peter Ujfalusi 2020-12-08 4268
017794739702d4 Peter Ujfalusi 2020-12-08 4269 irq_res.desc = kcalloc(irq_res.sets, sizeof(*irq_res.desc), GFP_KERNEL);
017794739702d4 Peter Ujfalusi 2020-12-08 4270 if (ud->bchan_cnt) {
017794739702d4 Peter Ujfalusi 2020-12-08 4271 rm_res = tisci_rm->rm_ranges[RM_RANGE_BCHAN];
017794739702d4 Peter Ujfalusi 2020-12-08 4272 for (i = 0; i < rm_res->sets; i++) {
017794739702d4 Peter Ujfalusi 2020-12-08 4273 irq_res.desc[i].start = rm_res->desc[i].start +
017794739702d4 Peter Ujfalusi 2020-12-08 4274 oes->bcdma_bchan_ring;
017794739702d4 Peter Ujfalusi 2020-12-08 4275 irq_res.desc[i].num = rm_res->desc[i].num;
017794739702d4 Peter Ujfalusi 2020-12-08 4276 }
017794739702d4 Peter Ujfalusi 2020-12-08 4277 }
017794739702d4 Peter Ujfalusi 2020-12-08 4278 if (ud->tchan_cnt) {
017794739702d4 Peter Ujfalusi 2020-12-08 4279 rm_res = tisci_rm->rm_ranges[RM_RANGE_TCHAN];
017794739702d4 Peter Ujfalusi 2020-12-08 4280 for (j = 0; j < rm_res->sets; j++, i += 2) {
017794739702d4 Peter Ujfalusi 2020-12-08 4281 irq_res.desc[i].start = rm_res->desc[j].start +
017794739702d4 Peter Ujfalusi 2020-12-08 4282 oes->bcdma_tchan_data;
017794739702d4 Peter Ujfalusi 2020-12-08 4283 irq_res.desc[i].num = rm_res->desc[j].num;
017794739702d4 Peter Ujfalusi 2020-12-08 4284
017794739702d4 Peter Ujfalusi 2020-12-08 4285 irq_res.desc[i + 1].start = rm_res->desc[j].start +
017794739702d4 Peter Ujfalusi 2020-12-08 4286 oes->bcdma_tchan_ring;
017794739702d4 Peter Ujfalusi 2020-12-08 4287 irq_res.desc[i + 1].num = rm_res->desc[j].num;
017794739702d4 Peter Ujfalusi 2020-12-08 4288 }
017794739702d4 Peter Ujfalusi 2020-12-08 4289 }
017794739702d4 Peter Ujfalusi 2020-12-08 4290 if (ud->rchan_cnt) {
017794739702d4 Peter Ujfalusi 2020-12-08 4291 rm_res = tisci_rm->rm_ranges[RM_RANGE_RCHAN];
017794739702d4 Peter Ujfalusi 2020-12-08 4292 for (j = 0; j < rm_res->sets; j++, i += 2) {
017794739702d4 Peter Ujfalusi 2020-12-08 4293 irq_res.desc[i].start = rm_res->desc[j].start +
017794739702d4 Peter Ujfalusi 2020-12-08 4294 oes->bcdma_rchan_data;
017794739702d4 Peter Ujfalusi 2020-12-08 4295 irq_res.desc[i].num = rm_res->desc[j].num;
017794739702d4 Peter Ujfalusi 2020-12-08 4296
017794739702d4 Peter Ujfalusi 2020-12-08 4297 irq_res.desc[i + 1].start = rm_res->desc[j].start +
017794739702d4 Peter Ujfalusi 2020-12-08 4298 oes->bcdma_rchan_ring;
017794739702d4 Peter Ujfalusi 2020-12-08 4299 irq_res.desc[i + 1].num = rm_res->desc[j].num;
017794739702d4 Peter Ujfalusi 2020-12-08 4300 }
017794739702d4 Peter Ujfalusi 2020-12-08 4301 }
017794739702d4 Peter Ujfalusi 2020-12-08 4302
017794739702d4 Peter Ujfalusi 2020-12-08 4303 ret = ti_sci_inta_msi_domain_alloc_irqs(ud->dev, &irq_res);
017794739702d4 Peter Ujfalusi 2020-12-08 4304 kfree(irq_res.desc);
017794739702d4 Peter Ujfalusi 2020-12-08 4305 if (ret) {
017794739702d4 Peter Ujfalusi 2020-12-08 4306 dev_err(ud->dev, "Failed to allocate MSI interrupts\n");
017794739702d4 Peter Ujfalusi 2020-12-08 4307 return ret;
017794739702d4 Peter Ujfalusi 2020-12-08 4308 }
017794739702d4 Peter Ujfalusi 2020-12-08 4309
017794739702d4 Peter Ujfalusi 2020-12-08 4310 return 0;
017794739702d4 Peter Ujfalusi 2020-12-08 4311 }
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Download attachment ".config.gz" of type "application/gzip" (39816 bytes)
Powered by blists - more mailing lists