Skip to content

Commit 7ea98e4

Browse files
nmenonUlrich Hecht
authored andcommitted
net: ethernet: ti: netcp: Standardize knav_dma_open_channel to return NULL on error
[ Upstream commit 90a88306eb874fe4bbdd860e6c9787f5bbc588b5 ] Make knav_dma_open_channel consistently return NULL on error instead of ERR_PTR. Currently the header include/linux/soc/ti/knav_dma.h returns NULL when the driver is disabled, but the driver implementation does not even return NULL or ERR_PTR on failure, causing inconsistency in the users. This results in a crash in netcp_free_navigator_resources as followed (trimmed): Unhandled fault: alignment exception (0x221) at 0xfffffff2 [fffffff2] *pgd=80000800207003, *pmd=82ffda003, *pte=00000000 Internal error: : 221 [#1] SMP ARM Modules linked in: CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 6.17.0-rc7 #1 NONE Hardware name: Keystone PC is at knav_dma_close_channel+0x30/0x19c LR is at netcp_free_navigator_resources+0x2c/0x28c [... TRIM...] Call trace: knav_dma_close_channel from netcp_free_navigator_resources+0x2c/0x28c netcp_free_navigator_resources from netcp_ndo_open+0x430/0x46c netcp_ndo_open from __dev_open+0x114/0x29c __dev_open from __dev_change_flags+0x190/0x208 __dev_change_flags from netif_change_flags+0x1c/0x58 netif_change_flags from dev_change_flags+0x38/0xa0 dev_change_flags from ip_auto_config+0x2c4/0x11f0 ip_auto_config from do_one_initcall+0x58/0x200 do_one_initcall from kernel_init_freeable+0x1cc/0x238 kernel_init_freeable from kernel_init+0x1c/0x12c kernel_init from ret_from_fork+0x14/0x38 [... TRIM...] Standardize the error handling by making the function return NULL on all error conditions. The API is used in just the netcp_core.c so the impact is limited. Note, this change, in effect reverts commit 5b6cb43 ("net: ethernet: ti: netcp_core: return error while dma channel open issue"), but provides a less error prone implementation. Suggested-by: Simon Horman <horms@kernel.org> Suggested-by: Jacob Keller <jacob.e.keller@intel.com> Signed-off-by: Nishanth Menon <nm@ti.com> Reviewed-by: Jacob Keller <jacob.e.keller@intel.com> Link: https://patch.msgid.link/20251103162811.3730055-1-nm@ti.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org> [uli: made typo-compatible for 4.19] Signed-off-by: Ulrich Hecht <uli@kernel.org> Reviewed-by: Pavel Machek <pavel@nabladev.com>
1 parent 045cbbb commit 7ea98e4

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

drivers/net/ethernet/ti/netcp_core.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,10 +1353,10 @@ int netcp_txpipe_open(struct netcp_tx_pipe *tx_pipe)
13531353

13541354
tx_pipe->dma_channel = knav_dma_open_channel(dev,
13551355
tx_pipe->dma_chan_name, &config);
1356-
if (IS_ERR(tx_pipe->dma_channel)) {
1356+
if (!tx_pipe->dma_channel) {
13571357
dev_err(dev, "failed opening tx chan(%s)\n",
13581358
tx_pipe->dma_chan_name);
1359-
ret = PTR_ERR(tx_pipe->dma_channel);
1359+
ret = -EINVAL;
13601360
goto err;
13611361
}
13621362

@@ -1374,7 +1374,7 @@ int netcp_txpipe_open(struct netcp_tx_pipe *tx_pipe)
13741374
return 0;
13751375

13761376
err:
1377-
if (!IS_ERR_OR_NULL(tx_pipe->dma_channel))
1377+
if (tx_pipe->dma_channel)
13781378
knav_dma_close_channel(tx_pipe->dma_channel);
13791379
tx_pipe->dma_channel = NULL;
13801380
return ret;
@@ -1693,10 +1693,10 @@ static int netcp_setup_navigator_resources(struct net_device *ndev)
16931693

16941694
netcp->rx_channel = knav_dma_open_channel(netcp->netcp_device->device,
16951695
netcp->dma_chan_name, &config);
1696-
if (IS_ERR(netcp->rx_channel)) {
1696+
if (!netcp->rx_channel) {
16971697
dev_err(netcp->ndev_dev, "failed opening rx chan(%s\n",
16981698
netcp->dma_chan_name);
1699-
ret = PTR_ERR(netcp->rx_channel);
1699+
ret = -EINVAL;
17001700
goto fail;
17011701
}
17021702

drivers/soc/ti/knav_dma.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ static int of_channel_match_helper(struct device_node *np, const char *name,
420420
* @name: slave channel name
421421
* @config: dma configuration parameters
422422
*
423-
* Returns pointer to appropriate DMA channel on success or error.
423+
* Return: Pointer to appropriate DMA channel on success or NULL on error.
424424
*/
425425
void *knav_dma_open_channel(struct device *dev, const char *name,
426426
struct knav_dma_cfg *config)
@@ -433,13 +433,13 @@ void *knav_dma_open_channel(struct device *dev, const char *name,
433433

434434
if (!kdev) {
435435
pr_err("keystone-navigator-dma driver not registered\n");
436-
return (void *)-EINVAL;
436+
return NULL;
437437
}
438438

439439
chan_num = of_channel_match_helper(dev->of_node, name, &instance);
440440
if (chan_num < 0) {
441441
dev_err(kdev->dev, "No DMA instace with name %s\n", name);
442-
return (void *)-EINVAL;
442+
return NULL;
443443
}
444444

445445
dev_dbg(kdev->dev, "initializing %s channel %d from DMA %s\n",
@@ -450,7 +450,7 @@ void *knav_dma_open_channel(struct device *dev, const char *name,
450450
if (config->direction != DMA_MEM_TO_DEV &&
451451
config->direction != DMA_DEV_TO_MEM) {
452452
dev_err(kdev->dev, "bad direction\n");
453-
return (void *)-EINVAL;
453+
return NULL;
454454
}
455455

456456
/* Look for correct dma instance */
@@ -462,7 +462,7 @@ void *knav_dma_open_channel(struct device *dev, const char *name,
462462
}
463463
if (!found) {
464464
dev_err(kdev->dev, "No DMA instace with name %s\n", instance);
465-
return (void *)-EINVAL;
465+
return NULL;
466466
}
467467

468468
/* Look for correct dma channel from dma instance */
@@ -483,14 +483,14 @@ void *knav_dma_open_channel(struct device *dev, const char *name,
483483
if (!found) {
484484
dev_err(kdev->dev, "channel %d is not in DMA %s\n",
485485
chan_num, instance);
486-
return (void *)-EINVAL;
486+
return NULL;
487487
}
488488

489489
if (atomic_read(&chan->ref_count) >= 1) {
490490
if (!check_config(chan, config)) {
491491
dev_err(kdev->dev, "channel %d config miss-match\n",
492492
chan_num);
493-
return (void *)-EINVAL;
493+
return NULL;
494494
}
495495
}
496496

0 commit comments

Comments
 (0)