Re: 2.6.14 kernels and above copy_to_user stupidity with IRQ disabled check

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Phillip Susi wrote:

[email protected] wrote:

OK. Got it. I guess I need to restructure. And BTW, This was a code fragment only, the spinlock gets released when -EFAULT is called -- was just an example.

Jeff


Unless you have redefined EFAULT in some strange and hideous way, it is not "called" and doesn't free the spinlock. EFAULT is defined as a literal integer, so you're just returning a number without freeing the spinlock.

If you have redefined EFAULT to a macro function call or whatever, then don't do that, it's REALLY horrible coding practice.


No.  I posted a code fragment as an example.  Here's the actual code:

int dump_regen(VIRTUAL_SETUP *s, ULONG count)
{
   register int i = 0;
   VIRTUAL_SETUP *v;
   spin_lock_irqsave(&regen_lock, regen_flags);
   v = regen_head;
   while (v)
   {
      if (i >= count)
      {
         spin_unlock_irqrestore(&regen_lock, regen_flags);
         return -EFAULT;
      }
      err = copy_to_user(&s[i++], v, sizeof(VIRTUAL_SETUP));
      if (err)
{ spin_unlock_irqrestore(&regen_lock, regen_flags);
          return err;
      }

      v = v->next;
   }
   spin_unlock_irqrestore(&regen_lock, regen_flags);
   return 0;
}

Needless to say, this has been restructured to this:

int dump_regen(VIRTUAL_SETUP *s, ULONG count)
{
   register int i = 0;
   VIRTUAL_SETUP *v;
   spin_lock_irqsave(&regen_lock, regen_flags);
   v = regen_head;
   while (v)
   {
      if (i >= count)
      {
         spin_unlock_irqrestore(&regen_lock, regen_flags);
         return 0;
      }
      P_Copy(&s[i++], v, sizeof(VIRTUAL_SETUP));
      v = v->next;
   }
   spin_unlock_irqrestore(&regen_lock, regen_flags);
   return 0;
}
Jeff

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

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux