Skip to content

Commit 90a8830

Browse files
nmenonkuba-moo
authored andcommitted
net: ethernet: ti: netcp: Standardize knav_dma_open_channel to return NULL on error
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 <[email protected]> Suggested-by: Jacob Keller <[email protected]> Signed-off-by: Nishanth Menon <[email protected]> Reviewed-by: Jacob Keller <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 0c71670 commit 90a8830

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

drivers/net/ethernet/ti/netcp_core.c

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

13391339
tx_pipe->dma_channel = knav_dma_open_channel(dev,
13401340
tx_pipe->dma_chan_name, &config);
1341-
if (IS_ERR(tx_pipe->dma_channel)) {
1341+
if (!tx_pipe->dma_channel) {
13421342
dev_err(dev, "failed opening tx chan(%s)\n",
13431343
tx_pipe->dma_chan_name);
1344-
ret = PTR_ERR(tx_pipe->dma_channel);
1344+
ret = -EINVAL;
13451345
goto err;
13461346
}
13471347

@@ -1359,7 +1359,7 @@ int netcp_txpipe_open(struct netcp_tx_pipe *tx_pipe)
13591359
return 0;
13601360

13611361
err:
1362-
if (!IS_ERR_OR_NULL(tx_pipe->dma_channel))
1362+
if (tx_pipe->dma_channel)
13631363
knav_dma_close_channel(tx_pipe->dma_channel);
13641364
tx_pipe->dma_channel = NULL;
13651365
return ret;
@@ -1678,10 +1678,10 @@ static int netcp_setup_navigator_resources(struct net_device *ndev)
16781678

16791679
netcp->rx_channel = knav_dma_open_channel(netcp->netcp_device->device,
16801680
netcp->dma_chan_name, &config);
1681-
if (IS_ERR(netcp->rx_channel)) {
1681+
if (!netcp->rx_channel) {
16821682
dev_err(netcp->ndev_dev, "failed opening rx chan(%s\n",
16831683
netcp->dma_chan_name);
1684-
ret = PTR_ERR(netcp->rx_channel);
1684+
ret = -EINVAL;
16851685
goto fail;
16861686
}
16871687

drivers/soc/ti/knav_dma.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ static int of_channel_match_helper(struct device_node *np, const char *name,
402402
* @name: slave channel name
403403
* @config: dma configuration parameters
404404
*
405-
* Returns pointer to appropriate DMA channel on success or error.
405+
* Return: Pointer to appropriate DMA channel on success or NULL on error.
406406
*/
407407
void *knav_dma_open_channel(struct device *dev, const char *name,
408408
struct knav_dma_cfg *config)
@@ -414,13 +414,13 @@ void *knav_dma_open_channel(struct device *dev, const char *name,
414414

415415
if (!kdev) {
416416
pr_err("keystone-navigator-dma driver not registered\n");
417-
return (void *)-EINVAL;
417+
return NULL;
418418
}
419419

420420
chan_num = of_channel_match_helper(dev->of_node, name, &instance);
421421
if (chan_num < 0) {
422422
dev_err(kdev->dev, "No DMA instance with name %s\n", name);
423-
return (void *)-EINVAL;
423+
return NULL;
424424
}
425425

426426
dev_dbg(kdev->dev, "initializing %s channel %d from DMA %s\n",
@@ -431,7 +431,7 @@ void *knav_dma_open_channel(struct device *dev, const char *name,
431431
if (config->direction != DMA_MEM_TO_DEV &&
432432
config->direction != DMA_DEV_TO_MEM) {
433433
dev_err(kdev->dev, "bad direction\n");
434-
return (void *)-EINVAL;
434+
return NULL;
435435
}
436436

437437
/* Look for correct dma instance */
@@ -443,7 +443,7 @@ void *knav_dma_open_channel(struct device *dev, const char *name,
443443
}
444444
if (!dma) {
445445
dev_err(kdev->dev, "No DMA instance with name %s\n", instance);
446-
return (void *)-EINVAL;
446+
return NULL;
447447
}
448448

449449
/* Look for correct dma channel from dma instance */
@@ -463,14 +463,14 @@ void *knav_dma_open_channel(struct device *dev, const char *name,
463463
if (!chan) {
464464
dev_err(kdev->dev, "channel %d is not in DMA %s\n",
465465
chan_num, instance);
466-
return (void *)-EINVAL;
466+
return NULL;
467467
}
468468

469469
if (atomic_read(&chan->ref_count) >= 1) {
470470
if (!check_config(chan, config)) {
471471
dev_err(kdev->dev, "channel %d config miss-match\n",
472472
chan_num);
473-
return (void *)-EINVAL;
473+
return NULL;
474474
}
475475
}
476476

0 commit comments

Comments
 (0)