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
--