Re: Magic in videobuf

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

 



On Tue, Mar 16, 2010 at 12:35 PM, Hans Verkuil <hverkuil@xxxxxxxxx> wrote:
> That is my opinion, yes. However, there is one case where this is actually
> useful. Take for example the function videobuf_to_dma in
> videobuf-dma-sg.c. This is called by drivers and it makes sense that that
> function should double-check that the videobuf_buffer is associated with
> the dma_sg memtype.
>
> But calling this 'magic' is a poor choice of name. There is nothing magic
> about it, in this case it is just an identifier of the memtype. And there
> may be better ways to do this check anyway.

It's funny, because when I saw the word "magic", I knew *exactly* what
it did.  The notion of putting a magic value at the top of a structure
is not that uncommon (although you don't see it in Linux much).  I've
seen it done many times over the years (all using the term "magic"
which is why I knew what it did).  The cases where it is really
helpful is when you have lots of (void *) pointers in your buffer
management code, as it lets you detect cases where a function gets
passed the wrong buffer type (which wouldn't fail a compile time due
to the void * pointer).  And by using different magic values for
different structure types, in many cases it will give you a hint where
the problem is (because you would now know *what* type of structure
got passed into the function).

That said, these sorts of cases usually aren't usually intended to
catch *random* memory corruption as they are to help isolate problems
in buffer handling code.

Devin

-- 
Devin J. Heitmueller - Kernel Labs
http://www.kernellabs.com
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux