From: Gao Xiang <gaoxiang25@huawei.com>
To: Li Guifu <blucerlee@gmail.com>, Li Guifu <bluce.liguifu@huawei.com>
Cc: Miao Xie <miaoxie@huawei.com>, linux-erofs@lists.ozlabs.org
Subject: Re: [PATCH v2] erofs-utils: complete missing memory handling
Date: Thu, 14 Nov 2019 09:51:10 +0800 [thread overview]
Message-ID: <20191114015110.GA155186@architecture4> (raw)
In-Reply-To: <20191114002428.GA2809@hsiangkao-HP-ZHAN-66-Pro-G1>
On Thu, Nov 14, 2019 at 08:24:31AM +0800, Gao Xiang via Linux-erofs wrote:
> Hi Guifu,
>
> On Thu, Nov 14, 2019 at 01:03:35AM +0800, Li Guifu wrote:
> > From: Li Guifu <bluce.liguifu@huawei.com>
> >
> > memory allocation failure should be handled
> > properly in principle.
> >
> > Signed-off-by: Li Guifu <bluce.liguifu@huawei.com>
> > [ Gao Xiang: due to Huawei outgoing email limitation,
> > I have to help Guifu send out his patches at work. ]
> > Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
> > Signed-off-by: Li Guifu <blucerlee@gmail.com>
> > ---
>
> As a common practice, It's perferred to leave some useful
> comments at this about what you modified compared wtih
> the last version.
>
> > lib/inode.c | 21 ++++++++++++++++++---
> > 1 file changed, 18 insertions(+), 3 deletions(-)
> >
> > diff --git a/lib/inode.c b/lib/inode.c
> > index 86c465e..b6c2b13 100644
> > --- a/lib/inode.c
> > +++ b/lib/inode.c
> > @@ -264,6 +264,8 @@ int erofs_write_dir_file(struct erofs_inode *dir)
> > if (used) {
> > /* fill tail-end dir block */
> > dir->idata = malloc(used);
> > + if (!dir->idata)
> > + return -ENOMEM;
> > DBG_BUGON(used != dir->idata_size);
> > fill_dirblock(dir->idata, dir->idata_size, q, head, d);
> > }
> > @@ -286,6 +288,8 @@ int erofs_write_file_from_buffer(struct erofs_inode *inode, char *buf)
> > inode->idata_size = inode->i_size % EROFS_BLKSIZ;
> > if (inode->idata_size) {
> > inode->idata = malloc(inode->idata_size);
> > + if (!inode->idata)
> > + return -ENOMEM;
> > memcpy(inode->idata, buf + blknr_to_addr(nblocks),
> > inode->idata_size);
> > }
> > @@ -347,9 +351,14 @@ int erofs_write_file(struct erofs_inode *inode)
> > inode->idata_size = inode->i_size % EROFS_BLKSIZ;
> > if (inode->idata_size) {
> > inode->idata = malloc(inode->idata_size);
> > -
> > + if (!inode->idata) {
> > + errno = ENOMEM;
> > + goto fail;
> > + }
When I revisited this patch, I noticed it's some weird to operate `errno' here.
The same sequence "close(fd); return -ENOMEM;" is indeed some unclean, but
I think you could make a separate cleanup patch then.
I will resend PATCH v3 since you aren't able to post public mail at work
and apply it to experimental branch.
Thanks,
Gao Xiang
> > ret = read(fd, inode->idata, inode->idata_size);
> > if (ret < inode->idata_size) {
> > + free(inode->idata);
> > + inode->idata = NULL;
>
> Anyway, it seems the diffstat is this line.
> I think it' better than v1 so let's use this version.
>
> Thanks,
> Gao Xiang
>
next prev parent reply other threads:[~2019-11-14 1:49 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-12 11:26 [PATCH 1/2] erofs-utils: complete missing memory handling Gao Xiang
2019-11-12 11:26 ` [PATCH 2/2] erofs-utils: set up all compiler/linker variables independently Gao Xiang
2019-11-13 17:12 ` Li Guifu
2019-11-14 0:26 ` Gao Xiang via Linux-erofs
2019-11-14 13:45 ` [PATCH v2] " Gao Xiang via Linux-erofs
2019-11-14 15:27 ` Li Guifu
2019-11-13 17:03 ` [PATCH v2] erofs-utils: complete missing memory handling Li Guifu
2019-11-14 0:24 ` Gao Xiang via Linux-erofs
2019-11-14 1:51 ` Gao Xiang [this message]
2019-11-14 9:19 ` [PATCH v3] " Gao Xiang via Linux-erofs
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=20191114015110.GA155186@architecture4 \
--to=gaoxiang25@huawei.com \
--cc=bluce.liguifu@huawei.com \
--cc=blucerlee@gmail.com \
--cc=linux-erofs@lists.ozlabs.org \
--cc=miaoxie@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