From: Dave Chinner <david@fromorbit.com>
To: Eric Sandeen <sandeen@sandeen.net>
Cc: zhanchengbin <zhanchengbin1@huawei.com>,
djwong@kernel.org, liuzhiqiang26@huawei.com,
linfeilong <linfeilong@huawei.com>,
linux-xfs@vger.kernel.org
Subject: Re: [PATCH 1/3] mkfs/proto.c: avoid to use NULL pointer
Date: Tue, 7 Jun 2022 07:46:13 +1000 [thread overview]
Message-ID: <20220606214613.GT227878@dread.disaster.area> (raw)
In-Reply-To: <cadc327b-2370-1b1d-6822-ae8a1da6d58c@sandeen.net>
On Mon, Jun 06, 2022 at 09:29:27AM -0500, Eric Sandeen wrote:
> On 6/6/22 7:33 AM, zhanchengbin wrote:
> > Change malloc to xmalloc.
>
> The commit log and cover letter say nothing about this, but apparently
> "xmalloc" is often defined locally to abort() on a memory failure, so I
> guess you are trying to make (some of?) xfsprogs do that.
>
> First, this doesn't seem to build....
>
> Building mkfs
> [CC] proto.o
> proto.c: In function ‘setup_proto’:
> proto.c:73:15: warning: implicit declaration of function ‘xmalloc’; did you mean ‘malloc’? [-Wimplicit-function-declaration]
> 73 | buf = xmalloc(size + 1);
> | ^~~~~~~
> | malloc
> proto.c:73:13: warning: assignment to ‘char *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
> 73 | buf = xmalloc(size + 1);
> | ^
> proto.c: In function ‘newregfile’:
> proto.c:306:21: warning: assignment to ‘char *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
> 306 | buf = xmalloc(size);
> | ^
> [LD] mkfs.xfs
> /usr/bin/ld: proto.o: in function `setup_proto':
> /src/git/xfsprogs-dev/mkfs/proto.c:73: undefined reference to `xmalloc'
> /usr/bin/ld: proto.o: in function `newregfile':
> /src/git/xfsprogs-dev/mkfs/proto.c:306: undefined reference to `xmalloc'
> collect2: error: ld returned 1 exit status
> gmake[2]: *** [../include/buildrules:65: mkfs.xfs] Error 1
> gmake[1]: *** [include/buildrules:36: mkfs] Error 2
> make: *** [Makefile:92: default] Error 2
>
> Second, we have calls to malloc all over the codebase, including around
> 100 outside of the internal libraries in the various userspace utilities.
> Why change only mkfs/db/repair?
xmalloc is local to xfs_db (db/malloc.c), it's not part of libxfs.
It's local to xfs_db because it is the tool that always runs out of
memory on large filesystems. It's just a wrapper that prints "out of
memory" and then exits immediately with no chance to recover. So,
essentially, it's no different to immediately SEGV on a NULL pointer
and dying.
> Third, what problem are you solving? Granted, we should be checking every
> malloc call, and it seems that we don't.
In general, that's because we can't do anything useful to free
memory when we fail memory allocation - we generally exit
immediately on memory allocation failure, so checking for failure is
almost redundant....
Cheers,
Dave.
--
Dave Chinner
david@fromorbit.com
next prev parent reply other threads:[~2022-06-06 21:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-06 12:31 [PATCH 0/3] xfsprogs: avoid to use NULL pointer zhanchengbin
2022-06-06 12:33 ` [PATCH 1/3] mkfs/proto.c: " zhanchengbin
2022-06-06 14:29 ` Eric Sandeen
2022-06-06 21:46 ` Dave Chinner [this message]
2022-06-06 12:33 ` [PATCH 2/3] db: " zhanchengbin
2022-06-06 12:34 ` [PATCH 3/3] repair/slab.c: " zhanchengbin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220606214613.GT227878@dread.disaster.area \
--to=david@fromorbit.com \
--cc=djwong@kernel.org \
--cc=linfeilong@huawei.com \
--cc=linux-xfs@vger.kernel.org \
--cc=liuzhiqiang26@huawei.com \
--cc=sandeen@sandeen.net \
--cc=zhanchengbin1@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox