* [PATCH V3] net: ethernet: ti: netcp: Standardize knav_dma_open_channel to return NULL on error
@ 2025-10-29 13:23 Nishanth Menon
2025-10-29 20:07 ` Jacob Keller
2025-10-29 20:07 ` Jacob Keller
0 siblings, 2 replies; 3+ messages in thread
From: Nishanth Menon @ 2025-10-29 13:23 UTC (permalink / raw)
To: Jakub Kicinski, pabeni@redhat.com, David S. Miller
Cc: Jacob Keller, Simon Horman, Uwe Kleine-König, Eric Dumazet,
Andrew Lunn, Santosh Shilimkar, Siddharth Vadapalli,
linux-arm-kernel, linux-kernel, netdev, Nishanth Menon
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 5b6cb43b4d62 ("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>
---
Changes since V2:
* All patches squashed to a single patch
* Updated commit message
* rebased to next-20251029
V2: https://lore.kernel.org/linux-arm-kernel/20250930121609.158419-1-nm@ti.com/
V1: https://lore.kernel.org/all/20250926150853.2907028-1-nm@ti.com/
Crash seen: https://dashboard.kernelci.org/log-viewer?itemId=ti%3A2eb55ed935eb42c292e02f59&org=ti&type=test&url=http%3A%2F%2Ffiles.kernelci.org%2F%2Fti%2Fmainline%2Fmaster%2Fv6.17-rc7-59-gbf40f4b87761%2Farm%2Fmulti_v7_defconfig%2BCONFIG_EFI%3Dy%2BCONFIG_ARM_LPAE%3Dy%2Bdebug%2Bkselftest%2Btinyconfig%2Fgcc-12%2Fbaseline-nfs-boot.nfs-k2hk-evm.txt.gz
drivers/net/ethernet/ti/netcp_core.c | 10 +++++-----
drivers/soc/ti/knav_dma.c | 14 +++++++-------
2 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/drivers/net/ethernet/ti/netcp_core.c b/drivers/net/ethernet/ti/netcp_core.c
index 857820657bac..5ee13db568f0 100644
--- a/drivers/net/ethernet/ti/netcp_core.c
+++ b/drivers/net/ethernet/ti/netcp_core.c
@@ -1338,10 +1338,10 @@ int netcp_txpipe_open(struct netcp_tx_pipe *tx_pipe)
tx_pipe->dma_channel = knav_dma_open_channel(dev,
tx_pipe->dma_chan_name, &config);
- if (IS_ERR(tx_pipe->dma_channel)) {
+ if (!tx_pipe->dma_channel) {
dev_err(dev, "failed opening tx chan(%s)\n",
tx_pipe->dma_chan_name);
- ret = PTR_ERR(tx_pipe->dma_channel);
+ ret = -EINVAL;
goto err;
}
@@ -1359,7 +1359,7 @@ int netcp_txpipe_open(struct netcp_tx_pipe *tx_pipe)
return 0;
err:
- if (!IS_ERR_OR_NULL(tx_pipe->dma_channel))
+ if (tx_pipe->dma_channel)
knav_dma_close_channel(tx_pipe->dma_channel);
tx_pipe->dma_channel = NULL;
return ret;
@@ -1678,10 +1678,10 @@ static int netcp_setup_navigator_resources(struct net_device *ndev)
netcp->rx_channel = knav_dma_open_channel(netcp->netcp_device->device,
netcp->dma_chan_name, &config);
- if (IS_ERR(netcp->rx_channel)) {
+ if (!netcp->rx_channel) {
dev_err(netcp->ndev_dev, "failed opening rx chan(%s\n",
netcp->dma_chan_name);
- ret = PTR_ERR(netcp->rx_channel);
+ ret = -EINVAL;
goto fail;
}
diff --git a/drivers/soc/ti/knav_dma.c b/drivers/soc/ti/knav_dma.c
index a25ebe6cd503..e69f0946de29 100644
--- a/drivers/soc/ti/knav_dma.c
+++ b/drivers/soc/ti/knav_dma.c
@@ -402,7 +402,7 @@ static int of_channel_match_helper(struct device_node *np, const char *name,
* @name: slave channel name
* @config: dma configuration parameters
*
- * Returns pointer to appropriate DMA channel on success or error.
+ * Returns pointer to appropriate DMA channel on success or NULL on error.
*/
void *knav_dma_open_channel(struct device *dev, const char *name,
struct knav_dma_cfg *config)
@@ -414,13 +414,13 @@ void *knav_dma_open_channel(struct device *dev, const char *name,
if (!kdev) {
pr_err("keystone-navigator-dma driver not registered\n");
- return (void *)-EINVAL;
+ return NULL;
}
chan_num = of_channel_match_helper(dev->of_node, name, &instance);
if (chan_num < 0) {
dev_err(kdev->dev, "No DMA instance with name %s\n", name);
- return (void *)-EINVAL;
+ return NULL;
}
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,
if (config->direction != DMA_MEM_TO_DEV &&
config->direction != DMA_DEV_TO_MEM) {
dev_err(kdev->dev, "bad direction\n");
- return (void *)-EINVAL;
+ return NULL;
}
/* Look for correct dma instance */
@@ -443,7 +443,7 @@ void *knav_dma_open_channel(struct device *dev, const char *name,
}
if (!dma) {
dev_err(kdev->dev, "No DMA instance with name %s\n", instance);
- return (void *)-EINVAL;
+ return NULL;
}
/* Look for correct dma channel from dma instance */
@@ -463,14 +463,14 @@ void *knav_dma_open_channel(struct device *dev, const char *name,
if (!chan) {
dev_err(kdev->dev, "channel %d is not in DMA %s\n",
chan_num, instance);
- return (void *)-EINVAL;
+ return NULL;
}
if (atomic_read(&chan->ref_count) >= 1) {
if (!check_config(chan, config)) {
dev_err(kdev->dev, "channel %d config miss-match\n",
chan_num);
- return (void *)-EINVAL;
+ return NULL;
}
}
--
2.47.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH V3] net: ethernet: ti: netcp: Standardize knav_dma_open_channel to return NULL on error
2025-10-29 13:23 [PATCH V3] net: ethernet: ti: netcp: Standardize knav_dma_open_channel to return NULL on error Nishanth Menon
@ 2025-10-29 20:07 ` Jacob Keller
2025-10-29 20:07 ` Jacob Keller
1 sibling, 0 replies; 3+ messages in thread
From: Jacob Keller @ 2025-10-29 20:07 UTC (permalink / raw)
To: Nishanth Menon, Jakub Kicinski, pabeni@redhat.com,
David S. Miller
Cc: Simon Horman, Uwe Kleine-König, Eric Dumazet, Andrew Lunn,
Santosh Shilimkar, Siddharth Vadapalli, linux-arm-kernel,
linux-kernel, netdev
[-- Attachment #1.1: Type: text/plain, Size: 2524 bytes --]
On 10/29/2025 6:23 AM, Nishanth Menon wrote:
> diff --git a/drivers/soc/ti/knav_dma.c b/drivers/soc/ti/knav_dma.c
> index a25ebe6cd503..e69f0946de29 100644
> --- a/drivers/soc/ti/knav_dma.c
> +++ b/drivers/soc/ti/knav_dma.c
> @@ -402,7 +402,7 @@ static int of_channel_match_helper(struct device_node *np, const char *name,
> * @name: slave channel name
> * @config: dma configuration parameters
> *
> - * Returns pointer to appropriate DMA channel on success or error.
> + * Returns pointer to appropriate DMA channel on success or NULL on error.
> */
> void *knav_dma_open_channel(struct device *dev, const char *name,
> struct knav_dma_cfg *config)
> @@ -414,13 +414,13 @@ void *knav_dma_open_channel(struct device *dev, const char *name,
>
> if (!kdev) {
> pr_err("keystone-navigator-dma driver not registered\n");
> - return (void *)-EINVAL;
> + return NULL;
> }
>
> chan_num = of_channel_match_helper(dev->of_node, name, &instance);
> if (chan_num < 0) {
> dev_err(kdev->dev, "No DMA instance with name %s\n", name);
> - return (void *)-EINVAL;
> + return NULL;
> }
>
> 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,
> if (config->direction != DMA_MEM_TO_DEV &&
> config->direction != DMA_DEV_TO_MEM) {
> dev_err(kdev->dev, "bad direction\n");
> - return (void *)-EINVAL;
> + return NULL;
> }
>
> /* Look for correct dma instance */
> @@ -443,7 +443,7 @@ void *knav_dma_open_channel(struct device *dev, const char *name,
> }
> if (!dma) {
> dev_err(kdev->dev, "No DMA instance with name %s\n", instance);
> - return (void *)-EINVAL;
> + return NULL;
> }
>
> /* Look for correct dma channel from dma instance */
> @@ -463,14 +463,14 @@ void *knav_dma_open_channel(struct device *dev, const char *name,
> if (!chan) {
> dev_err(kdev->dev, "channel %d is not in DMA %s\n",
> chan_num, instance);
> - return (void *)-EINVAL;
> + return NULL;
> }
>
> if (atomic_read(&chan->ref_count) >= 1) {
> if (!check_config(chan, config)) {
> dev_err(kdev->dev, "channel %d config miss-match\n",
> chan_num);
> - return (void *)-EINVAL;
> + return NULL;
> }
> }
>
Since we were basically always returning -EINVAL that seems reasonable
to just switch to NULL instead.
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Thanks,
Jake
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH V3] net: ethernet: ti: netcp: Standardize knav_dma_open_channel to return NULL on error
2025-10-29 13:23 [PATCH V3] net: ethernet: ti: netcp: Standardize knav_dma_open_channel to return NULL on error Nishanth Menon
2025-10-29 20:07 ` Jacob Keller
@ 2025-10-29 20:07 ` Jacob Keller
1 sibling, 0 replies; 3+ messages in thread
From: Jacob Keller @ 2025-10-29 20:07 UTC (permalink / raw)
To: Nishanth Menon, Jakub Kicinski, pabeni@redhat.com,
David S. Miller
Cc: Simon Horman, Uwe Kleine-König, Eric Dumazet, Andrew Lunn,
Santosh Shilimkar, Siddharth Vadapalli, linux-arm-kernel,
linux-kernel, netdev
[-- Attachment #1.1: Type: text/plain, Size: 767 bytes --]
On 10/29/2025 6:23 AM, Nishanth Menon wrote:
> diff --git a/drivers/soc/ti/knav_dma.c b/drivers/soc/ti/knav_dma.c
> index a25ebe6cd503..e69f0946de29 100644
> --- a/drivers/soc/ti/knav_dma.c
> +++ b/drivers/soc/ti/knav_dma.c
> @@ -402,7 +402,7 @@ static int of_channel_match_helper(struct device_node *np, const char *name,
> * @name: slave channel name
> * @config: dma configuration parameters
> *
> - * Returns pointer to appropriate DMA channel on success or error.
> + * Returns pointer to appropriate DMA channel on success or NULL on error.
> */
Minor nit: you could make this a proper kdoc returns by using "Return:"
or "Returns:" here to introduce this as a section instead of just a comment.
That would fix a kdoc warning too.
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-10-29 20:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-29 13:23 [PATCH V3] net: ethernet: ti: netcp: Standardize knav_dma_open_channel to return NULL on error Nishanth Menon
2025-10-29 20:07 ` Jacob Keller
2025-10-29 20:07 ` Jacob Keller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).