diff mbox series

[1/5] zfs: Fix malloc() success check

Message ID 20240407014743.13872-2-mwleeds@mailtundra.com
State Accepted
Delegated to: Tom Rini
Headers show
Series zfs: Fix zfs support on aarch64 | expand

Commit Message

mwleeds@mailtundra.com April 7, 2024, 1:47 a.m. UTC
This code was hitting the error code path whenever malloc() succeeded
rather than when it failed, so presumably this part of the code hasn't
been tested. I had to apply this fix (and others) to get U-Boot to boot
from ZFS on an Nvidia Jetson TX2 NX SoM (an aarch64 computer).

Signed-off-by: Phaedrus Leeds <mwleeds@mailtundra.com>
Tested-by: Phaedrus Leeds <mwleeds@mailtundra.com>
---
 fs/zfs/zfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Igor Opaniuk April 7, 2024, 11:22 a.m. UTC | #1
Hi Phaedrus,

On Sun, Apr 7, 2024 at 4:00 AM <mwleeds@mailtundra.com> wrote:

> This code was hitting the error code path whenever malloc() succeeded
> rather than when it failed, so presumably this part of the code hasn't
> been tested. I had to apply this fix (and others) to get U-Boot to boot
> from ZFS on an Nvidia Jetson TX2 NX SoM (an aarch64 computer).
>
> Signed-off-by: Phaedrus Leeds <mwleeds@mailtundra.com>
> Tested-by: Phaedrus Leeds <mwleeds@mailtundra.com>
>
It's an abuse of the Tested-by tag. If you are the author of the patch,
that obviously implies that you tested it before sending to ML.
Signed-off-by is enough in this case.

---
>  fs/zfs/zfs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/zfs/zfs.c b/fs/zfs/zfs.c
> index 1fec96cd5c..14779dee32 100644
> --- a/fs/zfs/zfs.c
> +++ b/fs/zfs/zfs.c
> @@ -648,21 +648,21 @@ dmu_read(dnode_end_t *dn, uint64_t blkid, void **buf,
>                 if (bp_array != dn->dn.dn_blkptr) {
>                         free(bp_array);
>                         bp_array = 0;
>                 }
>
>                 if (BP_IS_HOLE(bp)) {
>                         size_t size = zfs_to_cpu16(dn->dn.dn_datablkszsec,
>
>               dn->endian)
>                                 << SPA_MINBLOCKSHIFT;
>                         *buf = malloc(size);
> -                       if (*buf) {
> +                       if (!*buf) {
>                                 err = ZFS_ERR_OUT_OF_MEMORY;
>                                 break;
>                         }
>                         memset(*buf, 0, size);
>                         endian = (zfs_to_cpu64(bp->blk_prop, endian) >>
> 63) & 1;
>                         break;
>                 }
>                 if (level == 0) {
>                         err = zio_read(bp, endian, buf, 0, data);
>                         endian = (zfs_to_cpu64(bp->blk_prop, endian) >>
> 63) & 1;
> --
> 2.44.0
>
>
mwleeds@mailtundra.com April 12, 2024, 3:54 p.m. UTC | #2
On Sunday, April 7th, 2024 at 4:22 AM, Igor Opaniuk <igor.opaniuk@gmail.com> wrote:

> Hi Phaedrus,
> 
> On Sun, Apr 7, 2024 at 4:00 AM mwleeds@mailtundra.com wrote:
> 
> > This code was hitting the error code path whenever malloc() succeeded
> > rather than when it failed, so presumably this part of the code hasn't
> > been tested. I had to apply this fix (and others) to get U-Boot to boot
> > from ZFS on an Nvidia Jetson TX2 NX SoM (an aarch64 computer).
> > 
> > Signed-off-by: Phaedrus Leeds mwleeds@mailtundra.com
> > Tested-by: Phaedrus Leeds mwleeds@mailtundra.com
> 
> It's an abuse of the Tested-by tag. If you are the author of the patch,
> that obviously implies that you tested it before sending to ML.
> Signed-off-by is enough in this case.
> 

That makes sense. Sorry I'm a bit new to this way of submitting patches and more accustomed to pull requests. It seems like a minor thing though; should I re-submit the patches?

> ---
> 
> > fs/zfs/zfs.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/fs/zfs/zfs.c b/fs/zfs/zfs.c
> > index 1fec96cd5c..14779dee32 100644
> > --- a/fs/zfs/zfs.c
> > +++ b/fs/zfs/zfs.c
> > @@ -648,21 +648,21 @@ dmu_read(dnode_end_t *dn, uint64_t blkid, void **buf,
> > if (bp_array != dn->dn.dn_blkptr) {
> > free(bp_array);
> > bp_array = 0;
> > }
> > 
> > if (BP_IS_HOLE(bp)) {
> > size_t size = zfs_to_cpu16(dn->dn.dn_datablkszsec,
> > 
> > dn->endian)
> > << SPA_MINBLOCKSHIFT;
> > *buf = malloc(size);
> > - if (*buf) {
> > + if (!*buf) {
> > err = ZFS_ERR_OUT_OF_MEMORY;
> > break;
> > }
> > memset(*buf, 0, size);
> > endian = (zfs_to_cpu64(bp->blk_prop, endian) >>
> > 63) & 1;
> > break;
> > }
> > if (level == 0) {
> > err = zio_read(bp, endian, buf, 0, data);
> > endian = (zfs_to_cpu64(bp->blk_prop, endian) >>
> > 63) & 1;
> > --
> > 2.44.0
> 
> 
> --
> Best regards - Atentamente - Meilleures salutations
> 
> Igor Opaniuk
> 
> mailto: igor.opaniuk@gmail.com
> skype: igor.opanyuk
> https://www.linkedin.com/in/iopaniuk http://ua.linkedin.com/in/iopaniuk
diff mbox series

Patch

diff --git a/fs/zfs/zfs.c b/fs/zfs/zfs.c
index 1fec96cd5c..14779dee32 100644
--- a/fs/zfs/zfs.c
+++ b/fs/zfs/zfs.c
@@ -648,21 +648,21 @@  dmu_read(dnode_end_t *dn, uint64_t blkid, void **buf,
 		if (bp_array != dn->dn.dn_blkptr) {
 			free(bp_array);
 			bp_array = 0;
 		}
 
 		if (BP_IS_HOLE(bp)) {
 			size_t size = zfs_to_cpu16(dn->dn.dn_datablkszsec,
 											dn->endian)
 				<< SPA_MINBLOCKSHIFT;
 			*buf = malloc(size);
-			if (*buf) {
+			if (!*buf) {
 				err = ZFS_ERR_OUT_OF_MEMORY;
 				break;
 			}
 			memset(*buf, 0, size);
 			endian = (zfs_to_cpu64(bp->blk_prop, endian) >> 63) & 1;
 			break;
 		}
 		if (level == 0) {
 			err = zio_read(bp, endian, buf, 0, data);
 			endian = (zfs_to_cpu64(bp->blk_prop, endian) >> 63) & 1;