bitblt function

bitblt function

--- games/dgjamfall2020/codenamesunfish3d/game/game.c
+++ games/dgjamfall2020/codenamesunfish3d/game/game.c
@@ -45,7 +45,8 @@
     SEQCL_CALLBACK,                                     /* 4   callback */

     SEQCL_TEXT,                                         /* 5   text */
-    SEQCL_MAX                                           /* 6   */
+    SEQCL_BITBLT,                                       /* 6   bitblt (copy one VRAM location to another) */
+    SEQCL_MAX                                           /* 7   */
 };

 union seqcanvas_layeru_t;
@@ -95,12 +96,22 @@
     unsigned char                   color;
 };

+/* in unchained 256-color mode, VGA write mode 1 and copying from offscreen RAM can be an efficient means to bitblt (4 pixels at once per R/W!) */
+struct seqcanvas_bitblt {
+    uint16_t                        src,dst;            /* src, dest video ram locations. This is unchained 256-color mode, therefore multiple of 4 pixels */
+    uint16_t                        length;             /* how much to copy per row (4-pixel planar byte) */
+    uint16_t                        src_step;           /* source stride for copy (4-pixel planar byte) */
+    uint16_t                        dst_step;           /* dest stride for copy (4-pixel planar byte) */
+    uint16_t                        rows;               /* rows */
+};
+
 union seqcanvas_layeru_t {
     struct seqcanvas_memsetfill     msetfill;           /* memset (solid color) */
     struct seqcanvas_rotozoom       rotozoom;           /* draw a rotozoomer */
     struct seqcanvas_vrl            vrl;                /* draw VRL image */
     struct seqcanvas_callback       callback;           /* callback function */
     struct seqcanvas_text           text;               /* draw text */
+    struct seqcanvas_bitblt         bitblt;             /* bitblt (copy VRAM to another VRAM location) */
 };

 struct seqcanvas_layer_t {
@@ -563,6 +574,26 @@
     }
 }

+void seqanim_draw_canvasobj_bitblt(struct seqanim_t *sa,struct seqcanvas_layer_t *cl) {
+    const uint16_t sst = cl->rop.bitblt.src_step;
+    const uint16_t dst = cl->rop.bitblt.dst_step;
+    const uint16_t len = cl->rop.bitblt.length;
+    uint16_t rc = cl->rop.bitblt.rows;
+    uint16_t s = cl->rop.bitblt.src;
+    uint16_t d = cl->rop.bitblt.dst;
+
+    (void)sa;
+
+    vga_write_sequencer(0x02/*map mask*/,0xF);
+    vga_setup_wm1_block_copy();
+    while (rc-- != 0u) {
+        vga_wm1_mem_block_copy(d,s,len);
+        s += sst;
+        d += dst;
+    }
+    vga_restore_rm0wm0();
+}
+
 void seqanim_draw_canvasobj(struct seqanim_t *sa,struct seqcanvas_layer_t *cl) {
     switch (cl->what) {
         case SEQCL_MSETFILL:
@@ -580,6 +611,9 @@
             break;
         case SEQCL_TEXT:
             seqanim_draw_canvasobj_text(sa,cl);
+            break;
+        case SEQCL_BITBLT:
+            seqanim_draw_canvasobj_bitblt(sa,cl);
             break;
         case SEQCL_NONE:
         default:


Added virtual IsVersion

Added virtual IsVersion

--- PHOS/AliPHOS.h
+++ PHOS/AliPHOS.h
@@ -45,12 +45,13 @@
     assert(0==1) ;
   }
   virtual void   AddHit( Int_t shunt, Int_t primary, Int_t track, Int_t id, Float_t *hits ) = 0 ;
-  virtual  void  CreateMaterials() ;
+  virtual void   CreateMaterials() ;
   virtual  AliPHOSRecPoint::RecPointsList *  EmcRecPoints() {
     // Getting list of RecPoints
     return fEmcRecPoints ;
   }
-  virtual  AliPHOSGeometry * GetGeometry() = 0 ;
+  virtual  AliPHOSGeometry * GetGeometry() = 0 ;
+  virtual Int_t   IsVersion(void) const { return -1 ; }
   virtual  AliPHOSRecPoint::RecPointsList * PpsdRecPoints() {
     // to be redefined when ppsd is present
     return 0 ;


put shared buffer for Cumulated Sum in specific header file

error: pathspec 'eesupp/inc/CUMULSUM.h' did not match any file(s) known to git

--- eesupp/inc/CUMULSUM.h
+++ eesupp/inc/CUMULSUM.h
@@ -0,0 +1,24 @@
+C $Header$
+C $Name$
+CBOP
+C     !ROUTINE: CUMULSUM.h
+C     !INTERFACE:
+C     include "CUMULSUM.h"
+C     !DESCRIPTION:
+C     *==========================================================*
+C     | CUMULSUM.h
+C     | o Globals used by Fortran CUMULSUM\_TILE routine.
+C     *==========================================================*
+C     *==========================================================*
+CEOP
+
+C     shareBufCS2_R8 :: holds tile increment along X direction (1rst index=1)
+C                       and along Y direction (1rst index=2) (CUMULSUM input)
+C     shareBufCS1_R8 :: holds tile cumulated sum at tile origin (i,j)=1,1
+      COMMON  / CUMULSUM_R8 /  shareBufCS1_R8, shareBufCS2_R8
+      Real*8  shareBufCS1_R8  (nSx,nSy)
+      Real*8  shareBufCS2_R8(2,nSx,nSy)
+
+CEH3 ;;; Local Variables: ***
+CEH3 ;;; mode:fortran ***
+CEH3 ;;; End: ***


refact

refact

--- src/NiblackBinarization.h
+++ src/NiblackBinarization.h
@@ -14,7 +14,7 @@

     inline void NiblackBinarization::Binarize(cv::Mat &src, cv::Mat &dst, double kernelSize, double k = -0.2)
     {
-        if (kernelSize <= 2)
+        if (kernelSize < 3)
             throw std::invalid_argument("kernelSize should be >= 3.");

         if (src.type() != CV_8UC1)
@@ -29,6 +29,8 @@

         dst = cv::Mat(src.rows, src.cols, CV_8UC1);
         auto kernelArea = (double)(kernelSize*kernelSize);
+        auto invKernelArea = 1.0 / kernelArea;
+
         for (auto i = 0; i < dst.rows; i++)
         {
             auto *pTl = sum.ptr<int>(i);
@@ -49,10 +51,11 @@
                 auto sumValue = *pBr + *pTl - *pBl - *pTr;
                 auto sqSumValue = *pBr2 + *pTl2 - *pBl2 - *pTr2;

-                // TODO:speedup
-                auto mean = sumValue / kernelArea;
-                auto th = mean + k * sqrt(sqSumValue / kernelArea - mean * mean);

+                auto mean = sumValue *invKernelArea;
+                auto sigma = sqSumValue * invKernelArea - mean * mean;
+                sigma = sigma < 0.0 ? 0.0 : sqrt(sigma);
+                auto th = mean + k * sigma;
                 *pDst = double(*pSrc) > th ? 255U : 0U;

                 pTl++;
@@ -70,6 +73,5 @@

         return;
     }
-
 }
 #endif // _NIBLACK_BINARIZATION_H_


Fix commit 29e4529

Fix commit 29e4529

More uses of GLhandleARB had been added into the newer glext.h,
they must be removed.

--- src/OpenGl/OpenGl_glext.h
+++ src/OpenGl/OpenGl_glext.h
@@ -4194,14 +4194,6 @@
 #define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB 0x8B4D
 #define GL_OBJECT_ACTIVE_ATTRIBUTES_ARB   0x8B89
 #define GL_OBJECT_ACTIVE_ATTRIBUTE_MAX_LENGTH_ARB 0x8B8A
-typedef void (APIENTRYP PFNGLBINDATTRIBLOCATIONARBPROC) (GLhandleARB programObj, GLuint index, const GLcharARB *name);
-typedef void (APIENTRYP PFNGLGETACTIVEATTRIBARBPROC) (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name);
-typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONARBPROC) (GLhandleARB programObj, const GLcharARB *name);
-#ifdef GL_GLEXT_PROTOTYPES
-GLAPI void APIENTRY glBindAttribLocationARB (GLhandleARB programObj, GLuint index, const GLcharARB *name);
-GLAPI void APIENTRY glGetActiveAttribARB (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name);
-GLAPI GLint APIENTRY glGetAttribLocationARB (GLhandleARB programObj, const GLcharARB *name);
-#endif
 #endif /* GL_ARB_vertex_shader */

 #ifndef GL_ARB_vertex_type_10f_11f_11f_rev


Like sh_types, dt_tags just aren't in consecutive order, so we have to move away from indexing into an array.  Also add Sun and GNU specific tags.

--- usr.bin/elfdump/elfdump.c
+++ usr.bin/elfdump/elfdump.c
@@ -162,12 +162,78 @@
 	offsetof(Elf64_Rela, r_addend)
 };

-char *d_tags[] = {
-	"DT_NULL", "DT_NEEDED", "DT_PLTRELSZ", "DT_PLTGOT", "DT_HASH",
-	"DT_STRTAB", "DT_SYMTAB", "DT_RELA", "DT_RELASZ", "DT_RELAENT",
-	"DT_STRSZ", "DT_SYMENT", "DT_INIT", "DT_FINI", "DT_SONAME",
-	"DT_RPATH", "DT_SYMBOLIC", "DT_REL", "DT_RELSZ", "DT_RELENT",
-	"DT_PLTREL", "DT_DEBUG", "DT_TEXTREL", "DT_JMPREL"
+/* http://www.sco.com/developers/gabi/latest/ch5.dynamic.html#tag_encodings */
+const char *
+d_tags(u_int64_t tag) {
+	switch (tag) {
+	case 0: return "DT_NULL";
+	case 1: return "DT_NEEDED";
+	case 2: return "DT_PLTRELSZ";
+	case 3: return "DT_PLTGOT";
+	case 4: return "DT_HASH";
+	case 5: return "DT_STRTAB";
+	case 6: return "DT_SYMTAB";
+	case 7: return "DT_RELA";
+	case 8: return "DT_RELASZ";
+	case 9: return "DT_RELAENT";
+	case 10: return "DT_STRSZ";
+	case 11: return "DT_SYMENT";
+	case 12: return "DT_INIT";
+	case 13: return "DT_FINI";
+	case 14: return "DT_SONAME";
+	case 15: return "DT_RPATH";
+	case 16: return "DT_SYMBOLIC";
+	case 17: return "DT_REL";
+	case 18: return "DT_RELSZ";
+	case 19: return "DT_RELENT";
+	case 20: return "DT_PLTREL";
+	case 21: return "DT_DEBUG";
+	case 22: return "DT_TEXTREL";
+	case 23: return "DT_JMPREL";
+	case 24: return "DT_BIND_NOW";
+	case 25: return "DT_INIT_ARRAY";
+	case 26: return "DT_FINI_ARRAY";
+	case 27: return "DT_INIT_ARRAYSZ";
+	case 28: return "DT_FINI_ARRAYSZ";
+	case 29: return "DT_RUNPATH";
+	case 30: return "DT_FLAGS";
+	case 32: return "DT_PREINIT_ARRAY"; /* XXX: DT_ENCODING */
+	case 33: return "DT_PREINIT_ARRAYSZ";
+	/* 0x6000000D - 0x6ffff000 operating system-specific semantics */
+	case 0x6ffffdf5: return "DT_GNU_PRELINKED";
+	case 0x6ffffdf6: return "DT_GNU_CONFLICTSZ";
+	case 0x6ffffdf7: return "DT_GNU_LIBLISTSZ";
+	case 0x6ffffdf8: return "DT_SUNW_CHECKSUM";
+	case 0x6ffffdf9: return "DT_PLTPADSZ";
+	case 0x6ffffdfa: return "DT_MOVEENT";
+	case 0x6ffffdfb: return "DT_MOVESZ";
+	case 0x6ffffdfc: return "DT_FEATURE";
+	case 0x6ffffdfd: return "DT_POSFLAG_1";
+	case 0x6ffffdfe: return "DT_SYMINSZ";
+	case 0x6ffffdff: return "DT_SYMINENT (DT_VALRNGHI)";
+	case 0x6ffffe00: return "DT_ADDRRNGLO";
+	case 0x6ffffef8: return "DT_GNU_CONFLICT";
+	case 0x6ffffef9: return "DT_GNU_LIBLIST";
+	case 0x6ffffefa: return "DT_SUNW_CONFIG";
+	case 0x6ffffefb: return "DT_SUNW_DEPAUDIT";
+	case 0x6ffffefc: return "DT_SUNW_AUDIT";
+	case 0x6ffffefd: return "DT_SUNW_PLTPAD";
+	case 0x6ffffefe: return "DT_SUNW_MOVETAB";
+	case 0x6ffffeff: return "DT_SYMINFO (DT_ADDRRNGHI)";
+	case 0x6ffffff9: return "DT_RELACOUNT";
+	case 0x6ffffffa: return "DT_RELCOUNT";
+	case 0x6ffffffb: return "DT_FLAGS_1";
+	case 0x6ffffffc: return "DT_VERDEF";
+	case 0x6ffffffd: return "DT_VERDEFNUM";
+	case 0x6ffffffe: return "DT_VERNEED";
+	case 0x6fffffff: return "DT_VERNEEDNUM";
+	case 0x6ffffff0: return "DT_GNU_VERSYM";
+	/* 0x70000000 - 0x7fffffff processor-specific semantics */
+	case 0x7ffffffd: return "DT_SUNW_AUXILIARY";
+	case 0x7ffffffe: return "DT_SUNW_USED";
+	case 0x7fffffff: return "DT_SUNW_FILTER";
+	default: return "ERROR: TAG NOT DEFINED";
+	}
 };

 char *e_machines[] = {
@@ -209,8 +275,8 @@
 };

 /* http://www.sco.com/developers/gabi/latest/ch4.sheader.html#sh_type */
-const char
-*sh_types(u_int64_t sht) {
+const char *
+sh_types(u_int64_t sht) {
 	switch (sht) {
 	case 0:	return "SHT_NULL";
 	case 1: return "SHT_PROGBITS";
@@ -229,14 +295,17 @@
 	case 16: return "SHT_PREINIT_ARRAY";
 	case 17: return "SHT_GROUP";
 	case 18: return "SHT_SYMTAB_SHNDX";
+	/* 0x60000000 - 0x6fffffff operating system-specific semantics */
 	case 0x6ffffff0: return "XXX:VERSYM";
 	case 0x6ffffff7: return "SHT_GNU_LIBLIST";
 	case 0x6ffffffc: return "XXX:VERDEF";
 	case 0x6ffffffd: return "SHT_SUNW(GNU)_verdef";
 	case 0x6ffffffe: return "SHT_SUNW(GNU)_verneed";
 	case 0x6fffffff: return "SHT_SUNW(GNU)_versym";
+	/* 0x70000000 - 0x7fffffff processor-specific semantics */
 	case 0x7ffffffd: return "XXX:AUXILIARY";
 	case 0x7fffffff: return "XXX:FILTER";
+	/* 0x80000000 - 0xffffffff application programs */
 	default: return "ERROR: SHT NOT DEFINED";
 	}
 };
@@ -663,7 +732,7 @@
 		val = elf_get_addr(e, d, D_VAL);
 		fprintf(out, "\n");
 		fprintf(out, "entry: %d\n", i);
-		fprintf(out, "\td_tag: %s\n", d_tags[tag]);
+		fprintf(out, "\td_tag: %s\n", d_tags(tag));
 		switch (tag) {
 		case DT_NEEDED:
 		case DT_SONAME:


eek, how did that happen?  I must have committed something left over from when I was experimenting looking for an alternate format.  *blush*

--- bin/sh/miscbltin.c
+++ bin/sh/miscbltin.c
@@ -33,7 +33,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- *	$Id: miscbltin.c,v 1.6 1996/09/03 13:35:10 peter Exp $
+ *	$Id: miscbltin.c,v 1.7 1996/09/03 14:15:54 peter Exp $
  */

 #ifndef lint
@@ -356,11 +356,11 @@

 			if (l->units)
 				snprintf(optbuf, sizeof(optbuf),
-					"%s (%s, -%c) ", l->name, l->units, l->option);
+					"(%s, -%c) ", l->units, l->option);
 			else
 				snprintf(optbuf, sizeof(optbuf),
-					"%s (-%c) ", l->name, l->option);
-			out1fmt("%32s ", optbuf);
+					"(-%c) ", l->option);
+			out1fmt("%-18s %18s ", l->name, optbuf);
 			if (val == RLIM_INFINITY)
 				out1fmt("unlimited\n");
 			else


Added check for endianness for the Android platform

git-svn-id: 5398946ba177a3e438c2dae55e2cdfc2fb96c905@2957 a9d63959-f2ad-4865-b262-bf0e56cfafb6

--- common/include/sensor_msgs/PointCloud2.h
+++ common/include/sensor_msgs/PointCloud2.h
@@ -14,7 +14,8 @@
 #if (defined(__powerpc) || defined(__powerpc__) || defined(__POWERPC__) || defined(__ppc__) || defined(_M_PPC) || defined(__ARCH_PPC))
 #  define PCL_BIG_ENDIAN
 #elif (defined(i386) || defined(__i386__) || defined(__i386) || defined(_M_IX86) || defined(_X86_) || defined(__THW_INTEL__) || defined(__I86__) || defined(__INTEL__)) \
-  || (defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_X64))
+  || (defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_X64)) \
+	|| (defined(__ANDROID__))
 #  define PCL_LITTLE_ENDIAN
 #else
 #  error


ppb_graphics3d: add GLX defines for texture_from_pixmap extension

--- src/compat_glx_defines.h
+++ src/compat_glx_defines.h
@@ -36,5 +36,45 @@
 #define GLX_CONTEXT_ES_PROFILE_BIT_EXT          0x00000004
 #define GLX_CONTEXT_ES2_PROFILE_BIT_EXT         0x00000004

+// https://www.opengl.org/registry/specs/EXT/texture_from_pixmap.txt
+#define GLX_BIND_TO_TEXTURE_RGB_EXT        0x20D0
+#define GLX_BIND_TO_TEXTURE_RGBA_EXT       0x20D1
+#define GLX_BIND_TO_MIPMAP_TEXTURE_EXT     0x20D2
+#define GLX_BIND_TO_TEXTURE_TARGETS_EXT    0x20D3
+#define GLX_Y_INVERTED_EXT                 0x20D4
+
+#define GLX_TEXTURE_FORMAT_EXT             0x20D5
+#define GLX_TEXTURE_TARGET_EXT             0x20D6
+#define GLX_MIPMAP_TEXTURE_EXT             0x20D7
+
+#define GLX_TEXTURE_FORMAT_NONE_EXT        0x20D8
+#define GLX_TEXTURE_FORMAT_RGB_EXT         0x20D9
+#define GLX_TEXTURE_FORMAT_RGBA_EXT        0x20DA
+
+#define GLX_TEXTURE_1D_BIT_EXT             0x00000001
+#define GLX_TEXTURE_2D_BIT_EXT             0x00000002
+#define GLX_TEXTURE_RECTANGLE_BIT_EXT      0x00000004
+
+#define GLX_TEXTURE_1D_EXT                 0x20DB
+#define GLX_TEXTURE_2D_EXT                 0x20DC
+#define GLX_TEXTURE_RECTANGLE_EXT          0x20DD
+
+#define GLX_FRONT_LEFT_EXT                 0x20DE
+#define GLX_FRONT_RIGHT_EXT                0x20DF
+#define GLX_BACK_LEFT_EXT                  0x20E0
+#define GLX_BACK_RIGHT_EXT                 0x20E1
+#define GLX_FRONT_EXT                      GLX_FRONT_LEFT_EXT
+#define GLX_BACK_EXT                       GLX_BACK_LEFT_EXT
+#define GLX_AUX0_EXT                       0x20E2
+#define GLX_AUX1_EXT                       0x20E3
+#define GLX_AUX2_EXT                       0x20E4
+#define GLX_AUX3_EXT                       0x20E5
+#define GLX_AUX4_EXT                       0x20E6
+#define GLX_AUX5_EXT                       0x20E7
+#define GLX_AUX6_EXT                       0x20E8
+#define GLX_AUX7_EXT                       0x20E9
+#define GLX_AUX8_EXT                       0x20EA
+#define GLX_AUX9_EXT                       0x20EB
+

 #endif // FPP_COMPAT_GLX_DEFINES_H


Fix switch-case statement (#91)

Fix switch-case statement (#91)

Does not appear to affect any code in active use.

--- src/compiler/codegen_c.h
+++ src/compiler/codegen_c.h
@@ -296,8 +296,10 @@
         break;
     case fb_double:
         suffix = "";
+        break;
     case fb_float:
         suffix = "F";
+        break;
     default:
         gen_panic(0, "internal error: unexpected type during code generation");
         suffix = "";


usb_mux/amd_fp6: Handle chipset_reset

usb_mux/amd_fp6: Handle chipset_reset

The driver was only handling chipset_resume. chipset_reset also needs to
be handled. Otherwise mux won't be set on an apreset.

BUG=None
TEST=C1 display works after apreset
BRANCH=None

Signed-off-by: Rob Barnes <3ced0940a2329ce70499686f01d3d60685ec66ed@google.com>
Change-Id: I0ec336a733e51d44be7ea95f8fcfeb8a606d50a1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2845269
Reviewed-by: Diana Z <cb2016afc7183e5356c690dc63b4ba817470501a@chromium.org>

--- driver/usb_mux/amd_fp6.c
+++ driver/usb_mux/amd_fp6.c
@@ -216,8 +216,14 @@
 }
 DECLARE_HOOK(HOOK_CHIPSET_RESUME, amd_fp6_chipset_resume, HOOK_PRIO_DEFAULT);

+static int amd_fp6_chipset_reset(const struct usb_mux *me)
+{
+	amd_fp6_chipset_resume();
+	return EC_SUCCESS;
+}
+
 const struct usb_mux_driver amd_fp6_usb_mux_driver = {
 	.set = &amd_fp6_set_mux,
 	.get = &amd_fp6_get_mux,
-	/* .chipset_reset is handled by amd_fp6_chipset_resume hook */
+	.chipset_reset = &amd_fp6_chipset_reset
 };


ACPI: asus_acpi: don't printk on writing garbage to proc files

This reporting is useless (we errno anyway).

Signed-off-by: Alexey Dobriyan <b99bff5923d24d2fb8e844db9dac7cd59203da1d@gmail.com>
Signed-off-by: Andrew Morton <5c1e68b099950c134891f0b6e179498a8ebe9cf9@osdl.org>
Signed-off-by: Len Brown <b060cfa1096cc6e8be83699ddb4ed8a77dd63af5@intel.com>

--- drivers/acpi/asus_acpi.c
+++ drivers/acpi/asus_acpi.c
@@ -629,9 +629,7 @@
 			       "Asus ACPI: LED display write failed\n");
 		else
 			hotk->ledd_status = (u32) value;
-	} else if (rv < 0)
-		printk(KERN_WARNING "Asus ACPI: Error reading user input\n");
-
+	}
 	return rv;
 }

@@ -849,10 +847,7 @@
 		value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
 		/* 0 <= value <= 15 */
 		set_brightness(value);
-	} else if (rv < 0) {
-		printk(KERN_WARNING "Asus ACPI: Error reading user input\n");
-	}
-
+	}
 	return rv;
 }

@@ -897,9 +892,6 @@
 	rv = parse_arg(buffer, count, &value);
 	if (rv > 0)
 		set_display(value);
-	else if (rv < 0)
-		printk(KERN_WARNING "Asus ACPI: Error reading user input\n");
-
 	return rv;
 }


ata: ahci_mvebu: add suspend/resume support

This commit adds suspend/resume support to the ahci_mvebu driver. The
suspend hook doesn't do anything special despite calling the generic
ahci_platform_suspend_host() function. However, the resume hook has to
restore the MBus windows configuration, as well as the regret option.

Tested on Marvell Armada 388 GP.

Signed-off-by: Thomas Petazzoni <a5d87d2bd7c424ee5cbdb4e978635bf653d5a005@free-electrons.com>
Signed-off-by: Tejun Heo <546b05909706652891a87f7bfe385ae147f61f91@kernel.org>


null_blk: Cleanup error recovery in null_add_dev()

When creation of queues fails in init_driver_queues(), we free the
queues. But null_add_dev() doesn't test for this failure and continues
with the setup leading to strange consequences, likely oops. Fix the
problem by testing whether init_driver_queues() failed and do proper
error cleanup.

Coverity-id: 1148005
Signed-off-by: Jan Kara <596727c8a0ea4db3ba2ceceedccbacd3d7b371b8@suse.cz>
Signed-off-by: Jens Axboe <cd8c6775e60d6f67a6984377324e5290df3d5358@fb.com>


Update the code that computes the acceptance ratio.

--- include/sampleflow/consumers/acceptance_ratio.h
+++ include/sampleflow/consumers/acceptance_ratio.h
@@ -19,6 +19,7 @@
 #include <sampleflow/consumer.h>
 #include <sampleflow/types.h>
 #include <mutex>
+#include <valarray>

 namespace SampleFlow
 {
@@ -29,8 +30,6 @@
      * over all samples seen so far. The last value so computed can be
      * obtained by calling the get() function.
      *
-     * This code works if our sample have the form of vector.
-     *
      * The concept of acceptance/rejection of a sample is explained in the documentation of
      * the Producers::MetropolisHastings class. This calculation uses the
      * assumption that every *accepted* sample in the sampling algorithm is *different* from last one.
@@ -48,7 +47,9 @@
      * @tparam InputType The C++ type used for the samples $x_k$. All this class requires of
      *    the data type is that the comparison operator between two objects returns a `bool`. This
      *    is true for most classes, but not all. (For example, `std::valarray` returns a vector of
-     *    bool values.)
+     *    bool values; however, this class makes sure this works nonetheless by
+     *    working around this restriction for this particular
+     *    class.)
      */
     template <typename InputType>
     class AcceptanceRatio : public Consumer<InputType>
@@ -99,7 +100,7 @@
          * The current value of accepted values as described in the introduction
          * of this class.
          */
-        types::sample_index accept;
+        types::sample_index n_accepted_samples;

         /**
          * The number of samples processed so far.
@@ -121,8 +122,54 @@
     AcceptanceRatio ()
       :
       n_samples (0),
-      accept (0)
+      n_accepted_samples (0)
     {}
+
+
+    namespace internal
+    {
+      namespace AcceptanceRatio
+      {
+        /**
+         * A function that compares two objects of arbitrary type for
+         * equality. It does so by using `operator==`.
+         *
+         * There are specializations of this function below that are used
+         * for certain types for which `operator==` does not, in fact,
+         * return a single boolean.
+         */
+        template <typename T>
+        bool is_equal (const T &t1,
+                       const T &t2)
+        {
+          return (t1==t2);
+        }
+
+
+        /**
+         * A function that compares two `std::valarray` objects for
+         * equality. This function works around the fact that `std::valarray`'s
+         * `operator==` doesn't just return a single boolean, but in fact
+         * a `std::valarray<bool>` -- for reasons that are probably lost
+         * to history given how bad a choice that is.
+         */
+        template <typename T>
+        bool is_equal (const std::valarray<T> &t1,
+                       const std::valarray<T> &t2)
+        {
+          if (t1.size() != t2.size())
+            return false;
+
+          for (unsigned int i=0; i<t1.size(); ++i)
+            if (t1[i] != t2[i])
+              return false;
+
+          return true;
+        }
+
+      }
+    }
+

     template <typename InputType>
@@ -135,28 +182,32 @@
       // If this is the first sample we see, naturally, this sample is accepted.
       if (n_samples == 0)
         {
-          n_samples=1;
-          accept=1;
-          previous_sample = sample;
-        }
-      //Check if new sample is not equal to previous sample and if that is true add one to accept.
+          n_samples          = 1;
+          n_accepted_samples = 1;
+          previous_sample    = sample;
+        }
       else
-        {
-          ++n_samples;
-          bool truth=false;
-          for (int i = 0; i < sample.size(); i++)
+        // Check if new sample is not equal to previous sample and
+        // if that is true add one to accept.
+        {
+          if (internal::AcceptanceRatio::is_equal(sample, previous_sample))
             {
-              if (previous_sample[i]!=sample[i])
-                {
-                  truth=true;
-                  break;
-                }
+              // The two samples are equal. That is, we have not received
+              // a new "accepted" sample and don't need to update either
+              // the stored sample or the number of accepted samples.
+              ++n_samples;
             }
-          if (truth)
-            ++accept;
-          previous_sample = sample;
+          else
+            {
+              // The new sample is different. Update the counter and store
+              // the new sample.
+              ++n_accepted_samples;
+              previous_sample = sample;
+            }
         }
     }
+
+

     template <typename InputType>
     double
@@ -164,8 +215,13 @@
     get () const
     {
       std::lock_guard<std::mutex> lock(mutex);
-      const double ratio = static_cast<double>(accept) / static_cast<double>(n_samples);
-      return (ratio);
+
+      if (n_samples > 0)
+        return (static_cast<double>(n_accepted_samples)
+                /
+                static_cast<double>(n_samples));
+      else
+        return 0.0;
     }
   }
 }


specialix: Tidy up coding style

specialix: Tidy up coding style

Preparation for doing some real work on the driver. Do this first so we can
easily identify if the cleanups accidentally broke something

Signed-off-by: Alan Cox <91e38e63b890fbb214c8914809fde03c73e7f24d@redhat.com>
Signed-off-by: Linus Torvalds <69652caca27c8b940640ad396ab71f93cacec34f@linux-foundation.org>

--- drivers/char/specialix.c
+++ drivers/char/specialix.c
@@ -77,7 +77,7 @@

 #include <linux/module.h>

-#include <asm/io.h>
+#include <linux/io.h>
 #include <linux/kernel.h>
 #include <linux/sched.h>
 #include <linux/ioport.h>
@@ -92,7 +92,7 @@
 #include <linux/delay.h>
 #include <linux/pci.h>
 #include <linux/init.h>
-#include <asm/uaccess.h>
+#include <linux/uaccess.h>

 #include "specialix_io8.h"
 #include "cd1865.h"
@@ -112,7 +112,7 @@
 static int sx_rxfifo = SPECIALIX_RXFIFO;

 #ifdef DEBUG
-#define dprintk(f, str...) if (sx_debug & f) printk (str)
+#define dprintk(f, str...) if (sx_debug & f) printk(str)
 #else
 #define dprintk(f, str...) /* nothing */
 #endif
@@ -131,8 +131,8 @@
 #define SX_DEBUG_FIFO    0x0800

-#define func_enter() dprintk (SX_DEBUG_FLOW, "io8: enter %s\n",__func__)
-#define func_exit()  dprintk (SX_DEBUG_FLOW, "io8: exit  %s\n", __func__)
+#define func_enter() dprintk(SX_DEBUG_FLOW, "io8: enter %s\n", __func__)
+#define func_exit()  dprintk(SX_DEBUG_FLOW, "io8: exit  %s\n", __func__)

 #define jiffies_from_ms(a) ((((a) * HZ)/1000)+1)

@@ -169,8 +169,8 @@
 #endif

-/* Used to be outb (0xff, 0x80); */
-#define short_pause() udelay (1)
+/* Used to be outb(0xff, 0x80); */
+#define short_pause() udelay(1)

 #define SPECIALIX_LEGAL_FLAGS \
@@ -192,19 +192,19 @@

 #ifdef SPECIALIX_TIMER
 static struct timer_list missed_irq_timer;
-static irqreturn_t sx_interrupt(int irq, void * dev_id);
+static irqreturn_t sx_interrupt(int irq, void *dev_id);
 #endif

-static inline int sx_paranoia_check(struct specialix_port const * port,
+static inline int sx_paranoia_check(struct specialix_port const *port,
 				    char *name, const char *routine)
 {
 #ifdef SPECIALIX_PARANOIA_CHECK
-	static const char *badmagic =
-		KERN_ERR "sx: Warning: bad specialix port magic number for device %s in %s\n";
-	static const char *badinfo =
-		KERN_ERR "sx: Warning: null specialix port for device %s in %s\n";
+	static const char *badmagic = KERN_ERR
+	  "sx: Warning: bad specialix port magic number for device %s in %s\n";
+	static const char *badinfo = KERN_ERR
+	  "sx: Warning: null specialix port for device %s in %s\n";

 	if (!port) {
 		printk(badinfo, name, routine);
@@ -226,66 +226,69 @@
  */

 /* Get board number from pointer */
-static inline int board_No (struct specialix_board * bp)
+static inline int board_No(struct specialix_board *bp)
 {
 	return bp - sx_board;
 }

 /* Get port number from pointer */
-static inline int port_No (struct specialix_port const * port)
+static inline int port_No(struct specialix_port const *port)
 {
 	return SX_PORT(port - sx_port);
 }

 /* Get pointer to board from pointer to port */
-static inline struct specialix_board * port_Board(struct specialix_port const * port)
+static inline struct specialix_board *port_Board(
+					struct specialix_port const *port)
 {
 	return &sx_board[SX_BOARD(port - sx_port)];
 }

 /* Input Byte from CL CD186x register */
-static inline unsigned char sx_in(struct specialix_board  * bp, unsigned short reg)
+static inline unsigned char sx_in(struct specialix_board *bp,
+							unsigned short reg)
 {
 	bp->reg = reg | 0x80;
-	outb (reg | 0x80, bp->base + SX_ADDR_REG);
-	return inb  (bp->base + SX_DATA_REG);
+	outb(reg | 0x80, bp->base + SX_ADDR_REG);
+	return inb(bp->base + SX_DATA_REG);
 }

 /* Output Byte to CL CD186x register */
-static inline void sx_out(struct specialix_board  * bp, unsigned short reg,
+static inline void sx_out(struct specialix_board *bp, unsigned short reg,
 			  unsigned char val)
 {
 	bp->reg = reg | 0x80;
-	outb (reg | 0x80, bp->base + SX_ADDR_REG);
-	outb (val, bp->base + SX_DATA_REG);
+	outb(reg | 0x80, bp->base + SX_ADDR_REG);
+	outb(val, bp->base + SX_DATA_REG);
 }

 /* Input Byte from CL CD186x register */
-static inline unsigned char sx_in_off(struct specialix_board  * bp, unsigned short reg)
+static inline unsigned char sx_in_off(struct specialix_board *bp,
+				unsigned short reg)
 {
 	bp->reg = reg;
-	outb (reg, bp->base + SX_ADDR_REG);
-	return inb  (bp->base + SX_DATA_REG);
+	outb(reg, bp->base + SX_ADDR_REG);
+	return inb(bp->base + SX_DATA_REG);
 }

 /* Output Byte to CL CD186x register */
-static inline void sx_out_off(struct specialix_board  * bp, unsigned short reg,
-			  unsigned char val)
+static inline void sx_out_off(struct specialix_board  *bp,
+				unsigned short reg, unsigned char val)
 {
 	bp->reg = reg;
-	outb (reg, bp->base + SX_ADDR_REG);
-	outb (val, bp->base + SX_DATA_REG);
+	outb(reg, bp->base + SX_ADDR_REG);
+	outb(val, bp->base + SX_DATA_REG);
 }

 /* Wait for Channel Command Register ready */
-static inline void sx_wait_CCR(struct specialix_board  * bp)
+static inline void sx_wait_CCR(struct specialix_board  *bp)
 {
 	unsigned long delay, flags;
 	unsigned char ccr;
@@ -296,7 +299,7 @@
 		spin_unlock_irqrestore(&bp->lock, flags);
 		if (!ccr)
 			return;
-		udelay (1);
+		udelay(1);
 	}

 	printk(KERN_ERR "sx%d: Timeout waiting for CCR.\n", board_No(bp));
@@ -304,7 +307,7 @@

 /* Wait for Channel Command Register ready */
-static inline void sx_wait_CCR_off(struct specialix_board  * bp)
+static inline void sx_wait_CCR_off(struct specialix_board  *bp)
 {
 	unsigned long delay;
 	unsigned char crr;
@@ -316,7 +319,7 @@
 		spin_unlock_irqrestore(&bp->lock, flags);
 		if (!crr)
 			return;
-		udelay (1);
+		udelay(1);
 	}

 	printk(KERN_ERR "sx%d: Timeout waiting for CCR.\n", board_No(bp));
@@ -327,7 +330,7 @@
  *  specialix IO8+ IO range functions.
  */

-static inline int sx_request_io_range(struct specialix_board * bp)
+static inline int sx_request_io_range(struct specialix_board *bp)
 {
 	return request_region(bp->base,
 		bp->flags & SX_BOARD_IS_PCI ? SX_PCI_IO_SPACE : SX_IO_SPACE,
@@ -335,15 +338,15 @@
 }

-static inline void sx_release_io_range(struct specialix_board * bp)
-{
-	release_region(bp->base,
-	               bp->flags&SX_BOARD_IS_PCI?SX_PCI_IO_SPACE:SX_IO_SPACE);
+static inline void sx_release_io_range(struct specialix_board *bp)
+{
+	release_region(bp->base, bp->flags & SX_BOARD_IS_PCI ?
+					SX_PCI_IO_SPACE : SX_IO_SPACE);
 }

 /* Set the IRQ using the RTS lines that run to the PAL on the board.... */
-static int sx_set_irq ( struct specialix_board *bp)
+static int sx_set_irq(struct specialix_board *bp)
 {
 	int virq;
 	int i;
@@ -353,15 +356,24 @@
 		return 1;
 	switch (bp->irq) {
 	/* In the same order as in the docs... */
-	case 15: virq = 0;break;
-	case 12: virq = 1;break;
-	case 11: virq = 2;break;
-	case 9:  virq = 3;break;
-	default: printk (KERN_ERR "Speclialix: cannot set irq to %d.\n", bp->irq);
-	         return 0;
-	}
-	spin_lock_irqsave(&bp->lock, flags);
-	for (i=0;i<2;i++) {
+	case 15:
+		virq = 0;
+		break;
+	case 12:
+		virq = 1;
+		break;
+	case 11:
+		virq = 2;
+		break;
+	case 9:
+		virq = 3;
+		break;
+	default:printk(KERN_ERR
+			    "Speclialix: cannot set irq to %d.\n", bp->irq);
+		return 0;
+	}
+	spin_lock_irqsave(&bp->lock, flags);
+	for (i = 0; i < 2; i++) {
 		sx_out(bp, CD186x_CAR, i);
 		sx_out(bp, CD186x_MSVRTS, ((virq >> i) & 0x1)? MSVR_RTS:0);
 	}
@@ -371,7 +383,7 @@

 /* Reset and setup CD186x chip */
-static int sx_init_CD186x(struct specialix_board  * bp)
+static int sx_init_CD186x(struct specialix_board  *bp)
 {
 	unsigned long flags;
 	int scaler;
@@ -390,7 +402,7 @@
 	sx_out_off(bp, CD186x_PILR2, SX_ACK_TINT);      /* Prio for transmitter intr */
 	sx_out_off(bp, CD186x_PILR3, SX_ACK_RINT);      /* Prio for receiver intr    */
 	/* Set RegAckEn */
-	sx_out_off(bp, CD186x_SRCR, sx_in (bp, CD186x_SRCR) | SRCR_REGACKEN);
+	sx_out_off(bp, CD186x_SRCR, sx_in(bp, CD186x_SRCR) | SRCR_REGACKEN);

 	/* Setting up prescaler. We need 4 ticks per 1 ms */
 	scaler =  SX_OSCFREQ/SPECIALIX_TPS;
@@ -399,9 +411,9 @@
 	sx_out_off(bp, CD186x_PPRL, scaler & 0xff);
 	spin_unlock_irqrestore(&bp->lock, flags);

-	if (!sx_set_irq (bp)) {
+	if (!sx_set_irq(bp)) {
 		/* Figure out how to pass this along... */
-		printk (KERN_ERR "Cannot set irq to %d.\n", bp->irq);
+		printk(KERN_ERR "Cannot set irq to %d.\n", bp->irq);
 		rv = 0;
 	}

@@ -410,16 +422,16 @@
 }

-static int read_cross_byte (struct specialix_board *bp, int reg, int bit)
+static int read_cross_byte(struct specialix_board *bp, int reg, int bit)
 {
 	int i;
 	int t;
 	unsigned long flags;

 	spin_lock_irqsave(&bp->lock, flags);
-	for (i=0, t=0;i<8;i++) {
-		sx_out_off (bp, CD186x_CAR, i);
-		if (sx_in_off (bp, reg) & bit)
+	for (i = 0, t = 0; i < 8; i++) {
+		sx_out_off(bp, CD186x_CAR, i);
+		if (sx_in_off(bp, reg) & bit)
 			t |= 1 << i;
 	}
 	spin_unlock_irqrestore(&bp->lock, flags);
@@ -429,21 +441,20 @@

 #ifdef SPECIALIX_TIMER
-void missed_irq (unsigned long data)
+void missed_irq(unsigned long data)
 {
 	unsigned char irq;
 	unsigned long flags;
 	struct specialix_board  *bp = (struct specialix_board *)data;

 	spin_lock_irqsave(&bp->lock, flags);
-	irq = sx_in ((struct specialix_board *)data, CD186x_SRSR) &
-	                                            (SRSR_RREQint |
-	                                             SRSR_TREQint |
-	                                             SRSR_MREQint);
+	irq = sx_in((struct specialix_board *)data, CD186x_SRSR) &
+				(SRSR_RREQint | SRSR_TREQint | SRSR_MREQint);
 	spin_unlock_irqrestore(&bp->lock, flags);
 	if (irq) {
-		printk (KERN_INFO "Missed interrupt... Calling int from timer. \n");
-		sx_interrupt (-1, bp);
+		printk(KERN_INFO
+			"Missed interrupt... Calling int from timer. \n");
+		sx_interrupt(-1, bp);
 	}
 	mod_timer(&missed_irq_timer, jiffies + sx_poll);
 }
@@ -471,17 +482,18 @@

 	/* Are the I/O ports here ? */
 	sx_out_off(bp, CD186x_PPRL, 0x5a);
-	short_pause ();
+	short_pause();
 	val1 = sx_in_off(bp, CD186x_PPRL);

 	sx_out_off(bp, CD186x_PPRL, 0xa5);
-	short_pause ();
+	short_pause();
 	val2 = sx_in_off(bp, CD186x_PPRL);

 	if ((val1 != 0x5a) || (val2 != 0xa5)) {
-		printk(KERN_INFO "sx%d: specialix IO8+ Board at 0x%03x not found.\n",
-		       board_No(bp), bp->base);
+		printk(KERN_INFO
+			"sx%d: specialix IO8+ Board at 0x%03x not found.\n",
+						board_No(bp), bp->base);
 		sx_release_io_range(bp);
 		func_exit();
 		return 1;
@@ -489,10 +501,11 @@

 	/* Check the DSR lines that Specialix uses as board
 	   identification */
-	val1 = read_cross_byte (bp, CD186x_MSVR, MSVR_DSR);
-	val2 = read_cross_byte (bp, CD186x_MSVR, MSVR_RTS);
-	dprintk (SX_DEBUG_INIT, "sx%d: DSR lines are: %02x, rts lines are: %02x\n",
-	        board_No(bp),  val1, val2);
+	val1 = read_cross_byte(bp, CD186x_MSVR, MSVR_DSR);
+	val2 = read_cross_byte(bp, CD186x_MSVR, MSVR_RTS);
+	dprintk(SX_DEBUG_INIT,
+			"sx%d: DSR lines are: %02x, rts lines are: %02x\n",
+					board_No(bp), val1, val2);

 	/* They managed to switch the bit order between the docs and
 	   the IO8+ card. The new PCI card now conforms to old docs.
@@ -500,7 +513,8 @@
 	   old card. */
 	val2 = (bp->flags & SX_BOARD_IS_PCI)?0x4d : 0xb2;
 	if (val1 != val2) {
-		printk(KERN_INFO "sx%d: specialix IO8+ ID %02x at 0x%03x not found (%02x).\n",
+		printk(KERN_INFO
+		  "sx%d: specialix IO8+ ID %02x at 0x%03x not found (%02x).\n",
 		       board_No(bp), val2, bp->base, val1);
 		sx_release_io_range(bp);
 		func_exit();
@@ -512,40 +526,43 @@
 	/* It's time to find IRQ for this board */
 	for (retries = 0; retries < 5 && irqs <= 0; retries++) {
 		irqs = probe_irq_on();
-		sx_init_CD186x(bp);	       		/* Reset CD186x chip       */
-		sx_out(bp, CD186x_CAR, 2);               /* Select port 2          */
+		sx_init_CD186x(bp);		   /* Reset CD186x chip      */
+		sx_out(bp, CD186x_CAR, 2);         /* Select port 2          */
 		sx_wait_CCR(bp);
-		sx_out(bp, CD186x_CCR, CCR_TXEN);        /* Enable transmitter     */
-		sx_out(bp, CD186x_IER, IER_TXRDY);       /* Enable tx empty intr   */
+		sx_out(bp, CD186x_CCR, CCR_TXEN);  /* Enable transmitter     */
+		sx_out(bp, CD186x_IER, IER_TXRDY); /* Enable tx empty intr   */
 		msleep(50);
 		irqs = probe_irq_off(irqs);

-		dprintk (SX_DEBUG_INIT, "SRSR = %02x, ", sx_in(bp, CD186x_SRSR));
-		dprintk (SX_DEBUG_INIT, "TRAR = %02x, ", sx_in(bp, CD186x_TRAR));
-		dprintk (SX_DEBUG_INIT, "GIVR = %02x, ", sx_in(bp, CD186x_GIVR));
-		dprintk (SX_DEBUG_INIT, "GICR = %02x, ", sx_in(bp, CD186x_GICR));
-		dprintk (SX_DEBUG_INIT, "\n");
+		dprintk(SX_DEBUG_INIT, "SRSR = %02x, ", sx_in(bp, CD186x_SRSR));
+		dprintk(SX_DEBUG_INIT, "TRAR = %02x, ", sx_in(bp, CD186x_TRAR));
+		dprintk(SX_DEBUG_INIT, "GIVR = %02x, ", sx_in(bp, CD186x_GIVR));
+		dprintk(SX_DEBUG_INIT, "GICR = %02x, ", sx_in(bp, CD186x_GICR));
+		dprintk(SX_DEBUG_INIT, "\n");

 		/* Reset CD186x again      */
 		if (!sx_init_CD186x(bp)) {
 			/* Hmmm. This is dead code anyway. */
 		}

-		dprintk (SX_DEBUG_INIT "val1 = %02x, val2 = %02x, val3 = %02x.\n",
-		        val1, val2, val3);
+		dprintk(SX_DEBUG_INIT
+			"val1 = %02x, val2 = %02x, val3 = %02x.\n",
+				val1, val2, val3);

 	}

 #if 0
 	if (irqs <= 0) {
-		printk(KERN_ERR "sx%d: Can't find IRQ for specialix IO8+ board at 0x%03x.\n",
-		       board_No(bp), bp->base);
+		printk(KERN_ERR
+		  "sx%d: Can't find IRQ for specialix IO8+ board at 0x%03x.\n",
+						board_No(bp), bp->base);
 		sx_release_io_range(bp);
 		func_exit();
 		return 1;
 	}
 #endif
-	printk (KERN_INFO "Started with irq=%d, but now have irq=%d.\n", bp->irq, irqs);
+	printk(KERN_INFO "Started with irq=%d, but now have irq=%d.\n",
+								bp->irq, irqs);
 	if (irqs > 0)
 		bp->irq = irqs;
 #endif
@@ -560,7 +577,7 @@
 	bp->flags |= SX_BOARD_PRESENT;

 	/* Chip           revcode   pkgtype
-	                  GFRCR     SRCR bit 7
+			  GFRCR     SRCR bit 7
 	   CD180 rev B    0x81      0
 	   CD180 rev C    0x82      0
 	   CD1864 rev A   0x82      1
@@ -570,24 +587,37 @@
 	 */

 	switch (sx_in_off(bp, CD186x_GFRCR)) {
-	case 0x82:chip = 1864;rev='A';break;
-	case 0x83:chip = 1865;rev='A';break;
-	case 0x84:chip = 1865;rev='B';break;
-	case 0x85:chip = 1865;rev='C';break; /* Does not exist at this time */
-	default:chip=-1;rev='x';
-	}
-
-	dprintk (SX_DEBUG_INIT, " GFCR = 0x%02x\n", sx_in_off(bp, CD186x_GFRCR) );
+	case 0x82:
+		chip = 1864;
+		rev = 'A';
+		break;
+	case 0x83:
+		chip = 1865;
+		rev = 'A';
+		break;
+	case 0x84:
+		chip = 1865;
+		rev = 'B';
+		break;
+	case 0x85:
+		chip = 1865;
+		rev = 'C';
+		break; /* Does not exist at this time */
+	default:
+		chip = -1;
+		rev = 'x';
+	}
+
+	dprintk(SX_DEBUG_INIT, " GFCR = 0x%02x\n", sx_in_off(bp, CD186x_GFRCR));

 #ifdef SPECIALIX_TIMER
 	setup_timer(&missed_irq_timer, missed_irq, (unsigned long)bp);
 	mod_timer(&missed_irq_timer, jiffies + sx_poll);
 #endif

-	printk(KERN_INFO"sx%d: specialix IO8+ board detected at 0x%03x, IRQ %d, CD%d Rev. %c.\n",
-	       board_No(bp),
-	       bp->base, bp->irq,
-	       chip, rev);
+	printk(KERN_INFO
+    "sx%d: specialix IO8+ board detected at 0x%03x, IRQ %d, CD%d Rev. %c.\n",
+				board_No(bp), bp->base, bp->irq, chip, rev);

 	func_exit();
 	return 0;
@@ -598,20 +628,22 @@
  *  Interrupt processing routines.
  * */

-static inline struct specialix_port * sx_get_port(struct specialix_board * bp,
-					       unsigned char const * what)
+static inline struct specialix_port *sx_get_port(struct specialix_board *bp,
+					       unsigned char const *what)
 {
 	unsigned char channel;
-	struct specialix_port * port = NULL;
+	struct specialix_port *port = NULL;

 	channel = sx_in(bp, CD186x_GICR) >> GICR_CHAN_OFF;
-	dprintk (SX_DEBUG_CHAN, "channel: %d\n", channel);
+	dprintk(SX_DEBUG_CHAN, "channel: %d\n", channel);
 	if (channel < CD186x_NCH) {
 		port = &sx_port[board_No(bp) * SX_NPORT + channel];
-		dprintk (SX_DEBUG_CHAN, "port: %d %p flags: 0x%lx\n",board_No(bp) * SX_NPORT + channel,  port, port->port.flags & ASYNC_INITIALIZED);
+		dprintk(SX_DEBUG_CHAN, "port: %d %p flags: 0x%lx\n",
+			board_No(bp) * SX_NPORT + channel,  port,
+			port->port.flags & ASYNC_INITIALIZED);

 		if (port->port.flags & ASYNC_INITIALIZED) {
-			dprintk (SX_DEBUG_CHAN, "port: %d %p\n", channel, port);
+			dprintk(SX_DEBUG_CHAN, "port: %d %p\n", channel, port);
 			func_exit();
 			return port;
 		}
@@ -622,7 +654,7 @@
 }

-static inline void sx_receive_exc(struct specialix_board * bp)
+static inline void sx_receive_exc(struct specialix_board *bp)
 {
 	struct specialix_port *port;
 	struct tty_struct *tty;
@@ -633,7 +665,7 @@

 	port = sx_get_port(bp, "Receive");
 	if (!port) {
-		dprintk (SX_DEBUG_RX, "Hmm, couldn't find port.\n");
+		dprintk(SX_DEBUG_RX, "Hmm, couldn't find port.\n");
 		func_exit();
 		return;
 	}
@@ -641,19 +673,21 @@

 	status = sx_in(bp, CD186x_RCSR);

-	dprintk (SX_DEBUG_RX, "status: 0x%x\n", status);
+	dprintk(SX_DEBUG_RX, "status: 0x%x\n", status);
 	if (status & RCSR_OE) {
 		port->overrun++;
-		dprintk(SX_DEBUG_FIFO, "sx%d: port %d: Overrun. Total %ld overruns.\n",
-		       board_No(bp), port_No(port), port->overrun);
+		dprintk(SX_DEBUG_FIFO,
+			"sx%d: port %d: Overrun. Total %ld overruns.\n",
+				board_No(bp), port_No(port), port->overrun);
 	}
 	status &= port->mark_mask;

 	/* This flip buffer check needs to be below the reading of the
 	   status register to reset the chip's IRQ.... */
 	if (tty_buffer_request_room(tty, 1) == 0) {
-		dprintk(SX_DEBUG_FIFO, "sx%d: port %d: Working around flip buffer overflow.\n",
-		       board_No(bp), port_No(port));
+		dprintk(SX_DEBUG_FIFO,
+		    "sx%d: port %d: Working around flip buffer overflow.\n",
+					board_No(bp), port_No(port));
 		func_exit();
 		return;
 	}
@@ -664,8 +698,9 @@
 		return;
 	}
 	if (status & RCSR_TOUT) {
-		printk(KERN_INFO "sx%d: port %d: Receiver timeout. Hardware problems ?\n",
-		       board_No(bp), port_No(port));
+		printk(KERN_INFO
+		    "sx%d: port %d: Receiver timeout. Hardware problems ?\n",
+					board_No(bp), port_No(port));
 		func_exit();
 		return;

@@ -688,13 +723,13 @@
 	else
 		flag = TTY_NORMAL;

-	if(tty_insert_flip_char(tty, ch, flag))
+	if (tty_insert_flip_char(tty, ch, flag))
 		tty_flip_buffer_push(tty);
 	func_exit();
 }

-static inline void sx_receive(struct specialix_board * bp)
+static inline void sx_receive(struct specialix_board *bp)
 {
 	struct specialix_port *port;
 	struct tty_struct *tty;
@@ -702,15 +737,16 @@

 	func_enter();

-	if (!(port = sx_get_port(bp, "Receive"))) {
-		dprintk (SX_DEBUG_RX, "Hmm, couldn't find port.\n");
+	port = sx_get_port(bp, "Receive");
+	if (port == NULL) {
+		dprintk(SX_DEBUG_RX, "Hmm, couldn't find port.\n");
 		func_exit();
 		return;
 	}
 	tty = port->port.tty;

 	count = sx_in(bp, CD186x_RDCR);
-	dprintk (SX_DEBUG_RX, "port: %p: count: %d\n", port, count);
+	dprintk(SX_DEBUG_RX, "port: %p: count: %d\n", port, count);
 	port->hits[count > 8 ? 9 : count]++;

 	tty_buffer_request_room(tty, count);
@@ -722,18 +758,19 @@
 }

-static inline void sx_transmit(struct specialix_board * bp)
+static inline void sx_transmit(struct specialix_board *bp)
 {
 	struct specialix_port *port;
 	struct tty_struct *tty;
 	unsigned char count;

 	func_enter();
-	if (!(port = sx_get_port(bp, "Transmit"))) {
+	port = sx_get_port(bp, "Transmit");
+	if (port == NULL) {
 		func_exit();
 		return;
 	}
-	dprintk (SX_DEBUG_TX, "port: %p\n", port);
+	dprintk(SX_DEBUG_TX, "port: %p\n", port);
 	tty = port->port.tty;

 	if (port->IER & IER_TXEMPTY) {
@@ -765,7 +802,8 @@
 			sx_out(bp, CD186x_TDR, CD186x_C_ESC);
 			sx_out(bp, CD186x_TDR, CD186x_C_DELAY);
 			sx_out(bp, CD186x_TDR, count);
-			if (!(port->break_length -= count))
+			port->break_length -= count;
+			if (port->break_length == 0)
 				port->break_length--;
 		} else {
 			sx_out(bp, CD186x_TDR, CD186x_C_ESC);
@@ -794,36 +832,37 @@
 		sx_out(bp, CD186x_IER, port->IER);
 	}
 	if (port->xmit_cnt <= port->wakeup_chars)
- 		tty_wakeup(tty);
-
-	func_exit();
-}
-
-
-static inline void sx_check_modem(struct specialix_board * bp)
+		tty_wakeup(tty);
+
+	func_exit();
+}
+
+
+static inline void sx_check_modem(struct specialix_board *bp)
 {
 	struct specialix_port *port;
 	struct tty_struct *tty;
 	unsigned char mcr;
 	int msvr_cd;

-	dprintk (SX_DEBUG_SIGNALS, "Modem intr. ");
-	if (!(port = sx_get_port(bp, "Modem")))
+	dprintk(SX_DEBUG_SIGNALS, "Modem intr. ");
+	port = sx_get_port(bp, "Modem");
+	if (port == NULL)
 		return;

 	tty = port->port.tty;

 	mcr = sx_in(bp, CD186x_MCR);
-	printk ("mcr = %02x.\n", mcr);
+	printk("mcr = %02x.\n", mcr);	/* FIXME */

 	if ((mcr & MCR_CDCHG)) {
-		dprintk (SX_DEBUG_SIGNALS, "CD just changed... ");
+		dprintk(SX_DEBUG_SIGNALS, "CD just changed... ");
 		msvr_cd = sx_in(bp, CD186x_MSVR) & MSVR_CD;
 		if (msvr_cd) {
-			dprintk (SX_DEBUG_SIGNALS, "Waking up guys in open.\n");
+			dprintk(SX_DEBUG_SIGNALS, "Waking up guys in open.\n");
 			wake_up_interruptible(&port->port.open_wait);
 		} else {
-			dprintk (SX_DEBUG_SIGNALS, "Sending HUP.\n");
+			dprintk(SX_DEBUG_SIGNALS, "Sending HUP.\n");
 			tty_hangup(tty);
 		}
 	}
@@ -874,9 +913,12 @@

 	spin_lock_irqsave(&bp->lock, flags);

-	dprintk (SX_DEBUG_FLOW, "enter %s port %d room: %ld\n", __func__, port_No(sx_get_port(bp, "INT")), SERIAL_XMIT_SIZE - sx_get_port(bp, "ITN")->xmit_cnt - 1);
+	dprintk(SX_DEBUG_FLOW, "enter %s port %d room: %ld\n", __func__,
+		port_No(sx_get_port(bp, "INT")),
+		SERIAL_XMIT_SIZE - sx_get_port(bp, "ITN")->xmit_cnt - 1);
 	if (!(bp->flags & SX_BOARD_ACTIVE)) {
-		dprintk (SX_DEBUG_IRQ, "sx: False interrupt. irq %d.\n", bp->irq);
+		dprintk(SX_DEBUG_IRQ, "sx: False interrupt. irq %d.\n",
+								bp->irq);
 		spin_unlock_irqrestore(&bp->lock, flags);
 		func_exit();
 		return IRQ_NONE;
@@ -884,10 +926,11 @@

 	saved_reg = bp->reg;

-	while ((++loop < 16) && (status = (sx_in(bp, CD186x_SRSR) &
-	                                   (SRSR_RREQint |
-		                            SRSR_TREQint |
-	                                    SRSR_MREQint)))) {
+	while (++loop < 16) {
+		status = sx_in(bp, CD186x_SRSR) &
+				(SRSR_RREQint | SRSR_TREQint | SRSR_MREQint);
+		if (status == 0)
+			break;
 		if (status & SRSR_RREQint) {
 			ack = sx_in(bp, CD186x_RRAR);

@@ -896,8 +939,9 @@
 			else if (ack == (SX_ID | GIVR_IT_REXC))
 				sx_receive_exc(bp);
 			else
-				printk(KERN_ERR "sx%d: status: 0x%x Bad receive ack 0x%02x.\n",
-				       board_No(bp), status, ack);
+				printk(KERN_ERR
+				"sx%d: status: 0x%x Bad receive ack 0x%02x.\n",
+						board_No(bp), status, ack);

 		} else if (status & SRSR_TREQint) {
 			ack = sx_in(bp, CD186x_TRAR);
@@ -906,14 +950,16 @@
 				sx_transmit(bp);
 			else
 				printk(KERN_ERR "sx%d: status: 0x%x Bad transmit ack 0x%02x. port: %d\n",
-				       board_No(bp), status, ack, port_No (sx_get_port (bp, "Int")));
+					board_No(bp), status, ack,
+					port_No(sx_get_port(bp, "Int")));
 		} else if (status & SRSR_MREQint) {
 			ack = sx_in(bp, CD186x_MRAR);

 			if (ack == (SX_ID | GIVR_IT_MODEM))
 				sx_check_modem(bp);
 			else
-				printk(KERN_ERR "sx%d: status: 0x%x Bad modem ack 0x%02x.\n",
+				printk(KERN_ERR
+				  "sx%d: status: 0x%x Bad modem ack 0x%02x.\n",
 				       board_No(bp), status, ack);

 		}
@@ -921,7 +967,7 @@
 		sx_out(bp, CD186x_EOIR, 0);   /* Mark end of interrupt */
 	}
 	bp->reg = saved_reg;
-	outb (bp->reg, bp->base + SX_ADDR_REG);
+	outb(bp->reg, bp->base + SX_ADDR_REG);
 	spin_unlock_irqrestore(&bp->lock, flags);
 	func_exit();
 	return IRQ_HANDLED;
@@ -932,7 +978,7 @@
  *  Routines for open & close processing.
  */

-static void turn_ints_off (struct specialix_board *bp)
+static void turn_ints_off(struct specialix_board *bp)
 {
 	unsigned long flags;

@@ -945,13 +991,13 @@
 	}

 	spin_lock_irqsave(&bp->lock, flags);
-	(void) sx_in_off (bp, 0); /* Turn off interrupts. */
-	spin_unlock_irqrestore(&bp->lock, flags);
-
-	func_exit();
-}
-
-static void turn_ints_on (struct specialix_board *bp)
+	(void) sx_in_off(bp, 0); /* Turn off interrupts. */
+	spin_unlock_irqrestore(&bp->lock, flags);
+
+	func_exit();
+}
+
+static void turn_ints_on(struct specialix_board *bp)
 {
 	unsigned long flags;

@@ -961,7 +1007,7 @@
 		/* play with the PCI chip. See comment above. */
 	}
 	spin_lock_irqsave(&bp->lock, flags);
-	(void) sx_in (bp, 0); /* Turn ON interrupts. */
+	(void) sx_in(bp, 0); /* Turn ON interrupts. */
 	spin_unlock_irqrestore(&bp->lock, flags);

 	func_exit();
@@ -969,7 +1015,7 @@

 /* Called with disabled interrupts */
-static inline int sx_setup_board(struct specialix_board * bp)
+static inline int sx_setup_board(struct specialix_board *bp)
 {
 	int error;

@@ -977,14 +1023,16 @@
 		return 0;

 	if (bp->flags & SX_BOARD_IS_PCI)
-		error = request_irq(bp->irq, sx_interrupt, IRQF_DISABLED | IRQF_SHARED, "specialix IO8+", bp);
+		error = request_irq(bp->irq, sx_interrupt,
+			IRQF_DISABLED | IRQF_SHARED, "specialix IO8+", bp);
 	else
-		error = request_irq(bp->irq, sx_interrupt, IRQF_DISABLED, "specialix IO8+", bp);
+		error = request_irq(bp->irq, sx_interrupt,
+			IRQF_DISABLED, "specialix IO8+", bp);

 	if (error)
 		return error;

-	turn_ints_on (bp);
+	turn_ints_on(bp);
 	bp->flags |= SX_BOARD_ACTIVE;

 	return 0;
@@ -1003,13 +1051,10 @@

 	bp->flags &= ~SX_BOARD_ACTIVE;

-	dprintk (SX_DEBUG_IRQ, "Freeing IRQ%d for board %d.\n",
-		 bp->irq, board_No (bp));
+	dprintk(SX_DEBUG_IRQ, "Freeing IRQ%d for board %d.\n",
+		 bp->irq, board_No(bp));
 	free_irq(bp->irq, bp);
-
-	turn_ints_off (bp);
-
-
+	turn_ints_off(bp);
 	func_exit();
 }

@@ -1018,7 +1063,8 @@
  * Setting up port characteristics.
  * Must be called with disabled interrupts
  */
-static void sx_change_speed(struct specialix_board *bp, struct specialix_port *port)
+static void sx_change_speed(struct specialix_board *bp,
+						struct specialix_port *port)
 {
 	struct tty_struct *tty;
 	unsigned long baud;
@@ -1030,7 +1076,8 @@

 	func_enter();

-	if (!(tty = port->port.tty) || !tty->termios) {
+	tty = port->port.tty;
+	if (!tty || !tty->termios) {
 		func_exit();
 		return;
 	}
@@ -1048,7 +1095,7 @@
 	else
 		port->MSVR =  (sx_in(bp, CD186x_MSVR) & MSVR_RTS);
 	spin_unlock_irqrestore(&bp->lock, flags);
-	dprintk (SX_DEBUG_TERMIOS, "sx: got MSVR=%02x.\n", port->MSVR);
+	dprintk(SX_DEBUG_TERMIOS, "sx: got MSVR=%02x.\n", port->MSVR);
 	baud = tty_get_baud_rate(tty);

 	if (baud == 38400) {
@@ -1060,21 +1107,19 @@

 	if (!baud) {
 		/* Drop DTR & exit */
-		dprintk (SX_DEBUG_TERMIOS, "Dropping DTR...  Hmm....\n");
-		if (!SX_CRTSCTS (tty)) {
-			port -> MSVR &= ~ MSVR_DTR;
+		dprintk(SX_DEBUG_TERMIOS, "Dropping DTR...  Hmm....\n");
+		if (!SX_CRTSCTS(tty)) {
+			port->MSVR &= ~MSVR_DTR;
 			spin_lock_irqsave(&bp->lock, flags);
-			sx_out(bp, CD186x_MSVR, port->MSVR );
+			sx_out(bp, CD186x_MSVR, port->MSVR);
 			spin_unlock_irqrestore(&bp->lock, flags);
-		}
-		else
-			dprintk (SX_DEBUG_TERMIOS, "Can't drop DTR: no DTR.\n");
+		} else
+			dprintk(SX_DEBUG_TERMIOS, "Can't drop DTR: no DTR.\n");
 		return;
 	} else {
 		/* Set DTR on */
-		if (!SX_CRTSCTS (tty)) {
-			port ->MSVR |= MSVR_DTR;
-		}
+		if (!SX_CRTSCTS(tty))
+			port->MSVR |= MSVR_DTR;
 	}

 	/*
@@ -1083,28 +1128,27 @@

 	/* Set baud rate for port */
 	tmp = port->custom_divisor ;
-	if ( tmp )
-		printk (KERN_INFO "sx%d: Using custom baud rate divisor %ld. \n"
-		                  "This is an untested option, please be carefull.\n",
-		                  port_No (port), tmp);
+	if (tmp)
+		printk(KERN_INFO
+			"sx%d: Using custom baud rate divisor %ld. \n"
+			"This is an untested option, please be careful.\n",
+							port_No(port), tmp);
 	else
-		tmp = (((SX_OSCFREQ + baud/2) / baud +
-		         CD186x_TPC/2) / CD186x_TPC);
-
-	if ((tmp < 0x10) && time_before(again, jiffies)) {
+		tmp = (((SX_OSCFREQ + baud/2) / baud + CD186x_TPC/2) /
+								CD186x_TPC);
+
+	if (tmp < 0x10 && time_before(again, jiffies)) {
 		again = jiffies + HZ * 60;
 		/* Page 48 of version 2.0 of the CL-CD1865 databook */
 		if (tmp >= 12) {
-			printk (KERN_INFO "sx%d: Baud rate divisor is %ld. \n"
-			        "Performance degradation is possible.\n"
-			        "Read specialix.txt for more info.\n",
-			        port_No (port), tmp);
+			printk(KERN_INFO "sx%d: Baud rate divisor is %ld. \n"
+				"Performance degradation is possible.\n"
+				"Read specialix.txt for more info.\n",
+						port_No(port), tmp);
 		} else {
-			printk (KERN_INFO "sx%d: Baud rate divisor is %ld. \n"
-			        "Warning: overstressing Cirrus chip. "
-			        "This might not work.\n"
-			        "Read specialix.txt for more info.\n",
-			        port_No (port), tmp);
+			printk(KERN_INFO "sx%d: Baud rate divisor is %ld. \n"
+		"Warning: overstressing Cirrus chip. This might not work.\n"
+		"Read specialix.txt for more info.\n", port_No(port), tmp);
 		}
 	}
 	spin_lock_irqsave(&bp->lock, flags);
@@ -1114,7 +1158,8 @@
 	sx_out(bp, CD186x_TBPRL, tmp & 0xff);
 	spin_unlock_irqrestore(&bp->lock, flags);
 	if (port->custom_divisor)
-		baud = (SX_OSCFREQ + port->custom_divisor/2) / port->custom_divisor;
+		baud = (SX_OSCFREQ + port->custom_divisor/2) /
+							port->custom_divisor;
 	baud = (baud + 5) / 10;		/* Estimated CPS */

 	/* Two timer ticks seems enough to wakeup something like SLIP driver */
@@ -1129,16 +1174,16 @@
 	sx_out(bp, CD186x_RTPR, tmp);
 	spin_unlock_irqrestore(&bp->lock, flags);
 	switch (C_CSIZE(tty)) {
-	 case CS5:
+	case CS5:
 		cor1 |= COR1_5BITS;
 		break;
-	 case CS6:
+	case CS6:
 		cor1 |= COR1_6BITS;
 		break;
-	 case CS7:
+	case CS7:
 		cor1 |= COR1_7BITS;
 		break;
-	 case CS8:
+	case CS8:
 		cor1 |= COR1_8BITS;
 		break;
 	}
@@ -1175,7 +1220,8 @@
 		mcor1 |= MCOR1_DSRZD | MCOR1_CTSZD;
 		mcor2 |= MCOR2_DSROD | MCOR2_CTSOD;
 		spin_lock_irqsave(&bp->lock, flags);
-		tty->hw_stopped = !(sx_in(bp, CD186x_MSVR) & (MSVR_CTS|MSVR_DSR));
+		tty->hw_stopped = !(sx_in(bp, CD186x_MSVR) &
+							(MSVR_CTS|MSVR_DSR));
 		spin_unlock_irqrestore(&bp->lock, flags);
 #else
 		port->COR2 |= COR2_CTSAE;
@@ -1219,7 +1265,8 @@
 	spin_lock_irqsave(&bp->lock, flags);
 	sx_out(bp, CD186x_CCR, CCR_CORCHG1 | CCR_CORCHG2 | CCR_CORCHG3);
 	/* Setting up modem option registers */
-	dprintk (SX_DEBUG_TERMIOS, "Mcor1 = %02x, mcor2 = %02x.\n", mcor1, mcor2);
+	dprintk(SX_DEBUG_TERMIOS, "Mcor1 = %02x, mcor2 = %02x.\n",
+								mcor1, mcor2);
 	sx_out(bp, CD186x_MCOR1, mcor1);
 	sx_out(bp, CD186x_MCOR2, mcor2);
 	spin_unlock_irqrestore(&bp->lock, flags);
@@ -1238,7 +1285,8 @@

 /* Must be called with interrupts enabled */
-static int sx_setup_port(struct specialix_board *bp, struct specialix_port *port)
+static int sx_setup_port(struct specialix_board *bp,
+						struct specialix_port *port)
 {
 	unsigned long flags;

@@ -1253,7 +1301,8 @@
 		/* We may sleep in get_zeroed_page() */
 		unsigned long tmp;

-		if (!(tmp = get_zeroed_page(GFP_KERNEL))) {
+		tmp = get_zeroed_page(GFP_KERNEL);
+		if (tmp == 0L) {
 			func_exit();
 			return -ENOMEM;
 		}
@@ -1284,7 +1333,8 @@

 /* Must be called with interrupts disabled */
-static void sx_shutdown_port(struct specialix_board *bp, struct specialix_port *port)
+static void sx_shutdown_port(struct specialix_board *bp,
+						struct specialix_port *port)
 {
 	struct tty_struct *tty;
 	int i;
@@ -1298,11 +1348,11 @@
 	}

 	if (sx_debug & SX_DEBUG_FIFO) {
-		dprintk(SX_DEBUG_FIFO, "sx%d: port %d: %ld overruns, FIFO hits [ ",
-			board_No(bp), port_No(port), port->overrun);
-		for (i = 0; i < 10; i++) {
+		dprintk(SX_DEBUG_FIFO,
+			"sx%d: port %d: %ld overruns, FIFO hits [ ",
+				board_No(bp), port_No(port), port->overrun);
+		for (i = 0; i < 10; i++)
 			dprintk(SX_DEBUG_FIFO, "%ld ", port->hits[i]);
-		}
 		dprintk(SX_DEBUG_FIFO, "].\n");
 	}

@@ -1315,7 +1365,8 @@
 	spin_lock_irqsave(&bp->lock, flags);
 	sx_out(bp, CD186x_CAR, port_No(port));

-	if (!(tty = port->port.tty) || C_HUPCL(tty)) {
+	tty = port->port.tty;
+	if (tty == NULL || C_HUPCL(tty)) {
 		/* Drop DTR */
 		sx_out(bp, CD186x_MSVDTR, 0);
 	}
@@ -1338,8 +1389,8 @@
 }

-static int block_til_ready(struct tty_struct *tty, struct file * filp,
-                           struct specialix_port *port)
+static int block_til_ready(struct tty_struct *tty, struct file *filp,
+						struct specialix_port *port)
 {
 	DECLARE_WAITQUEUE(wait,  current);
 	struct specialix_board *bp = port_Board(port);
@@ -1389,23 +1440,22 @@
 	retval = 0;
 	add_wait_queue(&port->port.open_wait, &wait);
 	spin_lock_irqsave(&port->lock, flags);
-	if (!tty_hung_up_p(filp)) {
+	if (!tty_hung_up_p(filp))
 		port->port.count--;
-	}
 	spin_unlock_irqrestore(&port->lock, flags);
 	port->port.blocked_open++;
 	while (1) {
 		spin_lock_irqsave(&bp->lock, flags);
 		sx_out(bp, CD186x_CAR, port_No(port));
 		CD = sx_in(bp, CD186x_MSVR) & MSVR_CD;
-		if (SX_CRTSCTS (tty)) {
+		if (SX_CRTSCTS(tty)) {
 			/* Activate RTS */
 			port->MSVR |= MSVR_DTR;		/* WTF? */
-			sx_out (bp, CD186x_MSVR, port->MSVR);
+			sx_out(bp, CD186x_MSVR, port->MSVR);
 		} else {
 			/* Activate DTR */
 			port->MSVR |= MSVR_DTR;
-			sx_out (bp, CD186x_MSVR, port->MSVR);
+			sx_out(bp, CD186x_MSVR, port->MSVR);
 		}
 		spin_unlock_irqrestore(&bp->lock, flags);
 		set_current_state(TASK_INTERRUPTIBLE);
@@ -1430,9 +1480,8 @@
 	set_current_state(TASK_RUNNING);
 	remove_wait_queue(&port->port.open_wait, &wait);
 	spin_lock_irqsave(&port->lock, flags);
-	if (!tty_hung_up_p(filp)) {
+	if (!tty_hung_up_p(filp))
 		port->port.count++;
-	}
 	port->port.blocked_open--;
 	spin_unlock_irqrestore(&port->lock, flags);
 	if (retval) {
@@ -1446,12 +1495,12 @@
 }

-static int sx_open(struct tty_struct * tty, struct file * filp)
+static int sx_open(struct tty_struct *tty, struct file *filp)
 {
 	int board;
 	int error;
-	struct specialix_port * port;
-	struct specialix_board * bp;
+	struct specialix_port *port;
+	struct specialix_board *bp;
 	int i;
 	unsigned long flags;

@@ -1468,17 +1517,19 @@
 	port = sx_port + board * SX_NPORT + SX_PORT(tty->index);
 	port->overrun = 0;
 	for (i = 0; i < 10; i++)
-		port->hits[i]=0;
-
-	dprintk (SX_DEBUG_OPEN, "Board = %d, bp = %p, port = %p, portno = %d.\n",
-	        board, bp, port, SX_PORT(tty->index));
+		port->hits[i] = 0;
+
+	dprintk(SX_DEBUG_OPEN,
+			"Board = %d, bp = %p, port = %p, portno = %d.\n",
+				 board, bp, port, SX_PORT(tty->index));

 	if (sx_paranoia_check(port, tty->name, "sx_open")) {
 		func_enter();
 		return -ENODEV;
 	}

-	if ((error = sx_setup_board(bp))) {
+	error = sx_setup_board(bp);
+	if (error) {
 		func_exit();
 		return error;
 	}
@@ -1490,12 +1541,14 @@
 	port->port.tty = tty;
 	spin_unlock_irqrestore(&bp->lock, flags);

-	if ((error = sx_setup_port(bp, port))) {
+	error = sx_setup_port(bp, port);
+	if (error) {
 		func_enter();
 		return error;
 	}

-	if ((error = block_til_ready(tty, filp, port))) {
+	error = block_til_ready(tty, filp, port);
+	if (error) {
 		func_enter();
 		return error;
 	}
@@ -1508,7 +1561,7 @@
 {
 	struct specialix_port *port = (struct specialix_port *)tty->driver_data;
 	unsigned long flags;
-	struct specialix_board  * bp;
+	struct specialix_board  *bp;

 	func_enter();

@@ -1526,9 +1579,9 @@
 	func_exit();
 }

-static void sx_close(struct tty_struct * tty, struct file * filp)
-{
-	struct specialix_port *port = (struct specialix_port *) tty->driver_data;
+static void sx_close(struct tty_struct *tty, struct file *filp)
+{
+	struct specialix_port *port = (struct specialix_port *)tty->driver_data;
 	struct specialix_board *bp;
 	unsigned long flags;
 	unsigned long timeout;
@@ -1570,17 +1623,16 @@
 	 */
 	tty->closing = 1;
 	spin_unlock_irqrestore(&port->lock, flags);
-	dprintk (SX_DEBUG_OPEN, "Closing\n");
-	if (port->port.closing_wait != ASYNC_CLOSING_WAIT_NONE) {
+	dprintk(SX_DEBUG_OPEN, "Closing\n");
+	if (port->port.closing_wait != ASYNC_CLOSING_WAIT_NONE)
 		tty_wait_until_sent(tty, port->port.closing_wait);
-	}
 	/*
 	 * At this point we stop accepting input.  To do this, we
 	 * disable the receive line status interrupts, and tell the
 	 * interrupt driver to stop checking the data ready bit in the
 	 * line status register.
 	 */
-	dprintk (SX_DEBUG_OPEN, "Closed\n");
+	dprintk(SX_DEBUG_OPEN, "Closed\n");
 	port->IER &= ~IER_RXD;
 	if (port->port.flags & ASYNC_INITIALIZED) {
 		port->IER &= ~IER_TXRDY;
@@ -1595,11 +1647,11 @@
 		 * important if there is a transmit FIFO!
 		 */
 		timeout = jiffies+HZ;
-		while(port->IER & IER_TXEMPTY) {
-			set_current_state (TASK_INTERRUPTIBLE);
+		while (port->IER & IER_TXEMPTY) {
+			set_current_state(TASK_INTERRUPTIBLE);
 			msleep_interruptible(jiffies_to_msecs(port->timeout));
 			if (time_after(jiffies, timeout)) {
-				printk (KERN_INFO "Timeout waiting for close\n");
+				printk(KERN_INFO "Timeout waiting for close\n");
 				break;
 			}
 		}
@@ -1607,13 +1659,15 @@
 	}

 	if (--bp->count < 0) {
-		printk(KERN_ERR "sx%d: sx_shutdown_port: bad board count: %d port: %d\n",
-		       board_No(bp), bp->count, tty->index);
+		printk(KERN_ERR
+		    "sx%d: sx_shutdown_port: bad board count: %d port: %d\n",
+				board_No(bp), bp->count, tty->index);
 		bp->count = 0;
 	}
 	if (--port->port.count < 0) {
-		printk(KERN_ERR "sx%d: sx_close: bad port count for tty%d: %d\n",
-		       board_No(bp), port_No(port), port->port.count);
+		printk(KERN_ERR
+			"sx%d: sx_close: bad port count for tty%d: %d\n",
+				board_No(bp), port_No(port), port->port.count);
 		port->port.count = 0;
 	}

@@ -1625,9 +1679,9 @@
 	port->port.tty = NULL;
 	spin_unlock_irqrestore(&port->lock, flags);
 	if (port->port.blocked_open) {
-		if (port->port.close_delay) {
-			msleep_interruptible(jiffies_to_msecs(port->port.close_delay));
-		}
+		if (port->port.close_delay)
+			msleep_interruptible(
+				jiffies_to_msecs(port->port.close_delay));
 		wake_up_interruptible(&port->port.open_wait);
 	}
 	port->port.flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
@@ -1637,8 +1691,8 @@
 }

-static int sx_write(struct tty_struct * tty,
-                    const unsigned char *buf, int count)
+static int sx_write(struct tty_struct *tty,
+					const unsigned char *buf, int count)
 {
 	struct specialix_port *port = (struct specialix_port *)tty->driver_data;
 	struct specialix_board *bp;
@@ -1690,11 +1744,11 @@
 }

-static int sx_put_char(struct tty_struct * tty, unsigned char ch)
+static int sx_put_char(struct tty_struct *tty, unsigned char ch)
 {
 	struct specialix_port *port = (struct specialix_port *)tty->driver_data;
 	unsigned long flags;
-	struct specialix_board  * bp;
+	struct specialix_board  *bp;

 	func_enter();

@@ -1702,7 +1756,7 @@
 		func_exit();
 		return 0;
 	}
-	dprintk (SX_DEBUG_TX, "check tty: %p %p\n", tty, port->xmit_buf);
+	dprintk(SX_DEBUG_TX, "check tty: %p %p\n", tty, port->xmit_buf);
 	if (!port->xmit_buf) {
 		func_exit();
 		return 0;
@@ -1710,14 +1764,15 @@
 	bp = port_Board(port);
 	spin_lock_irqsave(&port->lock, flags);

-	dprintk (SX_DEBUG_TX, "xmit_cnt: %d xmit_buf: %p\n", port->xmit_cnt, port->xmit_buf);
-	if ((port->xmit_cnt >= SERIAL_XMIT_SIZE - 1) || (!port->xmit_buf)) {
+	dprintk(SX_DEBUG_TX, "xmit_cnt: %d xmit_buf: %p\n",
+					port->xmit_cnt, port->xmit_buf);
+	if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1 || !port->xmit_buf) {
 		spin_unlock_irqrestore(&port->lock, flags);
-		dprintk (SX_DEBUG_TX, "Exit size\n");
+		dprintk(SX_DEBUG_TX, "Exit size\n");
 		func_exit();
 		return 0;
 	}
-	dprintk (SX_DEBUG_TX, "Handle xmit: %p %p\n", port, port->xmit_buf);
+	dprintk(SX_DEBUG_TX, "Handle xmit: %p %p\n", port, port->xmit_buf);
 	port->xmit_buf[port->xmit_head++] = ch;
 	port->xmit_head &= SERIAL_XMIT_SIZE - 1;
 	port->xmit_cnt++;
@@ -1728,11 +1783,11 @@
 }

-static void sx_flush_chars(struct tty_struct * tty)
+static void sx_flush_chars(struct tty_struct *tty)
 {
 	struct specialix_port *port = (struct specialix_port *)tty->driver_data;
 	unsigned long flags;
-	struct specialix_board  * bp = port_Board(port);
+	struct specialix_board  *bp = port_Board(port);

 	func_enter();

@@ -1755,7 +1810,7 @@
 }

-static int sx_write_room(struct tty_struct * tty)
+static int sx_write_room(struct tty_struct *tty)
 {
 	struct specialix_port *port = (struct specialix_port *)tty->driver_data;
 	int	ret;
@@ -1790,12 +1845,10 @@
 	return port->xmit_cnt;
 }

-
-
 static int sx_tiocmget(struct tty_struct *tty, struct file *file)
 {
 	struct specialix_port *port = (struct specialix_port *)tty->driver_data;
-	struct specialix_board * bp;
+	struct specialix_board *bp;
 	unsigned char status;
 	unsigned int result;
 	unsigned long flags;
@@ -1808,25 +1861,25 @@
 	}

 	bp = port_Board(port);
-	spin_lock_irqsave (&bp->lock, flags);
+	spin_lock_irqsave(&bp->lock, flags);
 	sx_out(bp, CD186x_CAR, port_No(port));
 	status = sx_in(bp, CD186x_MSVR);
 	spin_unlock_irqrestore(&bp->lock, flags);
-	dprintk (SX_DEBUG_INIT, "Got msvr[%d] = %02x, car = %d.\n",
-		port_No(port), status, sx_in (bp, CD186x_CAR));
-	dprintk (SX_DEBUG_INIT, "sx_port = %p, port = %p\n", sx_port, port);
+	dprintk(SX_DEBUG_INIT, "Got msvr[%d] = %02x, car = %d.\n",
+			port_No(port), status, sx_in(bp, CD186x_CAR));
+	dprintk(SX_DEBUG_INIT, "sx_port = %p, port = %p\n", sx_port, port);
 	if (SX_CRTSCTS(port->port.tty)) {
 		result  = /*   (status & MSVR_RTS) ? */ TIOCM_DTR /* : 0) */
-		          |   ((status & MSVR_DTR) ? TIOCM_RTS : 0)
-		          |   ((status & MSVR_CD)  ? TIOCM_CAR : 0)
-		          |/* ((status & MSVR_DSR) ? */ TIOCM_DSR /* : 0) */
-		          |   ((status & MSVR_CTS) ? TIOCM_CTS : 0);
+			  |   ((status & MSVR_DTR) ? TIOCM_RTS : 0)
+			  |   ((status & MSVR_CD)  ? TIOCM_CAR : 0)
+			  |/* ((status & MSVR_DSR) ? */ TIOCM_DSR /* : 0) */
+			  |   ((status & MSVR_CTS) ? TIOCM_CTS : 0);
 	} else {
 		result  = /*   (status & MSVR_RTS) ? */ TIOCM_RTS /* : 0) */
-		          |   ((status & MSVR_DTR) ? TIOCM_DTR : 0)
-		          |   ((status & MSVR_CD)  ? TIOCM_CAR : 0)
-		          |/* ((status & MSVR_DSR) ? */ TIOCM_DSR /* : 0) */
-		          |   ((status & MSVR_CTS) ? TIOCM_CTS : 0);
+			  |   ((status & MSVR_DTR) ? TIOCM_DTR : 0)
+			  |   ((status & MSVR_CD)  ? TIOCM_CAR : 0)
+			  |/* ((status & MSVR_DSR) ? */ TIOCM_DSR /* : 0) */
+			  |   ((status & MSVR_CTS) ? TIOCM_CTS : 0);
 	}

 	func_exit();
@@ -1886,14 +1939,15 @@
 }

-static inline void sx_send_break(struct specialix_port * port, unsigned long length)
+static inline void sx_send_break(struct specialix_port *port,
+						unsigned long length)
 {
 	struct specialix_board *bp = port_Board(port);
 	unsigned long flags;

 	func_enter();

-	spin_lock_irqsave (&port->lock, flags);
+	spin_lock_irqsave(&port->lock, flags);
 	port->break_length = SPECIALIX_TPS / HZ * length;
 	port->COR2 |= COR2_ETC;
 	port->IER  |= IER_TXRDY;
@@ -1902,7 +1956,7 @@
 	sx_out(bp, CD186x_COR2, port->COR2);
 	sx_out(bp, CD186x_IER, port->IER);
 	spin_unlock_irqrestore(&bp->lock, flags);
-	spin_unlock_irqrestore (&port->lock, flags);
+	spin_unlock_irqrestore(&port->lock, flags);
 	sx_wait_CCR(bp);
 	spin_lock_irqsave(&bp->lock, flags);
 	sx_out(bp, CD186x_CCR, CCR_CORCHG2);
@@ -1913,8 +1967,8 @@
 }

-static inline int sx_set_serial_info(struct specialix_port * port,
-                                     struct serial_struct __user * newinfo)
+static inline int sx_set_serial_info(struct specialix_port *port,
+					struct serial_struct __user *newinfo)
 {
 	struct serial_struct tmp;
 	struct specialix_board *bp = port_Board(port);
@@ -1943,25 +1997,25 @@
 			return -EPERM;
 		}
 		port->port.flags = ((port->port.flags & ~ASYNC_USR_MASK) |
-		                  (tmp.flags & ASYNC_USR_MASK));
+						(tmp.flags & ASYNC_USR_MASK));
 		port->custom_divisor = tmp.custom_divisor;
 	} else {
 		port->port.flags = ((port->port.flags & ~ASYNC_FLAGS) |
-		                  (tmp.flags & ASYNC_FLAGS));
+						(tmp.flags & ASYNC_FLAGS));
 		port->port.close_delay = tmp.close_delay;
 		port->port.closing_wait = tmp.closing_wait;
 		port->custom_divisor = tmp.custom_divisor;
 	}
-	if (change_speed) {
+	if (change_speed)
 		sx_change_speed(bp, port);
-	}
+
 	func_exit();
 	unlock_kernel();
 	return 0;
 }

-static inline int sx_get_serial_info(struct specialix_port * port,
+static inline int sx_get_serial_info(struct specialix_port *port,
 				     struct serial_struct __user *retinfo)
 {
 	struct serial_struct tmp;
@@ -1992,8 +2046,8 @@
 }

-static int sx_ioctl(struct tty_struct * tty, struct file * filp,
-                    unsigned int cmd, unsigned long arg)
+static int sx_ioctl(struct tty_struct *tty, struct file *filp,
+				unsigned int cmd, unsigned long arg)
 {
 	struct specialix_port *port = (struct specialix_port *)tty->driver_data;
 	int retval;
@@ -2007,7 +2061,7 @@
 	}

 	switch (cmd) {
-	 case TCSBRK:	/* SVID version: non-zero arg --> no break */
+	case TCSBRK:	/* SVID version: non-zero arg --> no break */
 		retval = tty_check_change(tty);
 		if (retval) {
 			func_exit();
@@ -2017,7 +2071,7 @@
 		if (!arg)
 			sx_send_break(port, HZ/4);	/* 1/4 second */
 		return 0;
-	 case TCSBRKP:	/* support for POSIX tcsendbreak() */
+	case TCSBRKP:	/* support for POSIX tcsendbreak() */
 		retval = tty_check_change(tty);
 		if (retval) {
 			func_exit();
@@ -2027,13 +2081,13 @@
 		sx_send_break(port, arg ? arg*(HZ/10) : HZ/4);
 		func_exit();
 		return 0;
-	 case TIOCGSERIAL:
+	case TIOCGSERIAL:
 		 func_exit();
 		return sx_get_serial_info(port, argp);
-	 case TIOCSSERIAL:
+	case TIOCSSERIAL:
 		 func_exit();
 		return sx_set_serial_info(port, argp);
-	 default:
+	default:
 		 func_exit();
 		return -ENOIOCTLCMD;
 	}
@@ -2042,7 +2096,7 @@
 }

-static void sx_throttle(struct tty_struct * tty)
+static void sx_throttle(struct tty_struct *tty)
 {
 	struct specialix_port *port = (struct specialix_port *)tty->driver_data;
 	struct specialix_board *bp;
@@ -2058,15 +2112,16 @@
 	bp = port_Board(port);

 	/* Use DTR instead of RTS ! */
-	if (SX_CRTSCTS (tty))
+	if (SX_CRTSCTS(tty))
 		port->MSVR &= ~MSVR_DTR;
 	else {
 		/* Auch!!! I think the system shouldn't call this then. */
 		/* Or maybe we're supposed (allowed?) to do our side of hw
 		   handshake anyway, even when hardware handshake is off.
 		   When you see this in your logs, please report.... */
-		printk (KERN_ERR "sx%d: Need to throttle, but can't (hardware hs is off)\n",
-	                 port_No (port));
+		printk(KERN_ERR
+		   "sx%d: Need to throttle, but can't (hardware hs is off)\n",
+							port_No(port));
 	}
 	spin_lock_irqsave(&bp->lock, flags);
 	sx_out(bp, CD186x_CAR, port_No(port));
@@ -2086,7 +2141,7 @@
 }

-static void sx_unthrottle(struct tty_struct * tty)
+static void sx_unthrottle(struct tty_struct *tty)
 {
 	struct specialix_port *port = (struct specialix_port *)tty->driver_data;
 	struct specialix_board *bp;
@@ -2103,9 +2158,9 @@

 	spin_lock_irqsave(&port->lock, flags);
 	/* XXXX Use DTR INSTEAD???? */
-	if (SX_CRTSCTS(tty)) {
+	if (SX_CRTSCTS(tty))
 		port->MSVR |= MSVR_DTR;
-	} /* Else clause: see remark in "sx_throttle"... */
+	/* Else clause: see remark in "sx_throttle"... */
 	spin_lock_irqsave(&bp->lock, flags);
 	sx_out(bp, CD186x_CAR, port_No(port));
 	spin_unlock_irqrestore(&bp->lock, flags);
@@ -2127,7 +2182,7 @@
 }

-static void sx_stop(struct tty_struct * tty)
+static void sx_stop(struct tty_struct *tty)
 {
 	struct specialix_port *port = (struct specialix_port *)tty->driver_data;
 	struct specialix_board *bp;
@@ -2154,7 +2209,7 @@
 }

-static void sx_start(struct tty_struct * tty)
+static void sx_start(struct tty_struct *tty)
 {
 	struct specialix_port *port = (struct specialix_port *)tty->driver_data;
 	struct specialix_board *bp;
@@ -2182,7 +2237,7 @@
 	func_exit();
 }

-static void sx_hangup(struct tty_struct * tty)
+static void sx_hangup(struct tty_struct *tty)
 {
 	struct specialix_port *port = (struct specialix_port *)tty->driver_data;
 	struct specialix_board *bp;
@@ -2201,8 +2256,9 @@
 	spin_lock_irqsave(&port->lock, flags);
 	bp->count -= port->port.count;
 	if (bp->count < 0) {
-		printk(KERN_ERR "sx%d: sx_hangup: bad board count: %d port: %d\n",
-			board_No(bp), bp->count, tty->index);
+		printk(KERN_ERR
+			"sx%d: sx_hangup: bad board count: %d port: %d\n",
+					board_No(bp), bp->count, tty->index);
 		bp->count = 0;
 	}
 	port->port.count = 0;
@@ -2215,11 +2271,12 @@
 }

-static void sx_set_termios(struct tty_struct * tty, struct ktermios * old_termios)
+static void sx_set_termios(struct tty_struct *tty,
+					struct ktermios *old_termios)
 {
 	struct specialix_port *port = (struct specialix_port *)tty->driver_data;
 	unsigned long flags;
-	struct specialix_board  * bp;
+	struct specialix_board  *bp;

 	if (sx_paranoia_check(port, tty->name, "sx_set_termios"))
 		return;
@@ -2283,10 +2340,12 @@
 	specialix_driver->flags = TTY_DRIVER_REAL_RAW;
 	tty_set_operations(specialix_driver, &sx_ops);

-	if ((error = tty_register_driver(specialix_driver))) {
+	error = tty_register_driver(specialix_driver);
+	if (error) {
 		put_tty_driver(specialix_driver);
-		printk(KERN_ERR "sx: Couldn't register specialix IO8+ driver, error = %d\n",
-		       error);
+		printk(KERN_ERR
+		  "sx: Couldn't register specialix IO8+ driver, error = %d\n",
+								error);
 		func_exit();
 		return 1;
 	}
@@ -2323,9 +2382,9 @@
 	printk(KERN_INFO "sx: Specialix IO8+ driver v" VERSION ", (c) R.E.Wolff 1997/1998.\n");
 	printk(KERN_INFO "sx: derived from work (c) D.Gorodchanin 1994-1996.\n");
 #ifdef CONFIG_SPECIALIX_RTSCTS
-	printk (KERN_INFO "sx: DTR/RTS pin is always RTS.\n");
+	printk(KERN_INFO "sx: DTR/RTS pin is always RTS.\n");
 #else
-	printk (KERN_INFO "sx: DTR/RTS pin is RTS when CRTSCTS is on.\n");
+	printk(KERN_INFO "sx: DTR/RTS pin is RTS when CRTSCTS is on.\n");
 #endif

 	for (i = 0; i < SX_NBOARD; i++)
@@ -2344,27 +2403,27 @@
 	{
 		struct pci_dev *pdev = NULL;

-		i=0;
+		i = 0;
 		while (i < SX_NBOARD) {
 			if (sx_board[i].flags & SX_BOARD_PRESENT) {
 				i++;
 				continue;
 			}
-			pdev = pci_get_device (PCI_VENDOR_ID_SPECIALIX,
-			                        PCI_DEVICE_ID_SPECIALIX_IO8,
-			                        pdev);
-			if (!pdev) break;
+			pdev = pci_get_device(PCI_VENDOR_ID_SPECIALIX,
+					PCI_DEVICE_ID_SPECIALIX_IO8, pdev);
+			if (!pdev)
+				break;

 			if (pci_enable_device(pdev))
 				continue;

 			sx_board[i].irq = pdev->irq;

-			sx_board[i].base = pci_resource_start (pdev, 2);
+			sx_board[i].base = pci_resource_start(pdev, 2);

 			sx_board[i].flags |= SX_BOARD_IS_PCI;
 			if (!sx_probe(&sx_board[i]))
-				found ++;
+				found++;
 		}
 		/* May exit pci_get sequence early with lots of boards */
 		if (pdev != NULL)
@@ -2411,10 +2470,10 @@
 	func_enter();

 	if (iobase[0] || iobase[1] || iobase[2] || iobase[3]) {
-		for(i = 0; i < SX_NBOARD; i++) {
+		for (i = 0; i < SX_NBOARD; i++) {
 			sx_board[i].base = iobase[i];
 			sx_board[i].irq = irq[i];
-			sx_board[i].count= 0;
+			sx_board[i].count = 0;
 		}
 	}


ASoC: msm: Add size safety check to ACDB driver

Check that the size sent by userspace is not larger
then the internal amount allowed. This protects
against overflowing the stack due to an invalid size.

Change-Id: I4a5b5ca5212bea32b671027d68a66367c5d4c4e7
CRs-fixed: 470222
Signed-off-by: Ben Romberger <f6edf8d75b12405268138518fb6571756adf9446@codeaurora.org>


clk: wm831x: Provide is_prepared() rather than is_enabled()

Since the driver was written an is_prepared() operation has been made
possible. Since the driver uses I2C I/O only prepare operations are
provided so move the is_enabled() operation over to is_prepared().

Signed-off-by: Mark Brown <b51b9a92386687a9ac927cebfa0f978adeb8cea5@linaro.org>
Signed-off-by: Mike Turquette <6dab61939fc5e23761050a66932f032dceda5ebf@linaro.org>


n2_crypto: Add HMAC support.

n2_crypto: Add HMAC support.

One note is that, unlike with non-HMAC hashes, we can't support
hmac(sha224) using the HMAC_SHA256 opcode.

Signed-off-by: David S. Miller <fe08d3c717adf2ae63592e4c9aec6e3e404d8e3e@davemloft.net>

--- drivers/crypto/n2_core.c
+++ drivers/crypto/n2_core.c
@@ -246,6 +246,7 @@
 	u8			hw_op_hashsz;
 	u8			digest_size;
 	u8			auth_type;
+	u8			hmac_type;
 	struct ahash_alg	alg;
 };

@@ -259,8 +260,34 @@
 	return container_of(ahash_alg, struct n2_ahash_alg, alg);
 }

+struct n2_hmac_alg {
+	const char		*child_alg;
+	struct n2_ahash_alg	derived;
+};
+
+static inline struct n2_hmac_alg *n2_hmac_alg(struct crypto_tfm *tfm)
+{
+	struct crypto_alg *alg = tfm->__crt_alg;
+	struct ahash_alg *ahash_alg;
+
+	ahash_alg = container_of(alg, struct ahash_alg, halg.base);
+
+	return container_of(ahash_alg, struct n2_hmac_alg, derived.alg);
+}
+
 struct n2_hash_ctx {
 	struct crypto_ahash		*fallback_tfm;
+};
+
+#define N2_HASH_KEY_MAX			32 /* HW limit for all HMAC requests */
+
+struct n2_hmac_ctx {
+	struct n2_hash_ctx		base;
+
+	struct crypto_shash		*child_shash;
+
+	int				hash_key_len;
+	unsigned char			hash_key[N2_HASH_KEY_MAX];
 };

 struct n2_hash_req_ctx {
@@ -360,6 +387,94 @@
 	struct n2_hash_ctx *ctx = crypto_ahash_ctx(ahash);

 	crypto_free_ahash(ctx->fallback_tfm);
+}
+
+static int n2_hmac_cra_init(struct crypto_tfm *tfm)
+{
+	const char *fallback_driver_name = tfm->__crt_alg->cra_name;
+	struct crypto_ahash *ahash = __crypto_ahash_cast(tfm);
+	struct n2_hmac_ctx *ctx = crypto_ahash_ctx(ahash);
+	struct n2_hmac_alg *n2alg = n2_hmac_alg(tfm);
+	struct crypto_ahash *fallback_tfm;
+	struct crypto_shash *child_shash;
+	int err;
+
+	fallback_tfm = crypto_alloc_ahash(fallback_driver_name, 0,
+					  CRYPTO_ALG_NEED_FALLBACK);
+	if (IS_ERR(fallback_tfm)) {
+		pr_warning("Fallback driver '%s' could not be loaded!\n",
+			   fallback_driver_name);
+		err = PTR_ERR(fallback_tfm);
+		goto out;
+	}
+
+	child_shash = crypto_alloc_shash(n2alg->child_alg, 0, 0);
+	if (IS_ERR(child_shash)) {
+		pr_warning("Child shash '%s' could not be loaded!\n",
+			   n2alg->child_alg);
+		err = PTR_ERR(child_shash);
+		goto out_free_fallback;
+	}
+
+	crypto_ahash_set_reqsize(ahash, (sizeof(struct n2_hash_req_ctx) +
+					 crypto_ahash_reqsize(fallback_tfm)));
+
+	ctx->child_shash = child_shash;
+	ctx->base.fallback_tfm = fallback_tfm;
+	return 0;
+
+out_free_fallback:
+	crypto_free_ahash(fallback_tfm);
+
+out:
+	return err;
+}
+
+static void n2_hmac_cra_exit(struct crypto_tfm *tfm)
+{
+	struct crypto_ahash *ahash = __crypto_ahash_cast(tfm);
+	struct n2_hmac_ctx *ctx = crypto_ahash_ctx(ahash);
+
+	crypto_free_ahash(ctx->base.fallback_tfm);
+	crypto_free_shash(ctx->child_shash);
+}
+
+static int n2_hmac_async_setkey(struct crypto_ahash *tfm, const u8 *key,
+				unsigned int keylen)
+{
+	struct n2_hmac_ctx *ctx = crypto_ahash_ctx(tfm);
+	struct crypto_shash *child_shash = ctx->child_shash;
+	struct crypto_ahash *fallback_tfm;
+	struct {
+		struct shash_desc shash;
+		char ctx[crypto_shash_descsize(child_shash)];
+	} desc;
+	int err, bs, ds;
+
+	fallback_tfm = ctx->base.fallback_tfm;
+	err = crypto_ahash_setkey(fallback_tfm, key, keylen);
+	if (err)
+		return err;
+
+	desc.shash.tfm = child_shash;
+	desc.shash.flags = crypto_ahash_get_flags(tfm) &
+		CRYPTO_TFM_REQ_MAY_SLEEP;
+
+	bs = crypto_shash_blocksize(child_shash);
+	ds = crypto_shash_digestsize(child_shash);
+	BUG_ON(ds > N2_HASH_KEY_MAX);
+	if (keylen > bs) {
+		err = crypto_shash_digest(&desc.shash, key, keylen,
+					  ctx->hash_key);
+		if (err)
+			return err;
+		keylen = ds;
+	} else if (keylen <= N2_HASH_KEY_MAX)
+		memcpy(ctx->hash_key, key, keylen);
+
+	ctx->hash_key_len = keylen;
+
+	return err;
 }

 static unsigned long wait_for_tail(struct spu_queue *qp)
@@ -393,7 +508,8 @@

 static int n2_do_async_digest(struct ahash_request *req,
 			      unsigned int auth_type, unsigned int digest_size,
-			      unsigned int result_size, void *hash_loc)
+			      unsigned int result_size, void *hash_loc,
+			      unsigned long auth_key, unsigned int auth_key_len)
 {
 	struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
 	struct cwq_initial_entry *ent;
@@ -434,13 +550,13 @@
 	 */
 	ent = qp->q + qp->tail;

-	ent->control = control_word_base(nbytes, 0, 0,
+	ent->control = control_word_base(nbytes, auth_key_len, 0,
 					 auth_type, digest_size,
 					 false, true, false, false,
 					 OPCODE_INPLACE_BIT |
 					 OPCODE_AUTH_MAC);
 	ent->src_addr = __pa(walk.data);
-	ent->auth_key_addr = 0UL;
+	ent->auth_key_addr = auth_key;
 	ent->auth_iv_addr = __pa(hash_loc);
 	ent->final_auth_state_addr = 0UL;
 	ent->enc_key_addr = 0UL;
@@ -494,7 +610,40 @@

 	return n2_do_async_digest(req, n2alg->auth_type,
 				  n2alg->hw_op_hashsz, ds,
-				  &rctx->u);
+				  &rctx->u, 0UL, 0);
+}
+
+static int n2_hmac_async_digest(struct ahash_request *req)
+{
+	struct n2_hmac_alg *n2alg = n2_hmac_alg(req->base.tfm);
+	struct n2_hash_req_ctx *rctx = ahash_request_ctx(req);
+	struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
+	struct n2_hmac_ctx *ctx = crypto_ahash_ctx(tfm);
+	int ds;
+
+	ds = n2alg->derived.digest_size;
+	if (unlikely(req->nbytes == 0) ||
+	    unlikely(ctx->hash_key_len > N2_HASH_KEY_MAX)) {
+		struct n2_hash_req_ctx *rctx = ahash_request_ctx(req);
+		struct n2_hash_ctx *ctx = crypto_ahash_ctx(tfm);
+
+		ahash_request_set_tfm(&rctx->fallback_req, ctx->fallback_tfm);
+		rctx->fallback_req.base.flags =
+			req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP;
+		rctx->fallback_req.nbytes = req->nbytes;
+		rctx->fallback_req.src = req->src;
+		rctx->fallback_req.result = req->result;
+
+		return crypto_ahash_digest(&rctx->fallback_req);
+	}
+	memcpy(&rctx->u, n2alg->derived.hash_init,
+	       n2alg->derived.hw_op_hashsz);
+
+	return n2_do_async_digest(req, n2alg->derived.hmac_type,
+				  n2alg->derived.hw_op_hashsz, ds,
+				  &rctx->u,
+				  __pa(&ctx->hash_key),
+				  ctx->hash_key_len);
 }

 struct n2_cipher_context {
@@ -1127,6 +1276,7 @@
 	u8		digest_size;
 	u8		block_size;
 	u8		auth_type;
+	u8		hmac_type;
 };

 static const char md5_zero[MD5_DIGEST_SIZE] = {
@@ -1173,6 +1323,7 @@
 	  .hash_zero	= md5_zero,
 	  .hash_init	= md5_init,
 	  .auth_type	= AUTH_TYPE_MD5,
+	  .hmac_type	= AUTH_TYPE_HMAC_MD5,
 	  .hw_op_hashsz	= MD5_DIGEST_SIZE,
 	  .digest_size	= MD5_DIGEST_SIZE,
 	  .block_size	= MD5_HMAC_BLOCK_SIZE },
@@ -1180,6 +1331,7 @@
 	  .hash_zero	= sha1_zero,
 	  .hash_init	= sha1_init,
 	  .auth_type	= AUTH_TYPE_SHA1,
+	  .hmac_type	= AUTH_TYPE_HMAC_SHA1,
 	  .hw_op_hashsz	= SHA1_DIGEST_SIZE,
 	  .digest_size	= SHA1_DIGEST_SIZE,
 	  .block_size	= SHA1_BLOCK_SIZE },
@@ -1187,6 +1339,7 @@
 	  .hash_zero	= sha256_zero,
 	  .hash_init	= sha256_init,
 	  .auth_type	= AUTH_TYPE_SHA256,
+	  .hmac_type	= AUTH_TYPE_HMAC_SHA256,
 	  .hw_op_hashsz	= SHA256_DIGEST_SIZE,
 	  .digest_size	= SHA256_DIGEST_SIZE,
 	  .block_size	= SHA256_BLOCK_SIZE },
@@ -1194,6 +1347,7 @@
 	  .hash_zero	= sha224_zero,
 	  .hash_init	= sha224_init,
 	  .auth_type	= AUTH_TYPE_SHA256,
+	  .hmac_type	= AUTH_TYPE_RESERVED,
 	  .hw_op_hashsz	= SHA256_DIGEST_SIZE,
 	  .digest_size	= SHA224_DIGEST_SIZE,
 	  .block_size	= SHA224_BLOCK_SIZE },
@@ -1201,6 +1355,7 @@
 #define NUM_HASH_TMPLS ARRAY_SIZE(hash_tmpls)

 static LIST_HEAD(ahash_algs);
+static LIST_HEAD(hmac_algs);

 static int algs_registered;

@@ -1208,11 +1363,17 @@
 {
 	struct n2_cipher_alg *cipher, *cipher_tmp;
 	struct n2_ahash_alg *alg, *alg_tmp;
+	struct n2_hmac_alg *hmac, *hmac_tmp;

 	list_for_each_entry_safe(cipher, cipher_tmp, &cipher_algs, entry) {
 		crypto_unregister_alg(&cipher->alg);
 		list_del(&cipher->entry);
 		kfree(cipher);
+	}
+	list_for_each_entry_safe(hmac, hmac_tmp, &hmac_algs, derived.entry) {
+		crypto_unregister_ahash(&hmac->derived.alg);
+		list_del(&hmac->derived.entry);
+		kfree(hmac);
 	}
 	list_for_each_entry_safe(alg, alg_tmp, &ahash_algs, entry) {
 		crypto_unregister_ahash(&alg->alg);
@@ -1262,6 +1423,44 @@
 	return err;
 }

+static int __devinit __n2_register_one_hmac(struct n2_ahash_alg *n2ahash)
+{
+	struct n2_hmac_alg *p = kzalloc(sizeof(*p), GFP_KERNEL);
+	struct ahash_alg *ahash;
+	struct crypto_alg *base;
+	int err;
+
+	if (!p)
+		return -ENOMEM;
+
+	p->child_alg = n2ahash->alg.halg.base.cra_name;
+	memcpy(&p->derived, n2ahash, sizeof(struct n2_ahash_alg));
+	INIT_LIST_HEAD(&p->derived.entry);
+
+	ahash = &p->derived.alg;
+	ahash->digest = n2_hmac_async_digest;
+	ahash->setkey = n2_hmac_async_setkey;
+
+	base = &ahash->halg.base;
+	snprintf(base->cra_name, CRYPTO_MAX_ALG_NAME, "hmac(%s)", p->child_alg);
+	snprintf(base->cra_driver_name, CRYPTO_MAX_ALG_NAME, "hmac-%s-n2", p->child_alg);
+
+	base->cra_ctxsize = sizeof(struct n2_hmac_ctx);
+	base->cra_init = n2_hmac_cra_init;
+	base->cra_exit = n2_hmac_cra_exit;
+
+	list_add(&p->derived.entry, &hmac_algs);
+	err = crypto_register_ahash(ahash);
+	if (err) {
+		pr_err("%s alg registration failed\n", base->cra_name);
+		list_del(&p->derived.entry);
+		kfree(p);
+	} else {
+		pr_info("%s alg registered\n", base->cra_name);
+	}
+	return err;
+}
+
 static int __devinit __n2_register_one_ahash(const struct n2_hash_tmpl *tmpl)
 {
 	struct n2_ahash_alg *p = kzalloc(sizeof(*p), GFP_KERNEL);
@@ -1276,6 +1475,7 @@
 	p->hash_zero = tmpl->hash_zero;
 	p->hash_init = tmpl->hash_init;
 	p->auth_type = tmpl->auth_type;
+	p->hmac_type = tmpl->hmac_type;
 	p->hw_op_hashsz = tmpl->hw_op_hashsz;
 	p->digest_size = tmpl->digest_size;

@@ -1309,6 +1509,8 @@
 	} else {
 		pr_info("%s alg registered\n", base->cra_name);
 	}
+	if (!err && p->hmac_type != AUTH_TYPE_RESERVED)
+		err = __n2_register_one_hmac(p);
 	return err;
 }


MdeModulePkg/NvmExpressDxe: Handling return of write to sq and cq db

In case of an async command if updating the submission queue tail
doorbell fails then the command will not be picked up by device and
no completion response will be created. This scenario has to be handled.
Also if we create an AsyncRequest element and insert in the async queue,
it will never receive a completion so in the timer routine this element
won't be freed, resulting in memory leak. Also in case of blocking calls
we should capture the status of updating completion queue head doorbell
register and return it to caller of PassThru.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Suman Prakash <29f1979935153223c5df020a27310a98cb6877ca@samsung.com>
Reviewed-by: Hao Wu <f387b71200577e27ccf5abb090fda0ddd187ec6e@intel.com>

--- MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c
+++ MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c
@@ -603,7 +603,7 @@
     Private->SqTdbl[QueueId].Sqt ^= 1;
   }
   Data = ReadUnaligned32 ((UINT32*)&Private->SqTdbl[QueueId]);
-  PciIo->Mem.Write (
+  Status = PciIo->Mem.Write (
                PciIo,
                EfiPciIoWidthUint32,
                NVME_BAR,
@@ -611,6 +611,10 @@
                1,
                &Data
                );
+
+  if (EFI_ERROR (Status)) {
+    goto EXIT;
+  }

   //
   // For non-blocking requests, return directly if the command is placed
@@ -695,7 +699,7 @@
   }

   Data = ReadUnaligned32 ((UINT32*)&Private->CqHdbl[QueueId]);
-  PciIo->Mem.Write (
+  Status = PciIo->Mem.Write (
                PciIo,
                EfiPciIoWidthUint32,
                NVME_BAR,


Do not change scope in zephir_update_property_zval. See aa126bca

--- kernels/ZendEngine3/object.c
+++ kernels/ZendEngine3/object.c
@@ -650,7 +650,7 @@
 int zephir_update_property_zval(zval *object, const char *property_name,
 								unsigned int property_length, zval *value)
 {
-	zend_class_entry *ce, *scope;
+	zend_class_entry *ce;
 	zval property, sep_value;

 	if (Z_TYPE_P(object) != IS_OBJECT) {
@@ -660,9 +660,6 @@
 		return FAILURE;
 	}

-	/* Backup current scope */
-	scope = zephir_get_scope(0);
-
 	/* Is this function was called from within caller scope */
 	ce = zend_get_called_scope(EG(current_execute_data));
 	if (UNEXPECTED(!ce)) {
@@ -673,9 +670,6 @@
 	if (ce->parent) {
 		ce = zephir_lookup_class_ce(ce, property_name, property_length);
 	}
-
-	/* Use caller's scope */
-	zephir_set_scope(ce);

 	if (!Z_OBJ_HT_P(object)->write_property) {
 		const char *class_name;
@@ -701,9 +695,6 @@
 	   so no Z_TRY_ADDREF_P(value) is necessary */
 	Z_OBJ_HT_P(object)->write_property(object, &property, &sep_value, 0);
 	zval_ptr_dtor(&property);
-
-	/* Restore original scope */
-	zephir_set_scope(scope);

 	return SUCCESS;
 }


gk110: add fmul/ffma fmz bit

gk110: add fmul/ffma fmz bit


dmaengine: jz4780: Fall back on smaller transfer sizes where necessary

For some reason the controller does not support 8 byte transfers (but
does support all other powers of 2 up to 128). In this case fall back
to 4 bytes. In addition, fall back to 128 bytes when any larger power
of 2 would be possible within the alignment constraints, as this is
the maximum supported.

It makes no sense to outright reject 8 or >128 bytes just because the
alignment constraints make those the maximum possible size given the
parameters for the transaction. For instance, this can result in a DMA
from/to an 8 byte aligned address failing.

It is perfectly safe to fall back to smaller transfer sizes, the only
consequence is reduced transfer efficiency, which is far better than
not allowing the transfer at all.

Signed-off-by: Alex Smith <90b1f1e0d9d1df29083c0b820499620b8628880b@imgtec.com>
Cc: Vinod Koul <5cf69c63beb17bf38d63aa0e923ee8256af0e205@intel.com>
Cc: Zubair Lutfullah Kakakhel <ec72f352acb5332d4f13d5809ce8993e793f678d@imgtec.com>
Cc: dfad32b3b0e699adf6450abd6f7d686abcc79ff2@vger.kernel.org
Signed-off-by: Vinod Koul <5cf69c63beb17bf38d63aa0e923ee8256af0e205@intel.com>


Clean up number encoding to not format NULL.

--- ReQL-encode.c
+++ ReQL-encode.c
@@ -121,15 +121,21 @@
       return _reql_string_t_append(json, json_null, 4);
     }
     case _REQL_R_NUM: {
+      char *str = malloc(sizeof(char) * 30);
+
+      if (!str) {
+        return -1;
+      }
+
       double val = _reql_to_number(obj);

-      size_t size = sprintf(NULL, "%f", val);
+      size_t size = sprintf(str, "%g", val);

       if (size > UINT32_MAX) {
         return -1;
       }

-      uint8_t *str = malloc(sizeof(uint8_t) * size);
+      str = realloc(str, sizeof(char) * size);

       if (!str) {
         return -1;
@@ -137,8 +143,8 @@

       int err = -1;

-      if (size == sprintf((char *)str, "%f", val)) {
-        err = _reql_string_t_append(json, str, (uint32_t)size);
+      if (size == sprintf(str, "%g", val)) {
+        err = _reql_string_t_append(json, (uint8_t *)str, (uint32_t)size);
       }

       free(str);


edk2/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.h:
  Fix filename case(sensitivity) issues.

git-svn-id: 5648d1bec6962b0a6d1d1b40eba8cf5cdb62da3d@4827 6f19259b-4bc3-4df7-8a09-765794883524

--- MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.h
+++ MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.h
@@ -26,7 +26,7 @@
 #include <PiDxe.h>

 #include <Protocol/Dhcp4.h>
-#include <Protocol/IP4Config.h>
+#include <Protocol/Ip4Config.h>
 #include <Protocol/ManagedNetwork.h>

 #include <Library/DebugLib.h>


Fix #1946 use ZVAL_NULL

Fix #1946 use ZVAL_NULL

--- kernels/ZendEngine3/string.c
+++ kernels/ZendEngine3/string.c
@@ -1106,8 +1106,8 @@
 	zval rv, tmp_matches;
 	zval *rvp = return_value ? return_value : &rv;

-	ZEPHIR_NULL(&tmp_flags);
-	ZEPHIR_NULL(&tmp_offset);
+	ZVAL_NULL(&tmp_flags);
+	ZVAL_NULL(&tmp_offset);

 	ZVAL_LONG(&tmp_flags, flags);
 	ZVAL_LONG(&tmp_offset, offset);
@@ -1183,7 +1183,7 @@
 	zval zopts;
 	zval *params[2];

-	ZEPHIR_NULL(&zopts);
+	ZVAL_NULL(&zopts);
 	ZVAL_LONG(&zopts, opts);

 	params[0] = v;
@@ -1197,7 +1197,7 @@
 	zval zassoc;
 	zval *params[2];

-	ZEPHIR_NULL(&zassoc);
+	ZVAL_NULL(&zassoc);
 	ZVAL_BOOL(&zassoc, assoc);

 	params[0] = v;


drivers: gpio_nrfx: Correct the way the callbacks are fired

Add additional masking of the pins with fired callback triggers
against the currently enabled callbacks, in order to not call
handlers for callbacks that got disabled in some other callback
handlers that were called in the same ISR execution.

Signed-off-by: Andrzej Głąbek <6788b8d556a8a447102338fc996c42180ecff44e@nordicsemi.no>

--- drivers/gpio/gpio_nrfx.c
+++ drivers/gpio/gpio_nrfx.c
@@ -400,7 +400,25 @@

 static inline void fire_callbacks(struct device *port, u32_t pins)
 {
-	gpio_fire_callbacks(&get_port_data(port)->callbacks, port, pins);
+	struct gpio_nrfx_data *data = get_port_data(port);
+	sys_slist_t *list = &data->callbacks;
+	struct gpio_callback *cb, *tmp;
+
+	/* Instead of calling the common gpio_fire_callbacks() function,
+	 * iterate the list of callbacks locally, to be able to perform
+	 * additional masking of the pins and to call handlers only for
+	 * the currently enabled callbacks.
+	 */
+	SYS_SLIST_FOR_EACH_CONTAINER_SAFE(list, cb, tmp, node) {
+		/* Check currently enabled callbacks (data->int_en) in each
+		 * iteration, as some callbacks may get disabled also in any
+		 * of the handlers called here.
+		 */
+		if ((cb->pin_mask & pins) & data->int_en) {
+			__ASSERT(cb->handler, "No callback handler!");
+			cb->handler(port, cb, pins);
+		}
+	}
 }

 #ifdef CONFIG_GPIO_NRF_P0


o Improve interrupt handler;  fixes TX watchdog timeouts on my zaurus.
o Add /* FALLTHROUGH */'s to state handler (spotted by claudio@).
o Adapt debug levels.

OK claudio@

--- dev/pcmcia/if_malo.c
+++ dev/pcmcia/if_malo.c
@@ -1,4 +1,4 @@
-/*      $OpenBSD: if_malo.c,v 1.32 2007/08/03 08:27:15 claudio Exp $ */
+/*      $OpenBSD: if_malo.c,v 1.33 2007/08/04 12:02:36 mglocker Exp $ */

 /*
  * Copyright (c) 2007 Marcus Glocker <mglocker@openbsd.org>
@@ -60,7 +60,7 @@
  */

 #ifdef CMALO_DEBUG
-int cmalo_d = 2;
+int cmalo_d = 1;
 #define DPRINTF(l, x...)	do { if ((l) <= cmalo_d) printf(x); } while (0)
 #else
 #define DPRINTF(l, x...)
@@ -702,10 +702,12 @@
 			DPRINTF(1, "%s: newstate is IEEE80211_S_AUTH\n",
 			    sc->sc_dev.dv_xname);
 			cmalo_cmd_set_auth(sc);
+			/* FALLTHROUGH */
 		case IEEE80211_S_ASSOC:
 			DPRINTF(1, "%s: newstate is IEEE80211_S_ASSOC\n",
 			    sc->sc_dev.dv_xname);
 			cmalo_cmd_set_assoc(sc);
+			/* FALLTHROUGH */
 		case IEEE80211_S_RUN:
 			DPRINTF(1, "%s: newstate is IEEE80211_S_RUN\n",
 			    sc->sc_dev.dv_xname);
@@ -746,10 +748,10 @@
 cmalo_intr(void *arg)
 {
 	struct malo_softc *sc = arg;
-	uint16_t intr;
-
+	uint16_t intr = 0;
+
+	/* read interrupt reason */
 	intr = MALO_READ_2(sc, MALO_REG_HOST_INTR_CAUSE);
-
 	if (intr == 0) {
 		/* interrupt not for us */
 		return (0);
@@ -758,6 +760,16 @@
 		/* card has been detached */
 		return (0);
 	}
+
+	/* disable interrupts */
+	cmalo_intr_mask(sc, 0);
+
+	/* acknowledge interrupt */
+	MALO_WRITE_2(sc, MALO_REG_HOST_INTR_CAUSE,
+	    intr & MALO_VAL_HOST_INTR_MASK_ON);
+
+	/* enable interrupts */
+	cmalo_intr_mask(sc, 1);

 	DPRINTF(2, "%s: interrupt handler called (intr = 0x%04x)\n",
 	    sc->sc_dev.dv_xname, intr);
@@ -772,10 +784,6 @@
 		/* command response */
 		sc->sc_cmd_running = 0;

-	/* acknowledge interrupt */
-	intr &= MALO_VAL_HOST_INTR_MASK_ON;
-	MALO_WRITE_2(sc, MALO_REG_HOST_INTR_CAUSE, intr);
-
 	return (1);
 }

@@ -786,7 +794,7 @@

 	val16 = MALO_READ_2(sc, MALO_REG_HOST_INTR_MASK);

-	DPRINTF(1, "%s: intr mask changed from 0x%04x ",
+	DPRINTF(3, "%s: intr mask changed from 0x%04x ",
 	    sc->sc_dev.dv_xname, val16);

 	if (enable)
@@ -798,7 +806,7 @@

 	val16 = MALO_READ_2(sc, MALO_REG_HOST_INTR_MASK);

-	DPRINTF(1, "to 0x%04x\n", val16);
+	DPRINTF(3, "to 0x%04x\n", val16);
 }

 void
@@ -970,7 +978,7 @@
 		}
 	}

-	DPRINTF(2, "best network found is %s\n",
+	DPRINTF(1, "best network found is %s\n",
 	    sc->sc_aps[sc->sc_aps_best].ssid);
 }


gpu: host1x: Don't reset firewall between gathers

The firewall was reinitialised for each gather. Because the filter
was reinitialised, it did not track the class over gather boundaries.
This allowed the user application to set host1x class to one class
in one gather and use that class in another gather without firewall
having knowledge about that.

Signed-off-by: Terje Bergstrom <b8d9c01712a06e0617f9ca052381cbc8aad1ec73@nvidia.com>
Signed-off-by: Arto Merilainen <f2f2f691d1bcf3783f3a51cbc67af7660823b80a@nvidia.com>
Signed-off-by: Thierry Reding <b75a4d02013b0e68ae2c6bb0dcfd4b7bec282dc9@gmail.com>

--- drivers/gpu/host1x/job.c
+++ drivers/gpu/host1x/job.c
@@ -376,69 +376,60 @@
 	return 0;
 }

-static int validate(struct host1x_job *job, struct device *dev,
-		    struct host1x_job_gather *g)
+static int validate(struct host1x_firewall *fw, struct host1x_job_gather *g)
 {
 	u32 *cmdbuf_base;
 	int err = 0;
-	struct host1x_firewall fw;
-
-	fw.job = job;
-	fw.dev = dev;
-	fw.reloc = job->relocarray;
-	fw.num_relocs = job->num_relocs;
-	fw.cmdbuf_id = g->bo;
-
-	fw.offset = 0;
-	fw.class = 0;
-
-	if (!job->is_addr_reg)
+
+	if (!fw->job->is_addr_reg)
 		return 0;

 	cmdbuf_base = host1x_bo_mmap(g->bo);
 	if (!cmdbuf_base)
 		return -ENOMEM;
-
-	fw.words = g->words;
-	while (fw.words && !err) {
-		u32 word = cmdbuf_base[fw.offset];
+	fw->words = g->words;
+	fw->cmdbuf_id = g->bo;
+	fw->offset = 0;
+
+	while (fw->words && !err) {
+		u32 word = cmdbuf_base[fw->offset];
 		u32 opcode = (word & 0xf0000000) >> 28;

-		fw.mask = 0;
-		fw.reg = 0;
-		fw.count = 0;
-		fw.words--;
-		fw.offset++;
+		fw->mask = 0;
+		fw->reg = 0;
+		fw->count = 0;
+		fw->words--;
+		fw->offset++;

 		switch (opcode) {
 		case 0:
-			fw.class = word >> 6 & 0x3ff;
-			fw.mask = word & 0x3f;
-			fw.reg = word >> 16 & 0xfff;
-			err = check_mask(&fw);
+			fw->class = word >> 6 & 0x3ff;
+			fw->mask = word & 0x3f;
+			fw->reg = word >> 16 & 0xfff;
+			err = check_mask(fw);
 			if (err)
 				goto out;
 			break;
 		case 1:
-			fw.reg = word >> 16 & 0xfff;
-			fw.count = word & 0xffff;
-			err = check_incr(&fw);
+			fw->reg = word >> 16 & 0xfff;
+			fw->count = word & 0xffff;
+			err = check_incr(fw);
 			if (err)
 				goto out;
 			break;

 		case 2:
-			fw.reg = word >> 16 & 0xfff;
-			fw.count = word & 0xffff;
-			err = check_nonincr(&fw);
+			fw->reg = word >> 16 & 0xfff;
+			fw->count = word & 0xffff;
+			err = check_nonincr(fw);
 			if (err)
 				goto out;
 			break;

 		case 3:
-			fw.mask = word & 0xffff;
-			fw.reg = word >> 16 & 0xfff;
-			err = check_mask(&fw);
+			fw->mask = word & 0xffff;
+			fw->reg = word >> 16 & 0xfff;
+			err = check_mask(fw);
 			if (err)
 				goto out;
 			break;
@@ -453,12 +444,10 @@
 	}

 	/* No relocs should remain at this point */
-	if (fw.num_relocs)
+	if (fw->num_relocs)
 		err = -EINVAL;

 out:
-	host1x_bo_munmap(g->bo, cmdbuf_base);
-
 	return err;
 }

@@ -508,7 +497,14 @@
 	int err;
 	unsigned int i, j;
 	struct host1x *host = dev_get_drvdata(dev->parent);
+	struct host1x_firewall fw;
 	DECLARE_BITMAP(waitchk_mask, host1x_syncpt_nb_pts(host));
+
+	fw.job = job;
+	fw.dev = dev;
+	fw.reloc = job->relocarray;
+	fw.num_relocs = job->num_relocs;
+	fw.class = 0;

 	bitmap_zero(waitchk_mask, host1x_syncpt_nb_pts(host));
 	for (i = 0; i < job->num_waitchk; i++) {
@@ -543,7 +539,7 @@
 		err = 0;

 		if (IS_ENABLED(CONFIG_TEGRA_HOST1X_FIREWALL))
-			err = validate(job, dev, g);
+			err = validate(&fw, g);

 		if (err)
 			dev_err(dev, "Job invalid (err=%d)\n", err);