[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v1 44/59] 9p-local.c: remove unneeded label in local_unlinkat
From: |
Greg Kurz |
Subject: |
Re: [PATCH v1 44/59] 9p-local.c: remove unneeded label in local_unlinkat_common() |
Date: |
Tue, 7 Jan 2020 14:53:40 +0100 |
On Mon, 6 Jan 2020 15:24:10 -0300
Daniel Henrique Barboza <address@hidden> wrote:
> 'err_out' can be replaced by 'return ret' in the error conditions
> the jump was being made.
>
> CC: Greg Kurz <address@hidden>
> Signed-off-by: Daniel Henrique Barboza <address@hidden>
> ---
> hw/9pfs/9p-local.c | 12 +++++-------
> 1 file changed, 5 insertions(+), 7 deletions(-)
>
> diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c
> index ca641390fb..f9bdd2ad7c 100644
> --- a/hw/9pfs/9p-local.c
> +++ b/hw/9pfs/9p-local.c
> @@ -1094,12 +1094,12 @@ static int local_unlinkat_common(FsContext *ctx, int
> dirfd, const char *name,
>
> fd = openat_dir(dirfd, name);
> if (fd == -1) {
> - goto err_out;
> + return ret;
> }
> ret = unlinkat(fd, VIRTFS_META_DIR, AT_REMOVEDIR);
> close_preserve_errno(fd);
> if (ret < 0 && errno != ENOENT) {
> - goto err_out;
> + return ret;
> }
> }
> map_dirfd = openat_dir(dirfd, VIRTFS_META_DIR);
> @@ -1107,16 +1107,14 @@ static int local_unlinkat_common(FsContext *ctx, int
> dirfd, const char *name,
> ret = unlinkat(map_dirfd, name, 0);
> close_preserve_errno(map_dirfd);
> if (ret < 0 && errno != ENOENT) {
> - goto err_out;
> + return ret;
> }
> } else if (errno != ENOENT) {
> - goto err_out;
> + return ret;
Ouch... I now realize we can get there with ret == 0 when unlinking a
directory in mapped-file mode. The function will wrongly return success
despite the failure.... Since this function is supposed to return -1
on error, I suggest to do that instead of return ret, and to drop the
initialization of ret to -1, which wouldn't be needed anymore.
Since this would fix a bug it makes sense to post it separately from
this series. Rewrite the title/changelog accordingly and I'll merge
it via the 9p tree.
> }
> }
>
> - ret = unlinkat(dirfd, name, flags);
> -err_out:
> - return ret;
> + return unlinkat(dirfd, name, flags);
> }
>
> static int local_remove(FsContext *ctx, const char *path)
- Re: [PATCH v1 31/59] util/aio-posix.c: remove unneeded 'out' label in aio_epoll, (continued)
- [PATCH v1 33/59] ipmi/ipmi_bmc_sim.c: remove unneeded labels, Daniel Henrique Barboza, 2020/01/06
- [PATCH v1 39/59] usb/dev-mtp.c: remove unneeded label in write_retry(), Daniel Henrique Barboza, 2020/01/06
- [PATCH v1 41/59] intc/s390_flic_kvm.c: remove unneeded label in kvm_flic_load(), Daniel Henrique Barboza, 2020/01/06
- [PATCH v1 44/59] 9p-local.c: remove unneeded label in local_unlinkat_common(), Daniel Henrique Barboza, 2020/01/06
- [PATCH v1 45/59] 9pfs/9p.c: remove unneeded labels, Daniel Henrique Barboza, 2020/01/06
- [PATCH v1 47/59] pvrdma_main.c: remove unneeded labels, Daniel Henrique Barboza, 2020/01/06
- [PATCH v1 49/59] rdma/rdma_rm.c: remove unneeded label in rdma_rm_alloc_pd(), Daniel Henrique Barboza, 2020/01/06
- [PATCH v1 51/59] virtio/vhost.c: remove unneeded labels, Daniel Henrique Barboza, 2020/01/06
- [PATCH v1 52/59] net/vhost_net.c: remove unneeded labels, Daniel Henrique Barboza, 2020/01/06
- [PATCH v1 53/59] net/net_tx_pkt.c: remove unneeded label in net_tx_pkt_get_gso_type(), Daniel Henrique Barboza, 2020/01/06
- [PATCH v1 54/59] ivshmem-server/main.c: remove unneeded label in main(), Daniel Henrique Barboza, 2020/01/06