* [PATCH next] mtd: rawnand: loongson1: Fix error code in ls1x_nand_dma_transfer()
@ 2025-05-02 8:39 Dan Carpenter
2025-05-06 9:16 ` Keguang Zhang
2025-05-12 14:29 ` Miquel Raynal
0 siblings, 2 replies; 7+ messages in thread
From: Dan Carpenter @ 2025-05-02 8:39 UTC (permalink / raw)
To: Keguang Zhang
Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
linux-mips, linux-mtd, linux-kernel, kernel-janitors
The "desc" variable is NULL and PTR_ERR(NULL) is zero/success. Return
a negative error code instead.
Fixes: d2d10ede04b1 ("mtd: rawnand: Add Loongson-1 NAND Controller Driver")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
It's hard to know what the patch prefix should be here. Ideally when we
add a new driver we would use the patch prefix for the driver.
Tired: subsystem: Add driver XXX
Wired: subsystem: XXX: Add driver for XXX
drivers/mtd/nand/raw/loongson1-nand-controller.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/mtd/nand/raw/loongson1-nand-controller.c b/drivers/mtd/nand/raw/loongson1-nand-controller.c
index 6a369b1c7d86..8754bb4f8b56 100644
--- a/drivers/mtd/nand/raw/loongson1-nand-controller.c
+++ b/drivers/mtd/nand/raw/loongson1-nand-controller.c
@@ -371,7 +371,7 @@ static int ls1x_nand_dma_transfer(struct ls1x_nand_host *host, struct ls1x_nand_
desc = dmaengine_prep_slave_single(chan, dma_addr, op->len, xfer_dir, DMA_PREP_INTERRUPT);
if (!desc) {
dev_err(dev, "failed to prepare DMA descriptor\n");
- ret = PTR_ERR(desc);
+ ret = -ENOMEM;
goto err;
}
desc->callback = ls1x_nand_dma_callback;
--
2.47.2
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH next] mtd: rawnand: loongson1: Fix error code in ls1x_nand_dma_transfer() 2025-05-02 8:39 [PATCH next] mtd: rawnand: loongson1: Fix error code in ls1x_nand_dma_transfer() Dan Carpenter @ 2025-05-06 9:16 ` Keguang Zhang 2025-05-06 9:32 ` Dan Carpenter 2025-05-12 14:29 ` Miquel Raynal 1 sibling, 1 reply; 7+ messages in thread From: Keguang Zhang @ 2025-05-06 9:16 UTC (permalink / raw) To: Dan Carpenter Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra, linux-mips, linux-mtd, linux-kernel, kernel-janitors On Fri, May 2, 2025 at 4:39 PM Dan Carpenter <dan.carpenter@linaro.org> wrote: > > The "desc" variable is NULL and PTR_ERR(NULL) is zero/success. Return > a negative error code instead. > > Fixes: d2d10ede04b1 ("mtd: rawnand: Add Loongson-1 NAND Controller Driver") > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> > --- > It's hard to know what the patch prefix should be here. Ideally when we > add a new driver we would use the patch prefix for the driver. > > Tired: subsystem: Add driver XXX > Wired: subsystem: XXX: Add driver for XXX > > drivers/mtd/nand/raw/loongson1-nand-controller.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/mtd/nand/raw/loongson1-nand-controller.c b/drivers/mtd/nand/raw/loongson1-nand-controller.c > index 6a369b1c7d86..8754bb4f8b56 100644 > --- a/drivers/mtd/nand/raw/loongson1-nand-controller.c > +++ b/drivers/mtd/nand/raw/loongson1-nand-controller.c > @@ -371,7 +371,7 @@ static int ls1x_nand_dma_transfer(struct ls1x_nand_host *host, struct ls1x_nand_ > desc = dmaengine_prep_slave_single(chan, dma_addr, op->len, xfer_dir, DMA_PREP_INTERRUPT); > if (!desc) { > dev_err(dev, "failed to prepare DMA descriptor\n"); > - ret = PTR_ERR(desc); > + ret = -ENOMEM; Thank you for fixing this issue. However, I believe -EIO is more appropriate than -ENOMEM, since dmaengine_prep_slave_single() can return errors other than -ENOMEM. > goto err; > } > desc->callback = ls1x_nand_dma_callback; > -- > 2.47.2 > -- Best regards, Keguang Zhang ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH next] mtd: rawnand: loongson1: Fix error code in ls1x_nand_dma_transfer() 2025-05-06 9:16 ` Keguang Zhang @ 2025-05-06 9:32 ` Dan Carpenter 2025-05-06 10:01 ` Keguang Zhang 0 siblings, 1 reply; 7+ messages in thread From: Dan Carpenter @ 2025-05-06 9:32 UTC (permalink / raw) To: Keguang Zhang Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra, linux-mips, linux-mtd, linux-kernel, kernel-janitors On Tue, May 06, 2025 at 05:16:03PM +0800, Keguang Zhang wrote: > On Fri, May 2, 2025 at 4:39 PM Dan Carpenter <dan.carpenter@linaro.org> wrote: > > > > The "desc" variable is NULL and PTR_ERR(NULL) is zero/success. Return > > a negative error code instead. > > > > Fixes: d2d10ede04b1 ("mtd: rawnand: Add Loongson-1 NAND Controller Driver") > > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> > > --- > > It's hard to know what the patch prefix should be here. Ideally when we > > add a new driver we would use the patch prefix for the driver. > > > > Tired: subsystem: Add driver XXX > > Wired: subsystem: XXX: Add driver for XXX > > > > drivers/mtd/nand/raw/loongson1-nand-controller.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/mtd/nand/raw/loongson1-nand-controller.c b/drivers/mtd/nand/raw/loongson1-nand-controller.c > > index 6a369b1c7d86..8754bb4f8b56 100644 > > --- a/drivers/mtd/nand/raw/loongson1-nand-controller.c > > +++ b/drivers/mtd/nand/raw/loongson1-nand-controller.c > > @@ -371,7 +371,7 @@ static int ls1x_nand_dma_transfer(struct ls1x_nand_host *host, struct ls1x_nand_ > > desc = dmaengine_prep_slave_single(chan, dma_addr, op->len, xfer_dir, DMA_PREP_INTERRUPT); > > if (!desc) { > > dev_err(dev, "failed to prepare DMA descriptor\n"); > > - ret = PTR_ERR(desc); > > + ret = -ENOMEM; > > Thank you for fixing this issue. > However, I believe -EIO is more appropriate than -ENOMEM, since > dmaengine_prep_slave_single() can return errors other than -ENOMEM. > It's not an I/O error so -EIO isn't correct. There are a bunch of reasons it could fail but most likely dma_pool_alloc() failed. I think -ENOMEM is correct. regards, dan carpenter ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH next] mtd: rawnand: loongson1: Fix error code in ls1x_nand_dma_transfer() 2025-05-06 9:32 ` Dan Carpenter @ 2025-05-06 10:01 ` Keguang Zhang 2025-05-06 11:15 ` Dan Carpenter 0 siblings, 1 reply; 7+ messages in thread From: Keguang Zhang @ 2025-05-06 10:01 UTC (permalink / raw) To: Dan Carpenter Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra, linux-mips, linux-mtd, linux-kernel, kernel-janitors On Tue, May 6, 2025 at 5:32 PM Dan Carpenter <dan.carpenter@linaro.org> wrote: > > On Tue, May 06, 2025 at 05:16:03PM +0800, Keguang Zhang wrote: > > On Fri, May 2, 2025 at 4:39 PM Dan Carpenter <dan.carpenter@linaro.org> wrote: > > > > > > The "desc" variable is NULL and PTR_ERR(NULL) is zero/success. Return > > > a negative error code instead. > > > > > > Fixes: d2d10ede04b1 ("mtd: rawnand: Add Loongson-1 NAND Controller Driver") > > > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> > > > --- > > > It's hard to know what the patch prefix should be here. Ideally when we > > > add a new driver we would use the patch prefix for the driver. > > > > > > Tired: subsystem: Add driver XXX > > > Wired: subsystem: XXX: Add driver for XXX > > > > > > drivers/mtd/nand/raw/loongson1-nand-controller.c | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > diff --git a/drivers/mtd/nand/raw/loongson1-nand-controller.c b/drivers/mtd/nand/raw/loongson1-nand-controller.c > > > index 6a369b1c7d86..8754bb4f8b56 100644 > > > --- a/drivers/mtd/nand/raw/loongson1-nand-controller.c > > > +++ b/drivers/mtd/nand/raw/loongson1-nand-controller.c > > > @@ -371,7 +371,7 @@ static int ls1x_nand_dma_transfer(struct ls1x_nand_host *host, struct ls1x_nand_ > > > desc = dmaengine_prep_slave_single(chan, dma_addr, op->len, xfer_dir, DMA_PREP_INTERRUPT); > > > if (!desc) { > > > dev_err(dev, "failed to prepare DMA descriptor\n"); > > > - ret = PTR_ERR(desc); > > > + ret = -ENOMEM; > > > > Thank you for fixing this issue. > > However, I believe -EIO is more appropriate than -ENOMEM, since > > dmaengine_prep_slave_single() can return errors other than -ENOMEM. > > > > It's not an I/O error so -EIO isn't correct. > > There are a bunch of reasons it could fail but most likely > dma_pool_alloc() failed. I think -ENOMEM is correct. > Have you reviewed the implementation of ls1x_dma_prep_slave_sg()? Errors in this function can be caused not only by -ENOMEM, but also by -EINVAL. Moreover, in most cases, the error handling logic for dmaengine_prep_slave_single() returns -EIO when the function returns NULL. > regards, > dan carpenter > -- Best regards, Keguang Zhang ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH next] mtd: rawnand: loongson1: Fix error code in ls1x_nand_dma_transfer() 2025-05-06 10:01 ` Keguang Zhang @ 2025-05-06 11:15 ` Dan Carpenter 2025-05-06 12:12 ` Keguang Zhang 0 siblings, 1 reply; 7+ messages in thread From: Dan Carpenter @ 2025-05-06 11:15 UTC (permalink / raw) To: Keguang Zhang Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra, linux-mips, linux-mtd, linux-kernel, kernel-janitors On Tue, May 06, 2025 at 06:01:15PM +0800, Keguang Zhang wrote: > On Tue, May 6, 2025 at 5:32 PM Dan Carpenter <dan.carpenter@linaro.org> wrote: > > > > On Tue, May 06, 2025 at 05:16:03PM +0800, Keguang Zhang wrote: > > > On Fri, May 2, 2025 at 4:39 PM Dan Carpenter <dan.carpenter@linaro.org> wrote: > > > > > > > > The "desc" variable is NULL and PTR_ERR(NULL) is zero/success. Return > > > > a negative error code instead. > > > > > > > > Fixes: d2d10ede04b1 ("mtd: rawnand: Add Loongson-1 NAND Controller Driver") > > > > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> > > > > --- > > > > It's hard to know what the patch prefix should be here. Ideally when we > > > > add a new driver we would use the patch prefix for the driver. > > > > > > > > Tired: subsystem: Add driver XXX > > > > Wired: subsystem: XXX: Add driver for XXX > > > > > > > > drivers/mtd/nand/raw/loongson1-nand-controller.c | 2 +- > > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > > > diff --git a/drivers/mtd/nand/raw/loongson1-nand-controller.c b/drivers/mtd/nand/raw/loongson1-nand-controller.c > > > > index 6a369b1c7d86..8754bb4f8b56 100644 > > > > --- a/drivers/mtd/nand/raw/loongson1-nand-controller.c > > > > +++ b/drivers/mtd/nand/raw/loongson1-nand-controller.c > > > > @@ -371,7 +371,7 @@ static int ls1x_nand_dma_transfer(struct ls1x_nand_host *host, struct ls1x_nand_ > > > > desc = dmaengine_prep_slave_single(chan, dma_addr, op->len, xfer_dir, DMA_PREP_INTERRUPT); > > > > if (!desc) { > > > > dev_err(dev, "failed to prepare DMA descriptor\n"); > > > > - ret = PTR_ERR(desc); > > > > + ret = -ENOMEM; > > > > > > Thank you for fixing this issue. > > > However, I believe -EIO is more appropriate than -ENOMEM, since > > > dmaengine_prep_slave_single() can return errors other than -ENOMEM. > > > > > > > It's not an I/O error so -EIO isn't correct. > > > > There are a bunch of reasons it could fail but most likely > > dma_pool_alloc() failed. I think -ENOMEM is correct. > > > > Have you reviewed the implementation of ls1x_dma_prep_slave_sg()? The ls1x_dma_prep_slave_sg() has basically two error cases, buggy drivers and allocation errors. Someone could argue that if people pass invalid data then the correct return is -EINVAL but in these cases it's a buggy driver and we fix bugs, we don't work around them. So the correct return is -ENOMEM. > Errors in this function can be caused not only by -ENOMEM, but also by -EINVAL. > Moreover, in most cases, the error handling logic for > dmaengine_prep_slave_single() returns -EIO when the function returns > NULL. There are some that return -EIO but hardly the majority. Other places return -ENOMEM or -EINVAL. It's not worth going back and fixing all of these but really -ENOMEM is the correct return. regards, dan carpenter ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH next] mtd: rawnand: loongson1: Fix error code in ls1x_nand_dma_transfer() 2025-05-06 11:15 ` Dan Carpenter @ 2025-05-06 12:12 ` Keguang Zhang 0 siblings, 0 replies; 7+ messages in thread From: Keguang Zhang @ 2025-05-06 12:12 UTC (permalink / raw) To: Dan Carpenter Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra, linux-mips, linux-mtd, linux-kernel, kernel-janitors On Tue, May 6, 2025 at 7:16 PM Dan Carpenter <dan.carpenter@linaro.org> wrote: > > On Tue, May 06, 2025 at 06:01:15PM +0800, Keguang Zhang wrote: > > On Tue, May 6, 2025 at 5:32 PM Dan Carpenter <dan.carpenter@linaro.org> wrote: > > > > > > On Tue, May 06, 2025 at 05:16:03PM +0800, Keguang Zhang wrote: > > > > On Fri, May 2, 2025 at 4:39 PM Dan Carpenter <dan.carpenter@linaro.org> wrote: > > > > > > > > > > The "desc" variable is NULL and PTR_ERR(NULL) is zero/success. Return > > > > > a negative error code instead. > > > > > > > > > > Fixes: d2d10ede04b1 ("mtd: rawnand: Add Loongson-1 NAND Controller Driver") > > > > > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> > > > > > --- > > > > > It's hard to know what the patch prefix should be here. Ideally when we > > > > > add a new driver we would use the patch prefix for the driver. > > > > > > > > > > Tired: subsystem: Add driver XXX > > > > > Wired: subsystem: XXX: Add driver for XXX > > > > > > > > > > drivers/mtd/nand/raw/loongson1-nand-controller.c | 2 +- > > > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > > > > > diff --git a/drivers/mtd/nand/raw/loongson1-nand-controller.c b/drivers/mtd/nand/raw/loongson1-nand-controller.c > > > > > index 6a369b1c7d86..8754bb4f8b56 100644 > > > > > --- a/drivers/mtd/nand/raw/loongson1-nand-controller.c > > > > > +++ b/drivers/mtd/nand/raw/loongson1-nand-controller.c > > > > > @@ -371,7 +371,7 @@ static int ls1x_nand_dma_transfer(struct ls1x_nand_host *host, struct ls1x_nand_ > > > > > desc = dmaengine_prep_slave_single(chan, dma_addr, op->len, xfer_dir, DMA_PREP_INTERRUPT); > > > > > if (!desc) { > > > > > dev_err(dev, "failed to prepare DMA descriptor\n"); > > > > > - ret = PTR_ERR(desc); > > > > > + ret = -ENOMEM; > > > > > > > > Thank you for fixing this issue. > > > > However, I believe -EIO is more appropriate than -ENOMEM, since > > > > dmaengine_prep_slave_single() can return errors other than -ENOMEM. > > > > > > > > > > It's not an I/O error so -EIO isn't correct. > > > > > > There are a bunch of reasons it could fail but most likely > > > dma_pool_alloc() failed. I think -ENOMEM is correct. > > > > > > > Have you reviewed the implementation of ls1x_dma_prep_slave_sg()? > > The ls1x_dma_prep_slave_sg() has basically two error cases, buggy drivers > and allocation errors. Someone could argue that if people pass invalid > data then the correct return is -EINVAL but in these cases it's a buggy > driver and we fix bugs, we don't work around them. So the correct > return is -ENOMEM. > Yes, -EINVAL indicates a bug rather than a real error. However, this assumes that the caller is aware they are providing invalid data. Otherwise, they might be misled into thinking it is an out-of-memory error (-ENOMEM). > > Errors in this function can be caused not only by -ENOMEM, but also by -EINVAL. > > Moreover, in most cases, the error handling logic for > > dmaengine_prep_slave_single() returns -EIO when the function returns > > NULL. > > There are some that return -EIO but hardly the majority. Other places > return -ENOMEM or -EINVAL. It's not worth going back and fixing all of > these but really -ENOMEM is the correct return. > > regards, > dan carpenter > -- Best regards, Keguang Zhang ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH next] mtd: rawnand: loongson1: Fix error code in ls1x_nand_dma_transfer() 2025-05-02 8:39 [PATCH next] mtd: rawnand: loongson1: Fix error code in ls1x_nand_dma_transfer() Dan Carpenter 2025-05-06 9:16 ` Keguang Zhang @ 2025-05-12 14:29 ` Miquel Raynal 1 sibling, 0 replies; 7+ messages in thread From: Miquel Raynal @ 2025-05-12 14:29 UTC (permalink / raw) To: Keguang Zhang, Dan Carpenter Cc: Richard Weinberger, Vignesh Raghavendra, linux-mips, linux-mtd, linux-kernel, kernel-janitors On Fri, 02 May 2025 11:39:29 +0300, Dan Carpenter wrote: > The "desc" variable is NULL and PTR_ERR(NULL) is zero/success. Return > a negative error code instead. > > Applied to nand/next, thanks! [1/1] mtd: rawnand: loongson1: Fix error code in ls1x_nand_dma_transfer() commit: 0d470c72bea4d9f4c24b304fefdc857979cb5ca0 Patche(s) should be available on mtd/linux.git and will be part of the next PR (provided that no robot complains by then). Kind regards, Miquèl ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-05-12 14:29 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-05-02 8:39 [PATCH next] mtd: rawnand: loongson1: Fix error code in ls1x_nand_dma_transfer() Dan Carpenter 2025-05-06 9:16 ` Keguang Zhang 2025-05-06 9:32 ` Dan Carpenter 2025-05-06 10:01 ` Keguang Zhang 2025-05-06 11:15 ` Dan Carpenter 2025-05-06 12:12 ` Keguang Zhang 2025-05-12 14:29 ` Miquel Raynal
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox