Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

+checkpatch

  • Loading branch information...
commit 9bef4ebb699797660531fde66ec745f39ae8a6b0 1 parent e2cc0c4
Constantine authored
8 Makefile
View
@@ -1,5 +1,6 @@
#ccflags-y+=-Wfatal-errors
ccflags-y+=-include $M/ctracer.h
+ccflags-y+=-D DEBUG
ccflags-y+=-D CTRACER_ON
ccflags-y+=-D USE_PLATFORM_DEVICE
@@ -18,7 +19,7 @@ modules_install:
$(MAKE) -C $(KERNELDIR) M=$$PWD modules_install
clean:
- rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
+ rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions modules.order
depend .depend dep:
$(CC) $(ccflags-y) -M *.c > .depend
@@ -29,3 +30,8 @@ dio: CPPFLAGS+= -D CTRACER_ON -include ctracer.h -g
ifeq (.depend,$(wildcard .depend))
include .depend
endif
+
+_src=dio.c ldt.c ldt_plat_dev.c ldt_plat_drv.c ctracer.h
+
+checkpatch:
+ checkpatch.pl --no-tree --show-types --ignore LONG_LINE,LINE_CONTINUATIONS --terse -f $(_src) Makefile
355 ctracer.h
View
@@ -8,11 +8,12 @@
Dual BSD/GPL License
*/
-/* Configuration flags: */
-
-//#define TRACE_TIME
-//#define TRACE_MALLOC
-
+#if 0
+/* Optional configuration flags: */
+#define TRACE_TIME
+#define TRACE_MALLOC
+#define TRACE_LINUX_MEMORY_ON
+#endif
/*
VI command to include label _entry to each function start for tracing
:%s/) *\n{ *$/)\r{\t_entry:;/
@@ -20,28 +21,31 @@
#ifndef __ASSEMBLY__
-//__BEGIN_DECLS
#ifndef CTRACER_H_INCLUDED
#define CTRACER_H_INCLUDED
extern __thread int ret;
-#define _entry trllog(); goto _entry; _entry
-//#define _entry _trace_enter_exit_();trln(); goto _entry_second;_entry_second
-//#define _entry once(trl()); goto _entry; _entry
-//#define return trlm("} "); return
+#define multistatement(ms) ms /*trick to bybass checkpatch.pl error */
+#define _entry multistatement(trllog(); goto _entry; _entry)
+/*
+#define _entry _trace_enter_exit_(); trln(); goto _entry_second; _entry_second
+#define _entry once(trl()); goto _entry; _entry
+#define return trlm("} "); return
+*/
#ifdef TRACE_MALLOC
-static int malloc_count = 0;
-static void *malloc_trace = NULL;
+static int malloc_count;
+static void *malloc_trace;
#endif
#define empty_statement() do { } while (0)
-#define empty_function() { } while (0)
+#define empty_function() ({ } while (0))
+#define do_statement(a) do { a } while (0)
#define trace_ioctl(nr) tracef("ioctl=(%c%c %c #%i %i)\n", \
- (_IOC_READ & _IOC_DIR(nr))?'r':' ', (_IOC_WRITE & _IOC_DIR(nr))?'w':' ', \
+ (_IOC_READ & _IOC_DIR(nr)) ? 'r' : ' ', (_IOC_WRITE & _IOC_DIR(nr)) ? 'w' : ' ', \
_IOC_TYPE(nr), _IOC_NR(nr), _IOC_SIZE(nr))
-#define trace_ioctl_(nr) tracef("ioctl=(%i %i %i %i)", _IOC_DIR(nr),_IOC_TYPE(nr), _IOC_NR(nr), _IOC_SIZE(nr))
+#define trace_ioctl_(nr) tracef("ioctl=(%i %i %i %i)", _IOC_DIR(nr), _IOC_TYPE(nr), _IOC_NR(nr), _IOC_SIZE(nr))
#ifdef DEBUG
#define _TRACE
@@ -51,7 +55,7 @@ static void *malloc_trace = NULL;
#define _TRACE
#endif
-#ifdef CTRACER_OFF // force no tracing
+#ifdef CTRACER_OFF /* force no tracing */
#undef _TRACE
#endif
@@ -61,107 +65,99 @@ static void *malloc_trace = NULL;
#ifdef __KERNEL__
#undef TRACE_TIME
-//static inline void stack_trace(void) { }
-
-//#define TRACE_LINUX_MEMORY_ON
#ifdef TRACE_LINUX_MEMORY_ON
#include <linux/mmzone.h>
extern int free_pages_prev;
-#define trace_linux_mem() \
-do { \
+#define trace_linux_mem() do { \
extern zone_t *zone_table[MAX_NR_ZONES*MAX_NR_NODES]; \
int mem_change = zone_table[0]->free_pages - free_pages_prev; \
-if ( mem_change ) { trl_(); trvi_(mem_change ); trvi(zone_table[0]->free_pages); } \
-free_pages_prev = zone_table[0]->free_pages; \
-} while (0);
+if (mem_change) { \
+ trl_(); trvi_(mem_change); trvi(zone_table[0]->free_pages); } \
+ free_pages_prev = zone_table[0]->free_pages; \
+} while (0)
#endif
-//#define tracef(fmt, args...) { if (get_current()->trace) printk( fmt, ## args); }
#define SOL KERN_DEBUG
#define tracef(fmt, args...) printk(fmt, ##args)
-#else // ! __KERNEL__
-// _TRACE and not __KERNEL__
+#else /* !__KERNEL__ */
+/* _TRACE and not __KERNEL__ */
#include <stdio.h>
-#ifdef __GNUC__
-#define tracef(args...) fprintf(stderr,##args)
-
-//#include <signal.h>
-//#define BP {trl();kill(0,SIGTRAP);}
-//#define BP kill(0,SIGTRAP)
+#define tracef(args...) fprintf(stderr, ##args)
-#endif // __GNUC__
+#if 0
+#include <signal.h>
+#define BP {trl(); kill(0, SIGTRAP); }
+#define BP kill(0, SIGTRAP)
+#endif
#ifndef tracef
#define tracef printf
#endif
+#endif /* !__KERNEL__ */
+
+#ifndef _hweight32
+static inline unsigned int _hweight32(unsigned int w)
+{ /* from kernel */
+ w -= (w >> 1) & 0x55555555;
+ w = (w & 0x33333333) + ((w >> 2) & 0x33333333);
+ w = (w + (w >> 4)) & 0x0f0f0f0f;
+ return (w * 0x01010101) >> 24;
+}
-#endif // __KERNEL__
-#ifndef _hweight16_defined
-#ifdef __GNUC__
-static inline unsigned int _hweight16(unsigned int n)
-{
- int w = 0;;
- while (n) {
- w += n & 1;
- n = n >> 1;
- }
- return w;
-}
-#endif
-#define _hweight16_defined
+#define _hweight32 _hweight32
#endif
-#define trllog(args ... ) \
+#define trllog(args ...) \
do { \
- static int num; \
- if ( _hweight16(num) < 2 ) { \
- trla("#0x%x\n",(int)num); \
- } num++; \
+ static int num; \
+ if (_hweight32(num) < 2) { \
+ trla("#%d\n", (int)num); \
+ } num++; \
} while (0)
-#define trlnum(n, args ... ) \
+#define trlnum(n, args ...) \
do { \
- static int num; \
- if ( num < n ) { \
- trl_(); \
- tracef("#0x%x",(int)num); \
- args; \
- trln(); \
- } num++; \
+ static int num; \
+ if (num < n) { \
+ trl_(); \
+ tracef("#0x%x", (int)num); \
+ args; \
+ trln(); \
+ } num++; \
} while (0)
-#define trleach(n, args ... ) \
+#define trleach(n, args ...) \
do { \
- static int num; \
- if ( ! ( num % n ) ) { \
- trl_(); \
- trvi_(num); \
- args; \
- trln(); \
- } num++; \
+ static int num; \
+ if (!(num % n)) { \
+ trl_(); \
+ trvi_(num); \
+ args; \
+ trln(); \
+ } num++; \
} while (0)
-#else // ! _TRACE
-#define trllog(args ... )
+#else /* !_TRACE */
+#define trllog(args ...)
-#define IFDBG(x) do {} while (0)
+#define IFDBG(x) empty_statement()
#define trace_linux_mem() empty_statement()
#define tracef(fmt, args...) empty_function()
#define stack_trace() empty_statement()
-#endif // _TARCE
+#endif /* _TARCE */
#ifndef SOL
#define SOL ""
#endif
-#define EOL "\n" // for console
-//#define EOL "\r\n" // for com port
+#define EOL "\n" /* for console */
+ /*#define EOL "\r\n"*//* for com port */
#ifdef MODULE
-// omit full absolute path for modules
+/* omit full absolute path for modules */
static inline char *ctracer_file_name_no_path(char *fn)
{
char *strrchr(const char *s, int c);
@@ -177,79 +173,84 @@ static inline char *ctracer_file_name_no_path(char *fn)
#define __file__ __FILE__
#endif
-// trace variables: integer, hex, string, pointer, float, time value, with and w/o new line
-// macro with '_' doesn't prints new line
-// notation:
-// tr = trace
-// v<format> = printf Variable in specified format (d,x,f,s, etc)
-
-#define trla(fmt, args...) tracef("%s:%i %s "fmt,__file__,__LINE__,__FUNCTION__, ## args)
-#define trv(t,v) tracef(#v" = %"t EOL,v)
-#define trv_(t,v) tracef(#v" = %"t" ",v)
-#define trvd(d) trv("d",d)
-#define trvd_(d) trv_("d",d)
-#define trvx_(x) tracef(#x" = 0x%x ",(int)x)
-#define trvx(x) tracef(#x" = 0x%x"EOL,(int)x)
-#define trvlx(x) tracef(#x" = %#llx"EOL,(int)x)
-#define trvX(x) tracef(#x" = %#X"EOL,(int)x)
-#define trvf(f) tracef(#f" = %f"EOL,f)
-#define trvf_(f) tracef(#f" = %f ",f)
-#define trvtv_(tv) tracef(#tv" = %u.%06u ",(unsigned int)tv.tv_sec,(unsigned int)tv.tv_usec)
-#define trvtv(tv) tracef(#tv" = %u.%06u"EOL,(unsigned int)tv.tv_sec,(unsigned int)tv.tv_usec)
-#define trvs(s) tracef(#s" = \"%s\""EOL,s)
-#define trvs_(s) tracef(#s" = \"%s\" ",s)
-#define trvp(p) tracef(#p" = %08x"EOL,(unsigned)p)
-#define trvp_(p) tracef(#p" = %08x ",(unsigned)p)
-#define trvdn(d,n) {int i; tracef("%s",#d"[]=");for (i=0;i<n;i++)tracef("%d:%d,",i,(*((int*)d+i))); tracef(EOL);}
-#define trvxn(d,n) {int i; tracef("%s",#d"[]=");for (i=0;i<n;i++)tracef("%04x,",(*((int*)d+i))); tracef(EOL);}
-#define trvdr(record) trvdn(&record,sizeof(record)/sizeof(int));
-#define trvxr(record) trvxn(&record,sizeof(record)/sizeof(int));
-
-// TRace Digital Variable, if Not Zero
-#define trvdnz(d) { if(d) tracef(#d" = %d"EOL,(int)d); }
-#define trace(a) do { trla("calling %s {\n",#a);a; printk("} done\n"); } while (0)
-
-// trace location, with message
-#define trlm(m) tracef(SOL"%s:%i %s %s"EOL,__file__,__LINE__,__FUNCTION__,m)
-#define trlm_(m) tracef(SOL"%s:%i %s %s ",__file__,__LINE__,__FUNCTION__,m)
+/*
+ trace variables: integer, hex, string, pointer, float, time value, with and w/o new line
+ macro with '_' doesn't prints new line
+ notation:
+ tr = trace
+ v<letter> = printf Variable in specified format (d, x, f, s, etc)
+*/
+
+#define trla(fmt, args...) tracef("%s:%i %s "fmt, __file__, __LINE__, __func__, ## args)
+#define trv(t, v) tracef(#v" = %"t EOL, v)
+#define trv_(t, v) tracef(#v" = %"t" ", v)
+#define trvd(d) trv("d", d)
+#define trvd_(d) trv_("d", d)
+#define trvx_(x) tracef(#x" = 0x%x ", (int)x)
+#define trvx(x) tracef(#x" = 0x%x"EOL, (int)x)
+#define trvlx(x) tracef(#x" = %#llx"EOL, (int)x)
+#define trvX(x) tracef(#x" = %#X"EOL, (int)x)
+#define trvf(f) tracef(#f" = %f"EOL, f)
+#define trvf_(f) tracef(#f" = %f ", f)
+#define trvtv_(tv) tracef(#tv" = %u.%06u ", (unsigned int)tv.tv_sec, (unsigned int)tv.tv_usec)
+#define trvtv(tv) tracef(#tv" = %u.%06u"EOL, (unsigned int)tv.tv_sec, (unsigned int)tv.tv_usec)
+#define trvs(s) tracef(#s" = \"%s\""EOL, s)
+#define trvs_(s) tracef(#s" = \"%s\" ", s)
+#define trvp(p) tracef(#p" = %08x"EOL, (unsigned)p)
+#define trvp_(p) tracef(#p" = %08x ", (unsigned)p)
+#define trvdn(d, n) {int i; tracef("%s", #d"[]="); for (i = 0; i < n; i++) tracef("%d:%d,", i, (*((int *)d+i))); tracef(EOL); }
+#define trvxn(d, n) {int i; tracef("%s", #d"[]="); for (i = 0; i < n; i++) tracef("%04x,", (*((int *)d+i))); tracef(EOL); }
+#define trvdr(record) trvdn(&record, sizeof(record)/sizeof(int));
+#define trvxr(record) trvxn(&record, sizeof(record)/sizeof(int));
+
+/* trvdnz - TRace Digital Variable, if Not Zero */
+#define trvdnz(d) { if (d) tracef(#d" = %d"EOL, (int)d); }
+#define trace(a) do { trla("calling %s {\n", #a); a; printk("} done\n"); } while (0)
+
+/* trlm - TRace Location, with Message */
+#define trlm(m) tracef(SOL"%s:%i %s %s"EOL, __file__, __LINE__, __func__, m)
+#define trlm_(m) tracef(SOL"%s:%i %s %s ", __file__, __LINE__, __func__, m)
#define trl() do { trace_time(); trlm(""); } while (0)
-#define trl_() tracef(SOL"%s:%i %s ",__file__,__LINE__,__FUNCTION__)
+#define trl_() tracef(SOL"%s:%i %s ", __file__, __LINE__, __func__)
#define trln() tracef(EOL)
-#define trl_in() trace_time();trlm("{");
-#define trl_out() trace_time();trlm("}");
-
-#define trace_mem(P,N) \
- IFDBG( { int i=0; tracef("%s=",#P); for (; i < (int)(N) ; i++) \
-{ if (i && ( ! ( i % 16 ))) tracef("%i:",i); \
-tracef("%02x ",0xFF & *((char*)((void*)(P))+i)); \
-if (! ( (i+1) % 4 )) tracef(" "); \
-if (! ( (i+1) % 16 )) tracef(EOL); \
-};tracef(EOL); } )
-
-#define trace_mem_int_list(P,N) \
-IFDBG( { int i=0; for (; i < (int)(N) ; i+= sizeof(int)) \
-{ tracef("%i, ",*(int*)((void*)(P)+i)); \
-};} )
-
-#define trace_mem_int(P,N) \
-IFDBG( { int i=0; for (; i < (int)(N) ; i+= sizeof(int)) \
-{ if ( i && ( ! ( i % 16 ) ) ) tracef("%i:",i); \
-tracef("%x ",*(int*)((void*)(P)+i)); \
-if (! ( (i+1) % 64 )) tracef(EOL); \
-};tracef(EOL); } )
+#define trl_in() do_statement(trace_time(); trlm("{");)
+#define trl_out() do_statement(trace_time(); trlm("}");)
+
+#define trace_mem(P, N) \
+ IFDBG({ int i = 0; tracef("%s=", #P); for (; i < (int)(N) ; i++) \
+{ if (i && (!(i % 16))) tracef("%i:", i); \
+tracef("%02x ", 0xFF & *((char *)((void *)(P))+i)); \
+if (!((i+1) % 4)) \
+ tracef(" "); \
+if (!((i+1) % 16)) \
+ tracef(EOL); \
+}; tracef(EOL); })
+
+#define trace_mem_int_list(P, N) \
+IFDBG({ int i = 0; for (; i < (int)(N); i += sizeof(int)) \
+{ tracef("%i, ", *(int *)((void *)(P)+i)); \
+}; })
+
+#define trace_mem_int(P, N) \
+IFDBG({ int i = 0; for (; i < (int)(N) ; i += sizeof(int)) \
+{ if (i && (!(i % 16))) tracef("%i:", i); \
+tracef("%x ", *(int *)((void *)(P)+i)); \
+if (!((i+1) % 64)) \
+ tracef(EOL); \
+}; tracef(EOL); })
#ifdef TRACE_MALLOC
#define malloc(s) \
- (trla("malloc #%i %p %i\n",++malloc_count,malloc_trace=malloc(s),s),\
+ (trla("malloc #%i %p %i\n", ++malloc_count, malloc_trace = malloc(s), s),\
malloc_trace)
-#define free(p) { free(p); trla("free #%i %p\n",malloc_count--,(void*)p);}
+#define free(p) { free(p); trla("free #%i %p\n", malloc_count--, (void *)p); }
#define strdup(s) \
- (trla("strdup #%i %p\n",++malloc_count,malloc_trace=(void*)strdup(s)),\
- (char*)malloc_trace)
+ (trla("strdup #%i %p\n", ++malloc_count, malloc_trace = (void *)strdup(s)),\
+ (char *)malloc_trace)
#endif
@@ -277,18 +278,14 @@ void static inline trace_time()
time_cur = tv.tv_sec;
time_cur_f = 0.000001 * tv.tv_usec + time_cur;
double passed = time_cur_f - time_prev_f;
- if ( passed > 0.001 )
+ if (passed > 0.001)
{
- //static char time_str[30];
- // like ctime, but with other format
tracef("time=%04d-%02d-%02d %02d:%02d:%02d %02d +%1.4f s\n",
time_tm->tm_year+1900, time_tm->tm_mon+1, time_tm->tm_mday,
- time_tm->tm_hour,time_tm->tm_min,time_tm->tm_sec, (int)tv.tv_usec,
+ time_tm->tm_hour, time_tm->tm_min, time_tm->tm_sec, (int)tv.tv_usec,
passed);
time_prev_f = time_cur_f;
}
- //trvf(time_prev_f);
- //trvf(time_cur_f);
}
*/
#endif
@@ -307,7 +304,7 @@ void static inline trace_time()
#endif
#ifndef stack_trace_difined
#define stack_trace_difined
-// only once
+/* only once */
static inline void stack_trace(void)
{
void *array[5];
@@ -326,60 +323,40 @@ static inline void stack_trace(void)
free(strings);
}
#endif
-#endif // __GLIBC__
+#endif /* __GLIBC__ */
-//#include <linux/kernel.h>
-//#include <linux/mm.h>
-//#include <asm/bitops.h>
-
-//#undef current
-
-/* int static inline freeram()
-{
- struct sysinfo i;
- static unsigned int last;
- si_meminfo(&i);
- trl_();
- //trvi_(last);
- //trvi(nr_free_pages() << PAGE_SHIFT );
- //if (i.freeram - last) {
- trvi_((i.freeram-last));
- trvi(i.freeram); // pages
- //}
- last = i.freeram;
- return i.freeram << 2 ; // K
-} */
#include <linux/kernel.h>
-
-#define freeram() { struct sysinfo i; static unsigned int last; si_meminfo(&i); trl_(); \
+/* see also nr_free_pages */
+#define freeram() { \
+ static unsigned int last; struct sysinfo i; si_meminfo(&i); trl_(); \
int d = last-i.freeram; int used = i.totalram-i.freeram; \
- trvi_(i.freeram);trvi_(used); trvi(d); \
+ trvi_(i.freeram); trvi_(used); trvi(d); \
last = i.freeram; }
#define chkz(a) \
(p = a,\
- ((!p)?tracef("%s %i %s FAIL %i = %s\n",__FILE__,__LINE__,__FUNCTION__,p,#a):0),\
- p)
+ ((!p) ? tracef("%s %i %s FAIL %i = %s\n", __FILE__, __LINE__, __func__, p, #a) : 0),\
+ p)
#define chkn(a) \
(ret = a,\
- ((ret<0)?tracef("%s:%i %s FAIL\n\t%i=%s\n",__FILE__,__LINE__,__FUNCTION__,ret,#a)\
- :0),\
- ret)
+ ((ret < 0) ? tracef("%s:%i %s FAIL\n\t%i=%s\n", __FILE__, __LINE__, __func__, ret, #a)\
+ : 0), ret)
#define chkne(a) \
-( /* tracef("calling %s\n",#a), */ \
- ret = a,\
- ((ret<0)?tracef("%s:%i %s FAIL errno = %i \"%s\" %i = %s\n",__FILE__,__LINE__,__FUNCTION__,errno,strerror(errno),ret,#a)\
- :0),\
- ret)
+(/* tracef("calling %s\n",#a), */ \
+ ret = a,\
+ ((ret < 0) ? tracef("%s:%i %s FAIL errno = %i \"%s\" %i = %s\n", __FILE__, __LINE__, __func__, errno, strerror(errno), ret, #a)\
+ : 0), ret)
#define chkn2(a) \
(ret = a,\
- ((ret<0)?tracef("%s %i %s FAIL %i = %s\n",__FILE__,__LINE__,__FUNCTION__,ret,#a)\
- :tracef("%s %i %s %i = %s\n",__FILE__,__LINE__,__FUNCTION__,ret,#a)),\
- ret)
-#define once(exp) do{static int _passed;if (!_passed){exp;};_passed=1;}while(0)
+ ((ret < 0) ? tracef("%s %i %s FAIL %i = %s\n", __FILE__, __LINE__, __func__, ret, #a)\
+ : tracef("%s %i %s %i = %s\n", __FILE__, __LINE__, __func__, ret, #a)),\
+ ret)
+
+#define once(exp) do_statement( \
+ static int _passed; if (!_passed) {exp; }; _passed = 1;)
static inline void _func_exit(void *l)
{
@@ -388,9 +365,9 @@ static inline void _func_exit(void *l)
tracef("%s }\n", *loc);
}
-#define _trace_enter_exit_() char const *_location __attribute__ (( cleanup (_func_exit) )) = __func__; \
- tracef("%s { ",_location);
+#define _trace_enter_exit_() char const *_location __attribute__ ((cleanup(_func_exit))) = __func__; \
+ tracef("%s { ", _location);
-//__END_DECLS
-#endif // CTRACER_H_INCLUDED
-#endif // __ASSEMBLY__
+/*__END_DECLS */
+#endif /* CTRACER_H_INCLUDED */
+#endif /* __ASSEMBLY__ */
50 dio.c
View
@@ -28,7 +28,7 @@
#include <time.h>
#include <fcntl.h>
#include <assert.h>
-#include <asm/ioctl.h>
+#include <linux/ioctl.h>
static enum io_type {
file_io,
@@ -48,7 +48,9 @@ static int delay;
static char ioctl_type = 'A';
__thread int ret;
-//#define VERBOSE
+/*
+#define VERBOSE
+*/
int output(int dev, void *buf, int size)
{
@@ -125,7 +127,7 @@ int io_start(int dev)
break;
}
if (!data_in_len && !ignore_eof) {
- // read returns 0 on End Of File
+ /* read returns 0 on End Of File */
break;
}
#ifdef VERBOSE
@@ -150,12 +152,12 @@ int io_start(int dev)
break;
}
if (!data_out_len) {
- // EOF, dont extect data from the file any more
- // but wee can continue to write
+ /* EOF, don't expect data from the file any more
+ but wee can continue to write */
pfd[1].events = 0;
}
if (!data_out_len && !ignore_eof) {
- // read returns 0 on End Of File
+ /* read returns 0 on End Of File */
break;
}
write(fileno(stdout), outbuf, data_out_len);
@@ -189,12 +191,12 @@ int io_start(int dev)
}
#define add_literal_option(o) do { options[optnum].name = #o; \
- options[optnum].flag = (void*)&o; options[optnum].has_arg = 1; \
- options[optnum].val = -1; optnum++; } while (0)
+ options[optnum].flag = (void *)&o; options[optnum].has_arg = 1; \
+ options[optnum].val = -1; optnum++; } while (0)
-#define add_flag_option(n,p,v) do { options[optnum].name = n; \
- options[optnum].flag = (void*)p; options[optnum].has_arg = 0; \
- options[optnum].val = v; optnum++; } while (0)
+#define add_flag_option(n, p, v) do { options[optnum].name = n; \
+ options[optnum].flag = (void *)p; options[optnum].has_arg = 0; \
+ options[optnum].val = v; optnum++; } while (0)
static struct option options[100];
int optnum;
@@ -224,33 +226,37 @@ int options_init()
return optnum;
}
-/* expand_arg, return_if_arg_is_equal - utility functions to translate command line parameters
+/*
+ * expand_arg, return_if_arg_is_equal - utility functions
+ * to translate command line parameters
* from string to numeric values using predefined preprocessor defines
*/
-#define return_if_arg_is_equal(entry) if (0 == strcmp(arg,#entry)) return entry
+#define return_if_arg_is_equal(entry) do { if (0 == strcmp(arg, #entry)) return entry; } while (0)
int expand_arg(char *arg)
{
if (!arg)
return 0;
- //return_if_arg_is_equal(SOCK_STREAM);
+/*
+ return_if_arg_is_equal(SOCK_STREAM);
+*/
return strtol(arg, NULL, 0);
}
char *usage = "dio - Device Input/Output utility\n\
Usage:\n\
- dio <options> <device file>\n\
+ dio <options> <device file>\n\
\n\
options:\n\
\n\
default values are marked with '*'\n\
\n\
- -h | --help\n\
- show this help\n\
+ -h | --help\n\
+ show this help\n\
\n\
- --buf_size <n> \n\
- I/O buffer size\n\
+ --buf_size <n> \n\
+ I/O buffer size\n\
\n\
Samples:\n\
\n\
@@ -279,12 +285,10 @@ int init(int argc, char *argv[])
exit(EXIT_FAILURE);
}
}
- if (optind < argc) {
+ if (optind < argc)
dev_name = argv[optind];
- }
- if (io_type == ioctl_io && buf_size >= 1 << _IOC_SIZEBITS) {
+ if (io_type == ioctl_io && buf_size >= 1 << _IOC_SIZEBITS)
fprintf(stderr, "WARNING: size of ioctl data it too big\n");
- }
return 0;
}
6 ldt-test
View
@@ -46,6 +46,7 @@ tracing_stop()
# sudo rmmod parport_pc parport ppdev lp
sudo dmesg -n 7
sudo rmmod ldt ldt_plat_dev 2> /dev/null
+sudo dmesg -c > /dev/null
stty -F /dev/ttyS0 115200
make -s
set -o errexit
@@ -92,6 +93,7 @@ sleep 0.5; echo $data > /dev/ldt;
sleep 0.5
kill %1; wait %1 2> /dev/null || true
received=`cat R.tmp`
+rm -f R.tmp
if [ "$data" == "$received" ]; then
echo -e "${GREEN}LDT blocking read/write test passed$NOCOLOR"
@@ -121,7 +123,7 @@ echo expected $data
echo received $received
fi
-grep ldt /proc/interrupts || true
+#grep ldt /proc/interrupts || true
tracing_stop || true
-sudo dmesg --show-delta --notime --read-clear 2>/dev/null > kernel.log || \
+sudo dmesg --notime --read-clear 2>/dev/null > kernel.log || \
sudo dmesg -c > kernel.log && echo kernel.log saved
100 ldt.c
View
@@ -21,7 +21,7 @@
* tasklet
* timer
* work
- * kthread
+ * kthread
* misc device
* proc fs
* platform_driver and platform_device in another module
@@ -29,7 +29,7 @@
*
*/
-#include <asm/io.h>
+#include <linux/io.h>
#include <linux/mm.h>
#include <linux/interrupt.h>
#include <linux/sched.h>
@@ -50,7 +50,6 @@ static void *in_buf;
static void *out_buf;
static int uart_detected;
-// TODO: move to ldt_platform_device
static int port;
module_param(port, int, 0);
static int port_size;
@@ -63,15 +62,16 @@ static int loopback;
module_param(loopback, int, 0);
/*
- * print_context prints execution context: hard interrupt, soft interrupt or scheduled task
+ * print_context prints execution context:
+ * hard interrupt, soft interrupt or scheduled task
*/
#define print_context() \
- printk(KERN_DEBUG"%s:%d %s %s %x\n", __file__, __LINE__, __func__, \
- in_irq()?"hardirq":current->comm,preempt_count());
+ pr_debug("%s:%d %s %s 0x%x\n", __file__, __LINE__, __func__, \
+ (in_irq() ? "harirq" : current->comm), preempt_count());
#define check(a) \
-( ret=a,((ret<0)?tracef("%s:%i %s FAIL\n\t%i=%s\n",__FILE__,__LINE__,__FUNCTION__,ret,#a):0),ret)
+(ret = a, ((ret < 0) ? tracef("%s:%i %s FAIL\n\t%i=%s\n", __file__, __LINE__, __func__, ret, #a) : 0), ret)
static int isr_counter;
static int ldt_work_counter;
@@ -102,18 +102,14 @@ void ldt_received(void *data, int size)
void ldt_send(void *data, int size)
{
if (uart_detected) {
- if (inb(port + UART_LSR) & UART_LSR_THRE) {
+ if (inb(port + UART_LSR) & UART_LSR_THRE)
outb(*(char *)data, port + UART_TX);
- } else {
+ else
trlm("overflow");
- }
- } else {
- /*
- * emulate loopback
- */
- if (loopback)
- ldt_received(data, size);
- }
+ } else
+ /* emulate loopback */
+ if (loopback)
+ ldt_received(data, size);
}
/*
@@ -182,14 +178,14 @@ irqreturn_t ldt_isr(int irq, void *dev_id, struct pt_regs *regs)
{
_entry:
/*
- * UART interrupt is not called on loopback mode, therefore fire ldt_tasklet from timer too
+ * UART interrupt is not fired in loopback mode,
+ * therefore fire ldt_tasklet from timer too
*/
once(print_context());
isr_counter++;
trl_();
trvx(inb(port + UART_IIR));
tasklet_schedule(&ldt_tasklet);
- //return IRQ_NONE; /* not our IRQ */
return IRQ_HANDLED; /* our IRQ */
}
@@ -202,7 +198,8 @@ void ldt_timer_func(unsigned long data)
{
_entry:
/*
- * this timer is used just to fire ldt_tasklet, when there is no interrupt in loopback mode
+ * this timer is used just to fire ldt_tasklet,
+ * when there is no interrupt in loopback mode
*/
if (loopback)
tasklet_schedule(&ldt_tasklet);
@@ -237,12 +234,11 @@ static int ldt_release(struct inode *inode, struct file *file)
static DEFINE_MUTEX(read_lock);
-static ssize_t ldt_read(struct file *file, char __user * buf, size_t count, loff_t * ppos)
+static ssize_t ldt_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
{
int ret;
unsigned int copied;
_entry:
- // TODO: implement blocking I/O
if (kfifo_is_empty(&in_fifo)) {
if (file->f_flags & O_NONBLOCK) {
ret = -EAGAIN;
@@ -273,15 +269,14 @@ static ssize_t ldt_read(struct file *file, char __user * buf, size_t count, loff
static DEFINE_MUTEX(write_lock);
-static ssize_t ldt_write(struct file *file, const char __user * buf, size_t count, loff_t * ppos)
+static ssize_t ldt_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
{
int ret;
unsigned int copied;
_entry:
- // TODO wait_event_interruptible ... ldt_writeable
- if (mutex_lock_interruptible(&write_lock)) {
+ /* TODO: wait_event_interruptible ... ldt_writeable */
+ if (mutex_lock_interruptible(&write_lock))
return -EINTR;
- }
ret = kfifo_from_user(&out_fifo, buf, count, &copied);
mutex_unlock(&write_lock);
tasklet_schedule(&ldt_tasklet);
@@ -292,19 +287,20 @@ static ssize_t ldt_write(struct file *file, const char __user * buf, size_t coun
* polling
*/
-static unsigned int ldt_poll(struct file *file, poll_table * pt)
+static unsigned int ldt_poll(struct file *file, poll_table *pt)
{
unsigned int mask = 0;
_entry:
poll_wait(file, &ldt_readable, pt);
- //poll_wait(file, ldt_writeable, pt); // TODO
+ /*poll_wait(file, ldt_writeable, pt); TODO */
- if (!kfifo_is_empty(&in_fifo)) {
+ if (!kfifo_is_empty(&in_fifo))
mask |= POLLIN | POLLRDNORM;
- }
mask |= POLLOUT | POLLWRNORM;
- //mask |= POLLHUP; // on output eof
- //mask |= POLLERR; // on output error
+#if 0
+ mask |= POLLHUP; /* on output eof */
+ mask |= POLLERR; /* on output error */
+#endif
trl_();
trvx(mask);
return mask;
@@ -378,7 +374,7 @@ long ldt_ioctl(struct file *f, unsigned int cmnd, unsigned long arg)
return 0;
}
-struct file_operations ldt_fops = {
+static const struct file_operations ldt_fops = {
.owner = THIS_MODULE,
.open = ldt_open,
.release = ldt_release,
@@ -448,7 +444,7 @@ int uart_probe(void)
trvx(inb(port + UART_MSR));
if (uart_detected) {
- //outb(UART_IER_MSI | UART_IER_THRI | UART_IER_RDI | UART_IER_RLSI, port + UART_IER);
+ /*outb(UART_IER_MSI | UART_IER_THRI | UART_IER_RDI | UART_IER_RLSI, port + UART_IER); */
outb(UART_IER_RDI | UART_IER_RLSI | UART_IER_THRI, port + UART_IER);
outb(UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2, port + UART_MCR);
outb(UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT, port + UART_FCR);
@@ -456,10 +452,8 @@ int uart_probe(void)
if (loopback)
outb(inb(port + UART_MCR) | UART_MCR_LOOP, port + UART_MCR);
}
- if (!uart_detected && loopback) {
- printk(KERN_WARNING "Emulating loopback is software\n");
- }
-
+ if (!uart_detected && loopback)
+ pr_warn("Emulating loopback is software\n");
}
trvx(uart_detected);
trvx_(inb(port + UART_IER));
@@ -496,23 +490,23 @@ static __devinit int ldt_probe(struct platform_device *pdev)
trvd_(irq);
trvd_(bufsize);
trln();
- if (!(in_buf = alloc_pages_exact(bufsize, GFP_KERNEL | __GFP_ZERO))) {
+ in_buf = alloc_pages_exact(bufsize, GFP_KERNEL | __GFP_ZERO);
+ if (!in_buf) {
ret = -ENOMEM;
goto exit;
}
pages_flag(virt_to_page(in_buf), PFN_UP(bufsize), PG_reserved, 1);
- if (!(out_buf = alloc_pages_exact(bufsize, GFP_KERNEL | __GFP_ZERO))) {
+ out_buf = alloc_pages_exact(bufsize, GFP_KERNEL | __GFP_ZERO);
+ if (!out_buf) {
ret = -ENOMEM;
goto exit;
}
pages_flag(virt_to_page(out_buf), PFN_UP(bufsize), PG_reserved, 1);
- //ret = register_chrdev (0, KBUILD_MODNAME, &ldt_fops);
if (pdev) {
data = pdev->dev.platform_data;
r = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
- if (r && !irq) {
+ if (r && !irq)
irq = r->start;
- }
r = platform_get_resource(pdev, IORESOURCE_IO, 0);
if (r && !port)
port = r->start;
@@ -522,8 +516,10 @@ static __devinit int ldt_probe(struct platform_device *pdev)
}
trvp(data);
trvs(data);
+#if 0
+ ret = register_chrdev(0, KBUILD_MODNAME, &ldt_fops);
+#endif
ret = check(misc_register(&ldt_miscdev));
- //ret = check(register_chrdev (0, KBUILD_MODNAME, &ldt_fops));
if (ret < 0)
goto exit;
trvd(ldt_miscdev.minor);
@@ -532,9 +528,8 @@ static __devinit int ldt_probe(struct platform_device *pdev)
proc_create(KBUILD_MODNAME, 0, NULL, &ldt_fops);
mod_timer(&ldt_timer, jiffies + HZ / 10);
thread = kthread_run(ldt_thread, NULL, "%s", KBUILD_MODNAME);
- if (IS_ERR(thread)) {
+ if (IS_ERR(thread))
ret = PTR_ERR(thread);
- }
exit:
trl_();
trvd(ret);
@@ -556,9 +551,8 @@ static int __devexit ldt_remove(struct platform_device *pdev)
kthread_stop(thread);
}
del_timer(&ldt_timer);
- if (port_r) {
+ if (port_r)
release_region(port, port_size);
- }
if (irq) {
outb(0, port + UART_IER);
outb(0, port + UART_FCR);
@@ -598,7 +592,8 @@ module_platform_driver(ldt_driver);
#else
/*
- * for Linux kernel releases before v3.1-12 without macro module_platform_driver
+ * for Linux kernel releases before v3.1-12
+ * without macro module_platform_driver
*/
static int ldt_init(void)
@@ -617,9 +612,9 @@ static void ldt_exit(void)
module_init(ldt_init);
module_exit(ldt_exit);
-#endif // module_platform_driver
+#endif /* module_platform_driver */
-#else // ! USE_PLATFORM_DEVICE
+#else /* !USE_PLATFORM_DEVICE */
/*
* Standalone module initialization to run without platform_device
@@ -630,7 +625,8 @@ static int ldt_init(void)
int ret = 0;
_entry:
/*
- * Call probe function directly, bypassing platform_device infrastructure
+ * Call probe function directly,
+ * bypassing platform_device infrastructure
*/
ret = ldt_probe(NULL);
return ret;
2  ldt_plat_dev.c
View
@@ -1,6 +1,6 @@
/*
* LDT - Linux Driver Template
- *
+ *
* Copyright (C) 2012 Constantine Shulyupin http://www.makelinux.net/
*
* Dual BSD/GPL License
2  ldt_plat_drv.c
View
@@ -1,6 +1,6 @@
/*
* LDT - Linux Driver Template
- *
+ *
* Copyright (C) 2012 Constantine Shulyupin http://www.makelinux.net/
*
* Dual BSD/GPL License
Please sign in to comment.
Something went wrong with that request. Please try again.