<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-family:monospace"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">2023年3月3日(金) 18:39 Yue Hu <<a href="mailto:zbestahu@gmail.com" target="_blank">zbestahu@gmail.com</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Fri,  3 Mar 2023 16:52:18 +0900<br>
Noboru Asai <<a href="mailto:asai@sijam.com" target="_blank">asai@sijam.com</a>> wrote:<br>
<br>
> The variable 'vi->xattr_shared_count' could be ZERO.<br>
> <br>
> Signed-off-by: Noboru Asai <<a href="mailto:asai@sijam.com" target="_blank">asai@sijam.com</a>><br>
> ---<br>
>  fs/erofs/xattr.c | 2 ++<br>
>  1 file changed, 2 insertions(+)<br>
> <br>
> diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c<br>
> index 60729b1220b6..5164813a693b 100644<br>
> --- a/fs/erofs/xattr.c<br>
> +++ b/fs/erofs/xattr.c<br>
> @@ -80,6 +80,8 @@ static int init_inode_xattrs(struct inode *inode)<br>
>  <br>
>       ih = (struct erofs_xattr_ibody_header *)(it.kaddr + it.ofs);<br>
>       vi->xattr_shared_count = ih->h_shared_count;<br>
> +     if (!vi->xattr_shared_count)<br>
> +             goto out_unlock;<br>
<br>
Questions: ret = 0? no need to <span class="gmail_default" style="font-family:monospace"></span>erofs_put_metabuf?<br></blockquote><div><br></div><div><div class="gmail_default" style="font-family:monospace">You are right. this patch needs to call erofs_put_metabuf() before goto out_unlock.</div></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
I think we can keep current since <span class="gmail_default" style="font-family:monospace"></span>kmalloc_array() will check whether the<br>
size(->xattr_shared_count) is zero size or not. rt?<br></blockquote><div><br></div><div><div class="gmail_default" style="font-family:monospace">In case of xattr_shared_count == 0, <span class="gmail_default"></span><span style="font-family:Arial,Helvetica,sans-serif">kmalloc_array()</span><span style="font-family:Arial,Helvetica,sans-serif"> return </span><span style="font-family:Arial,Helvetica,sans-serif">ZERO_SIZE_PTR. </span></div><div class="gmail_default" style="font-family:monospace"><span style="font-family:Arial,Helvetica,sans-serif">And kfree() do noting in this case (safe).</span></div><div class="gmail_default" style="font-family:monospace"><br></div></div><div>#define ZERO_SIZE_PTR ((void *)16)<br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
>       vi->xattr_shared_xattrs = kmalloc_array(vi->xattr_shared_count,<br>
>                                               sizeof(uint), GFP_KERNEL);<br>
>       if (!vi->xattr_shared_xattrs) {<br>
<br>
</blockquote></div></div>