Skip to content

Commit

Permalink
I ♥♥♥ luuv ♥♥♥ cstyle
Browse files Browse the repository at this point in the history
Signed-off-by: Alexey Zaytsev <alexey.zaytsev@gmail.com>
  • Loading branch information
xl0 committed Jun 21, 2011
1 parent 44d24f9 commit b64110f
Show file tree
Hide file tree
Showing 7 changed files with 486 additions and 446 deletions.
16 changes: 10 additions & 6 deletions virtio/util.c
Expand Up @@ -6,8 +6,8 @@
#include <sys/sunndi.h>
#include "util.h"

/*
* Add to ddi?
/*
* Add to ddi?
*/
void
dev_err(dev_info_t *dip, int ce, char *fmt, ...)
Expand All @@ -25,7 +25,8 @@ dev_err(dev_info_t *dip, int ce, char *fmt, ...)
ddi_get_instance(dip), buf);
}

void dev_panic(dev_info_t *dip, char *fmt, ...)
void
dev_panic(dev_info_t *dip, char *fmt, ...)
{
va_list ap;
char buf[256];
Expand All @@ -40,7 +41,8 @@ void dev_panic(dev_info_t *dip, char *fmt, ...)
ddi_get_instance(dip), buf);
}

void hex_dump(char *prefix, void *addr, int len)
void
hex_dump(char *prefix, void *addr, int len)
{
unsigned char *base = addr;
char buff[256], *bptr;
Expand All @@ -55,11 +57,13 @@ void hex_dump(char *prefix, void *addr, int len)
i++;

if (!(i % 16)) {
cmn_err(CE_NOTE, "%s: 0x%p: %s", prefix, base + i - 16, buff);
cmn_err(CE_NOTE, "%s: 0x%p: %s",
prefix, base + i - 16, buff);
bptr = buff;
}
}

if (i % 16)
cmn_err(CE_NOTE, "%s: 0x%p: %s", prefix, base + i - (i % 16), buff);
cmn_err(CE_NOTE, "%s: 0x%p: %s",
prefix, base + i - (i % 16), buff);
}
20 changes: 6 additions & 14 deletions virtio/util.h
Expand Up @@ -7,20 +7,12 @@ void dev_panic(dev_info_t *dip, char *fmt, ...);

void hex_dump(char *prefix, void *addr, int len);

static inline int up_to_power2(int i) {

if (ISP2(i))
return i;

/* Highbit returns h+1. */
return (1 << (highbit(i) - 1));
}

/*
/*
* Stolen from the Linux kernel! Will find a BSD one, but pls don't
* sue us yet. ;)
*/
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})

#define container_of(ptr, type, member) ( \
{ \
const typeof(((type *)0)->member) *__mptr = (ptr); \
(type *)((char *)__mptr - offsetof(type, member)); \
})

0 comments on commit b64110f

Please sign in to comment.