[PATCH 05/13] erofs-utils: lib: keep self maintained devname
Gao Xiang
hsiangkao at linux.alibaba.com
Mon Aug 14 16:55:01 AEST 2023
On 2023/8/14 14:43, Gao Xiang wrote:
>
>
> On 2023/8/14 11:42, Jingbo Xu wrote:
>> Keep self allocated and maintained devname in erofs_sb_info.
>>
>> Signed-off-by: Jingbo Xu <jefflexu at linux.alibaba.com>
>> ---
...
>> @@ -95,7 +97,11 @@ int dev_open(struct erofs_sb_info *sbi, const char *dev)
>> return -EINVAL;
>> }
>> - sbi->devname = dev;
>> + sbi->devname = strdup(dev);
>
> Could we move sbi->devname assignment to the beginning of the function?
> e.g.
>
> ..
> sbi->devname = strdup(dev);
> if (!sbi->devname)
> return -ENOMEM;
>
> fd = open(dev, O_RDWR | O_CREAT | O_BINARY, 0644);
> ...
>
>
>> + if (!sbi->devname) {
>> + close(fd);
>> + return -ENOMEM;
>> + }
After a second thought, since there are already several `close(fd);` in the
error paths and they are unavoidable. So it looks good to me now:
Reviewed-by: Gao Xiang <hsiangkao at linux.alibaba.com>
Thanks,
Gao Xiang
More information about the Linux-erofs
mailing list