Re: [patch 15/24] perfmon: context creation

From: Ingo Molnar
Date: Wed Nov 26 2008 - 08:34:22 EST



* eranian@xxxxxxxxxxxxxx <eranian@xxxxxxxxxxxxxx> wrote:

> +/**
> + * pfm_undo_create -- undo context creation
> + * @fd: file descriptor to close
> + * @ctx: newly created context
> + *
> + * upon return neither fd nor ctx are useable
> + */
> +void pfm_undo_create(int fd, struct pfm_context *ctx)
> +{
> + struct files_struct *files = current->files;
> + struct file *file;
> + int fput_needed;
> +
> + file = fget_light(fd, &fput_needed);
> + /*
> + * there is no fd_uninstall(), so we do it
> + * here. put_unused_fd() does not remove the
> + * effect of fd_install().
> + */
> +
> + spin_lock(&files->file_lock);
> + files->fd_array[fd] = NULL;
> + spin_unlock(&files->file_lock);
> +
> + fput_light(file, fput_needed);
> +
> + /*
> + * decrement ref count and kill file
> + */
> + put_filp(file);
> +
> + put_unused_fd(fd);
> +
> + pfm_free_context(ctx);
> +}

This function is superfluous.

The only place where this is used is when a fresh sys_pfm_create()
fails to do a user-copy of the sif:

+ if (ureq && copy_to_user(ureq, &sif, sizeof(sif))) {
+ pfm_undo_create(ret, new_ctx);
+ ret = -EFAULT;
+ }

but this code should be calling sys_close(fd) instead - the fd is
already set up with pfm_fs so it will tear down the context if this
was the last user of the perfmon context.

So basically pfm_undo_create() is an open-coded sys_close(fd).

Ingo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/