Re: [PATCH V7 4/8] posix clocks: hook dynamic clocks into system calls

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Thomas Gleixner
Date: Friday, December 17, 2010 - 3:03 am

On Fri, 17 Dec 2010, Richard Cochran wrote:

  if (!id & ~CLOCKFD_MASK)
  if ((id & CLOCKFD_MASK) == CLOCKFD)

Not a real problem. I just always stumble over that coding style.


Hmm ok, so you use clk->mutex to prevent the underlying device from
going away while you call a function and clk->zombie indicates that
it's gone and clk just kept around for an open file descriptor. Now it
makes sense, but that wants a big fat comment in the code. :)

Doesn't the same problem exist for the file operations of patch 3? I
think you want the very same protection there unless you want to do
the same magic in your USB driver as well.

So you could do the following:

static int get_fd_clk(struct posix_clock_descr *cd, struct file *fp)
{
	cd->fp = fp;
	cd->clk = fp->private_data;
	mutex_lock(&cd->clk->mutex);
	if (!cd->clk->zombie)
		return 0;
	mutex_unlock(&cd->clk->mutex);
	return -ENODEV;
}

static void put_fd_clk(struct posix_clock_descr *cd)
{
	mutex_unlock(&cd->clk->mutex);
}

static int get_posix_clock(const clockid_t id, struct posix_clock_descr *cd)
{
	struct file *fp = fget(CLOCKID_TO_FD(id));
	int ret;

	if (!fp || fp->f_op->open != posix_clock_open || !fp->private_data)
	   	return -ENODEV;
	ret = get_fd_clk(cd, fp);
	if (ret)
		fput(fp);
	return ret;
}

static void put_posix_clock(struct posix_clock_descr *cd)
{
	put_fd_clk(cd);
	fput(cd->fp);
}

So your fops would call get_fd_clk() and put_fd_clk() and the pc_timer
ones get_posix_clock() and put_posix_clock() or whatever sensible
function names you come up with.

Thoughts ?


Yes, he's right. Was too tired to think about the clock ids assingment
when devices are removed and plugged. The fd mapping makes that all go
away.

Thanks,

	tglx
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH V7 0/8] ptp: IEEE 1588 hardware clock support, Richard Cochran, (Thu Dec 16, 8:41 am)
[PATCH V7 1/8] ntp: add ADJ_SETOFFSET mode bit, Richard Cochran, (Thu Dec 16, 8:41 am)
[PATCH V7 3/8] posix clocks: introduce dynamic clocks, Richard Cochran, (Thu Dec 16, 8:43 am)
[PATCH V7 7/8] ptp: Added a clock driver for the IXP46x., Richard Cochran, (Thu Dec 16, 8:44 am)
Re: [PATCH V7 3/8] posix clocks: introduce dynamic clocks, Arnd Bergmann, (Thu Dec 16, 9:16 am)
Re: [PATCH V7 1/8] ntp: add ADJ_SETOFFSET mode bit, Thomas Gleixner, (Thu Dec 16, 10:48 am)
Re: [PATCH V7 3/8] posix clocks: introduce dynamic clocks, Thomas Gleixner, (Thu Dec 16, 1:56 pm)
Re: [PATCH V7 3/8] posix clocks: introduce dynamic clocks, Richard Cochran, (Thu Dec 16, 11:29 pm)
Re: [PATCH V7 4/8] posix clocks: hook dynamic clocks into ..., Richard Cochran, (Fri Dec 17, 12:04 am)
Re: [PATCH V7 4/8] posix clocks: hook dynamic clocks into ..., Thomas Gleixner, (Fri Dec 17, 3:03 am)
Re: [PATCH V7 1/8] ntp: add ADJ_SETOFFSET mode bit, Kuwahara,T., (Fri Dec 17, 1:16 pm)
Re: [PATCH V7 1/8] ntp: add ADJ_SETOFFSET mode bit, john stultz, (Tue Dec 21, 12:37 pm)
Re: [PATCH V7 1/8] ntp: add ADJ_SETOFFSET mode bit, Kuwahara,T., (Tue Dec 21, 1:57 pm)
Re: [PATCH V7 1/8] ntp: add ADJ_SETOFFSET mode bit, Kuwahara,T., (Tue Dec 21, 2:13 pm)
Re: [PATCH V7 1/8] ntp: add ADJ_SETOFFSET mode bit, Richard Cochran, (Wed Dec 22, 12:11 am)
Re: [PATCH V7 1/8] ntp: add ADJ_SETOFFSET mode bit, Richard Cochran, (Wed Dec 22, 12:13 am)
Re: [PATCH V7 1/8] ntp: add ADJ_SETOFFSET mode bit, Alexander Gordeev, (Wed Dec 22, 2:58 am)
Re: [PATCH V7 1/8] ntp: add ADJ_SETOFFSET mode bit, Kuwahara,T., (Wed Dec 22, 1:27 pm)
Re: [PATCH V7 1/8] ntp: add ADJ_SETOFFSET mode bit, john stultz, (Wed Dec 22, 5:00 pm)
Re: [PATCH V7 1/8] ntp: add ADJ_SETOFFSET mode bit, Richard Cochran, (Wed Dec 22, 11:13 pm)
Re: [PATCH V7 1/8] ntp: add ADJ_SETOFFSET mode bit, Kuwahara,T., (Sat Dec 25, 1:38 pm)
Re: [PATCH V7 7/8] ptp: Added a clock driver for the IXP46x., Richard Cochran, (Mon Jan 3, 10:07 am)