git-svn-id: https://www.imagemagick.org/subversion/ImageMagick/trunk@1031 aa41f4f7-0bf4-0310-aa73-e5a19afd5a74

--- magick/resize.c
+++ magick/resize.c
@@ -82,11 +82,11 @@
   MagickRealType
     (*filter)(const MagickRealType,const ResizeFilter *),
     (*window)(const MagickRealType,const ResizeFilter *),
-    support,   /* filter region of support - the filter support limit */
-    window_support,  /* window support, usally equal to support (expert only) */
-    scale,     /* dimension to scale to fit window support (usally 1.0) */
-    blur,      /* x-scale (blur-sharpen) */
-    cubic[8];  /* cubic coefficents for smooth Cubic filters */
+    support,        /* filter region of support - the filter support limit */
+    window_support, /* window support, usally equal to support (expert only) */
+    scale,          /* dimension to scale to fit window support (usally 1.0) */
+    blur,           /* x-scale (blur-sharpen) */
+    cubic[8];       /* cubic coefficents for smooth Cubic filters */

   unsigned long
     signature;
@@ -112,24 +112,25 @@
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  These are the various filter and windowing functions that are provided,
-%
-%  They are all internal to this module only.  See AcquireResizeFilterInfo()
-%  for details of the access to these functions, via the
-%  GetResizeFilterSupport() and GetResizeFilterWeight() API interface.
+%  These are the various filter and windowing functions that are provided.
+%
+%  They are internal to this module only.  See AcquireResizeFilterInfo() for
+%  details of the access to these functions, via the GetResizeFilterSupport()
+%  and GetResizeFilterWeight() API interface.
 %
 %  The individual filter functions have this format...
 %
 %     static MagickRealtype *FilterName(const MagickRealType x,
 %        const MagickRealType support)
 %
-%    o x: the distance from the sampling point
-%         generally in the range of  0 to support
-%         The GetResizeFilterWeight() ensures this a positive value.
-%
-%    o resize_filter: Current Filter Information
-%        This allows function to access support, and posibly other
-%        pre-calculated information defineding the functions.
+%  A description of each parameter follows:
+%
+%    o x: the distance from the sampling point generally in the range of 0 to
+%      support.  The GetResizeFilterWeight() ensures this a positive value.
+%
+%    o resize_filter: current filter information.  This allows function to
+%      access support, and possibly other pre-calculated information defining
+%      the functions.
 %
 */

@@ -139,10 +140,9 @@
   /*
     See Pratt "Digital Image Processing" p.97 for Bessel functions

-    This function actually a X-scaled Jinc(x) function.
-      http://mathworld.wolfram.com/JincFunction.html
-    And on page 11 of...
-      http://www.ph.ed.ac.uk/%7ewjh/teaching/mo/slides/lens/lens.pdf
+    This function actually a X-scaled Jinc(x) function. See
+    http://mathworld.wolfram.com/JincFunction.html and page 11 of
+    http://www.ph.ed.ac.uk/%7ewjh/teaching/mo/slides/lens/lens.pdf
   */
   if (x == 0.0)
     return((MagickRealType) (MagickPI/4.0));
@@ -187,13 +187,12 @@
     Cubic B-Spline      B= 1  C= 0    Spline Approximation of Gaussian
     Hermite             B= 0  C= 0    Quadratic Spline (support = 1)

-    See paper by Mitchell and Netravali,
-      Reconstruction Filters in Computer Graphics
-      Computer Graphics, Volume 22, Number 4, August 1988
-        http://www.cs.utexas.edu/users/fussell/courses/cs384g/
-                 lectures/mitchell/Mitchell.pdf
-
-    Coefficents are determined from B,C values
+    See paper by Mitchell and Netravali, Reconstruction Filters in Computer
+    Graphics Computer Graphics, Volume 22, Number 4, August 1988
+    http://www.cs.utexas.edu/users/fussell/courses/cs384g/lectures/mitchell/
+    Mitchell.pdf
+
+    Coefficents are determined from B,C values:
        P0 = (  6 - 2*B       )/6
        P1 =         0
        P2 = (-18 +12*B + 6*C )/6
@@ -203,11 +202,11 @@
        Q2 = (      6*B +30*C )/6
        Q3 = (    - 1*B - 6*C )/6

-    Which is used to define the filter...
+    which are used to define the filter:
        P0 + P1*x + P2*x^2 + P3*x^3      0 <= x < 1
        Q0 + Q1*x + Q2*x^2 + Q3*x^3      1 <= x <= 2

-    Which ensures function is continuous in value and derivative (slope).
+    which ensures function is continuous in value and derivative (slope).
   */
   if (x < 1.0)
     return(resize_filter->cubic[0]+x*(resize_filter->cubic[1]+x*
@@ -249,9 +248,9 @@
 #define I0A  (1.0/I0(Alpha))

   /*
-    Kaiser Windowing Function (bessel windowing):
-      Alpha is a free value  from 5 to 8 (currently hardcoded to 6.5)
-      Future: make alphand the IOA pre-calculation, a 'expert' setting.
+    Kaiser Windowing Function (bessel windowing): Alpha is a free value from 5
+    to 8 (currently hardcoded to 6.5).  Future: make alpha the IOA
+    pre-calculation, a 'expert' setting.
   */
   return(I0A*I0(Alpha*sqrt((double) (1.0-x*x))));
 }
@@ -270,15 +269,15 @@
     i;

   /*
-    Lagrange Piece-Wise polynomial fit of Sinc:
-      N is the 'order' of the lagrange function and depends on
-      the overall support window size of the filter. That is for
-      a support of 2, gives a lagrange-4 or piece-wise cubic functions
-
-      Note that n is the specific piece of the piece-wise function to calculate.
-
-      See Survey: Interpolation Methods, IEEE Transactions on Medical Imaging,
-      Vol 18, No 11, November 1999, p1049-1075, -- Equation 27 on p1064
+    Lagrange Piece-Wise polynomial fit of Sinc: N is the 'order' of the
+    lagrange function and depends on the overall support window size of the
+    filter. That is for a support of 2, gives a lagrange-4 or piece-wise cubic
+    functions.
+
+    Note that n is the specific piece of the piece-wise function to calculate.
+
+    See Survey: Interpolation Methods, IEEE Transactions on Medical Imaging,
+    Vol 18, No 11, November 1999, p1049-1075, -- Equation 27 on p1064
   */
   if (x > resize_filter->support)
     return(0.0);
@@ -319,8 +318,8 @@
   const ResizeFilter *magick_unused(resize_filter))
 {
   /*
-    1rd order (linear) B-Spline,  bilinear interpolation,
-    Tent 1D filter, or a Bartlett 2D Cone filter
+    1rd order (linear) B-Spline,  bilinear interpolation, Tent 1D filter, or a
+    Bartlett 2D Cone filter.
   */
   if (x < 1.0)
     return(1.0-x);
@@ -445,12 +444,14 @@
 %        const FilterTypes filter_type, const MagickBooleanType radial,
 %        ExceptionInfo *exception)
 %
+%  A description of each parameter follows:
+%
 %    o image: the image.
 %
 %    o filter: the filter type, defining a preset filter, window and support.
 %
-%    o blur: blur the filter by this amount, use 1.0 if unknown.
-%            Image artifact "filter:blur"  will override this old usage
+%    o blur: blur the filter by this amount, use 1.0 if unknown.  Image
+%      artifact "filter:blur"  will override this old usage
 %
 %    o radial: 1D orthogonal filter (Sinc) or 2D radial filter (Bessel)
 %
@@ -469,7 +470,7 @@
     window_type;

   long
-    filter_artifact;
+    option;

   MagickRealType
     B,
@@ -479,11 +480,11 @@
     *resize_filter;

   /*
-    Table Mapping given Filter, into  Weighting and Windowing functions.
-    A 'Box' windowing function means its a simble non-windowed filter.
-    A 'Sinc' filter function (must be windowed) could be upgraded to a
-    'Bessel' filter if a "cylindrical" filter is requested, unless a "Sinc"
-    filter specifically request.
+    Table Mapping given Filter, into  Weighting and Windowing functions.  A
+    'Box' windowing function means its a simble non-windowed filter.  A 'Sinc'
+    filter function (must be windowed) could be upgraded to a 'Bessel' filter
+    if a "cylindrical" filter is requested, unless a "Sinc" filter specifically
+    request.
   */
   static struct
   {
@@ -518,8 +519,8 @@
   /*
     Table maping the filter/window function from the above table to the actual
     filter/window function call to use.  The default support size for that
-    filter as a weighting function, and the point to scale when that function
-    is used as a windowing function (typ 1.0).
+    filter as a weighting function, and the point to scale when that function is
+    used as a windowing function (typ 1.0).
   */
   static struct
   {
@@ -555,10 +556,10 @@
     { Triangle,  1.0f,  1.0f, 0.0f, 0.0f }  /* Bartlett, Triangle windowing */
   };
   /*
-    The known zero crossings of the Bessel() or the Jinc(x*PI) function
-    Found by using
-      http://cose.math.bas.bg/webMathematica/webComputing/BesselZeros.jsp
-    for Jv-function with v=1,  then dividing X-roots by PI (tabled below)
+    The known zero crossings of the Bessel() or the Jinc(x*PI) function found
+    by using http://cose.math.bas.bg/webMathematica/webComputing/
+    BesselZeros.jsp.  For Jv-function with v=1, divide X-roots by PI (tabled
+    below).
   */
   static MagickRealType
     bessel_zeros[16] =
@@ -581,6 +582,9 @@
       16.247661874701f
    };

+  /*
+    Allocate resize filter.
+  */
   assert(image != (const Image *) NULL);
   assert(image->signature == MagickSignature);
   if (image->debug != MagickFalse)
@@ -588,157 +592,204 @@
   assert(UndefinedFilter < filter && filter < SentinelFilter);
   assert(exception != (ExceptionInfo *) NULL);
   assert(exception->signature == MagickSignature);
-
   resize_filter=(ResizeFilter *) AcquireAlignedMemory(1,sizeof(*resize_filter));
   if (resize_filter == (ResizeFilter *) NULL)
     ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
-
-  /* defaults for the requested filter */
-  filter_type = mapping[filter].filter;
-  window_type = mapping[filter].window;
-
-
-  /* Filter blur -- scaling both filter and support window */
-  resize_filter->blur = blur;
+  /*
+    Defaults for the requested filter.
+  */
+  filter_type=mapping[filter].filter;
+  window_type=mapping[filter].window;
+  /*
+    Filter blur -- scaling both filter and support window.
+  */
+  resize_filter->blur=blur;
   artifact=GetImageArtifact(image,"filter:blur");
   if (artifact != (const char *) NULL)
-    resize_filter->blur = StringToDouble(artifact);
-  if ( resize_filter->blur < MagickEpsilon )
-    resize_filter->blur = (MagickRealType) MagickEpsilon;
-
-  /* Modifications for Cylindrical filter use */
-  if ( cylindrical != MagickFalse && filter != SincFilter ) {
-    /* promote 1D Sinc Filter to a 2D Bessel filter */
-    if ( filter_type == SincFilter )
-      filter_type = BesselFilter;
-    /* Prompote Lanczos (Sinc-Sinc) to Lanczos (Bessel-Bessel) */
-    else if ( filter_type == LanczosFilter ) {
-      filter_type = BesselFilter;
-      window_type = BesselFilter;
-    }
-   /* Blur other filters appropriatally correct cylindrical usage */
-    else if ( filter_type == GaussianFilter )
-      /* Gaussian is scaled by  4*ln(2) and not 4*sqrt(2/MagickPI)
-         - according to Paul Heckbert's paper on EWA resampling */
-      resize_filter->blur *= 2.0*log(2.0)/sqrt(2.0/MagickPI);
-    else if ( filter_type != BesselFilter )
-      /* filters with a 1.0 zero root crossing by the first bessel_zero */
-      resize_filter->blur *= bessel_zeros[0];
-  }
-
-  /* Override Filter Selection */
-  artifact=GetImageArtifact(image,"filter:filter");
-  if (artifact != (const char *) NULL) {
-    /* raw filter request - no window function */
-    filter_artifact=ParseMagickOption(MagickFilterOptions,
-         MagickFalse,artifact);
-    if ( UndefinedFilter < filter_artifact &&
-             filter_artifact < SentinelFilter ) {
-      filter_type = (FilterTypes) filter_artifact;
-      window_type = BoxFilter;
-    }
-    /* Lanczos is nor a real filter but a self windowing Sinc/Bessel */
-    if ( filter_artifact == LanczosFilter ) {
-      filter_type = (cylindrical!=MagickFalse) ? BesselFilter : LanczosFilter;
-      window_type = (cylindrical!=MagickFalse) ? BesselFilter : SincFilter;
-    }
-    /* Filter overwide with a specific window function? */
-    artifact=GetImageArtifact(image,"filter:window");
-    if (artifact != (const char *) NULL) {
-      filter_artifact=ParseMagickOption(MagickFilterOptions,
-            MagickFalse,artifact);
-      if ( UndefinedFilter < filter_artifact &&
-               filter_artifact < SentinelFilter ) {
-        if ( filter_artifact != LanczosFilter )
-          window_type = (FilterTypes) filter_artifact;
-        else
-          window_type = (cylindrical!=MagickFalse) ? BesselFilter : SincFilter;
+    resize_filter->blur=StringToDouble(artifact);
+  if (resize_filter->blur < MagickEpsilon)
+    resize_filter->blur=(MagickRealType) MagickEpsilon;
+  if ((cylindrical != MagickFalse) && (filter != SincFilter))
+    switch (filter_type)
+    {
+      case SincFilter:
+      {
+        /*
+          Promote 1D Sinc Filter to a 2D Bessel filter.
+        */
+        filter_type=BesselFilter;
+        break;
+      }
+      case LanczosFilter:
+      {
+        /*
+          Promote Lanczos (Sinc-Sinc) to Lanczos (Bessel-Bessel).
+        */
+        filter_type=BesselFilter;
+        window_type=BesselFilter;
+        break;
+      }
+      case GaussianFilter:
+      {
+        /*
+          Gaussian is scaled by 4*ln(2) and not 4*sqrt(2/MagickPI) according to
+          Paul Heckbert's paper on EWA resampling.
+        */
+        resize_filter->blur*=2.0*log(2.0)/sqrt(2.0/MagickPI);
+        break;
+      }
+      case BesselFilter:
+      {
+        /*
+          Filters with a 1.0 zero root crossing by the first bessel zero.
+        */
+        resize_filter->blur*=bessel_zeros[0];
+        break;
       }
     }
-  }
-  else {
-    /* window specified, but no filter function?  Assume Sinc/Bessel */
-    artifact=GetImageArtifact(image,"filter:window");
-    if (artifact != (const char *) NULL) {
-      filter_artifact=ParseMagickOption(MagickFilterOptions,MagickFalse,
+  artifact=GetImageArtifact(image,"filter:filter");
+  if (artifact != (const char *) NULL)
+    {
+      option=ParseMagickOption(MagickFilterOptions,MagickFalse,
         artifact);
-      if ( UndefinedFilter < filter_artifact &&
-               filter_artifact < SentinelFilter ) {
-        filter_type = (cylindrical!=MagickFalse) ? BesselFilter : SincFilter;
-        if ( filter_artifact != LanczosFilter )
-          window_type = (FilterTypes) filter_artifact;
-        else
-          window_type = filter_type;
-      }
+      if ((UndefinedFilter < option) && (option < SentinelFilter))
+        {
+          /*
+            Raw filter request - no window function.
+          */
+          filter_type=(FilterTypes) option;
+          window_type=BoxFilter;
+        }
+      if (option == LanczosFilter)
+        {
+          /*
+            Lanczos is nor a real filter but a self windowing Sinc/Bessel.
+          */
+          filter_type=cylindrical != MagickFalse ? BesselFilter : LanczosFilter;
+          window_type=cylindrical != MagickFalse ? BesselFilter : SincFilter;
+        }
+      /*
+        Filter overwide with a specific window function.
+      */
+      artifact=GetImageArtifact(image,"filter:window");
+      if (artifact != (const char *) NULL)
+        {
+          option=ParseMagickOption(MagickFilterOptions,MagickFalse,
+            artifact);
+          if ((UndefinedFilter < option) && (option < SentinelFilter))
+            {
+              if (option != LanczosFilter)
+                window_type=(FilterTypes) option;
+             else
+               window_type=cylindrical != MagickFalse ? BesselFilter :
+                 SincFilter;
+           }
+        }
     }
-  }
-
-  resize_filter->filter   = filters[filter_type].function;
-  resize_filter->support  = filters[filter_type].support;
-  resize_filter->window   = filters[window_type].function;
-  resize_filter->scale    = filters[window_type].scale;
+  else
+    {
+      /*
+        Window specified, but no filter function?  Assume Sinc/Bessel.
+      */
+      artifact=GetImageArtifact(image,"filter:window");
+      if (artifact != (const char *) NULL)
+        {
+          option=ParseMagickOption(MagickFilterOptions,MagickFalse,
+            artifact);
+          if ((UndefinedFilter < option) && (option < SentinelFilter))
+            {
+              option=cylindrical != MagickFalse ? BesselFilter : SincFilter;
+              if (option != LanczosFilter)
+                window_type=(FilterTypes) option;
+              else
+                window_type=option;
+            }
+        }
+    }
+  resize_filter->filter=filters[filter_type].function;
+  resize_filter->support=filters[filter_type].support;
+  resize_filter->window=filters[window_type].function;
+  resize_filter->scale=filters[window_type].scale;
   resize_filter->signature=MagickSignature;
-
-  /* Filter support overrides */
+  /*
+    Filter support overrides.
+  */
   artifact=GetImageArtifact(image,"filter:lobes");
-  if (artifact != (const char *) NULL) {
-    long lobes = StringToLong(artifact);
-    if ( lobes < 1  ) lobes = 1;
-    resize_filter->support = (MagickRealType) lobes;
-    if ( filter_type == BesselFilter ) {
-      if ( lobes > 16 ) lobes = 16;
-      resize_filter->support = bessel_zeros[lobes-1];
+  if (artifact != (const char *) NULL)
+    {
+      long
+        lobes;
+
+      lobes=StringToLong(artifact);
+      if (lobes < 1)
+        lobes=1;
+      resize_filter->support=(MagickRealType) lobes;
+      if (filter_type == BesselFilter)
+        {
+          if (lobes > 16)
+            lobes=16;
+          resize_filter->support=bessel_zeros[lobes-1];
+        }
     }
-  }
   artifact=GetImageArtifact(image,"filter:support");
   if (artifact != (const char *) NULL)
-    resize_filter->support = fabs(StringToDouble(artifact));
-
-  /* Scale windowing function separatally to the support 'clipping' window
-     that calling operator is planning to actually use. - Expert Use Only
-  */
-  resize_filter->window_support = resize_filter->support;
+    resize_filter->support=fabs(StringToDouble(artifact));
+  /*
+    Scale windowing function separatally to the support 'clipping' window
+    that calling operator is planning to actually use.
+  */
+  resize_filter->window_support=resize_filter->support;
   artifact=GetImageArtifact(image,"filter:win-support");
   if (artifact != (const char *) NULL)
-    resize_filter->window_support = fabs(StringToDouble(artifact));
-
-  /* Set Cubic Spline B,C values, calculate Cubic coefficents */
+    resize_filter->window_support=fabs(StringToDouble(artifact));
+  /*
+    Set Cubic Spline B,C values, calculate Cubic coefficents.
+  */
   B=0.0;
   C=0.0;
-  if ( filters[filter_type].function == CubicBC
-       || filters[window_type].function == CubicBC ) {
-    if ( filters[filter_type].function == CubicBC ) {
-      B=filters[filter_type].B;
-      C=filters[filter_type].C;
-    }
-    else if ( filters[window_type].function == CubicBC ) {
-      B=filters[window_type].B;
-      C=filters[window_type].C;
-    }
-    artifact=GetImageArtifact(image,"filter:b");
-    if (artifact != (const char *) NULL) {
-      B=StringToDouble(artifact);
-      C=(1.0-B)/2.0; /* Calculate C as if it is a Keys cubic filter */
-      artifact=GetImageArtifact(image,"filter:c");
+  if ((filters[filter_type].function == CubicBC) ||
+      (filters[window_type].function == CubicBC))
+    {
+      if (filters[filter_type].function == CubicBC)
+        {
+          B=filters[filter_type].B;
+          C=filters[filter_type].C;
+        }
+      else
+        if (filters[window_type].function == CubicBC)
+          {
+            B=filters[window_type].B;
+            C=filters[window_type].C;
+          }
+      artifact=GetImageArtifact(image,"filter:b");
       if (artifact != (const char *) NULL)
-        C=StringToDouble(artifact);
-    }
-    else {
-      artifact=GetImageArtifact(image,"filter:c");
-      if (artifact != (const char *) NULL) {
-        C=StringToDouble(artifact);
-        B=1.0-2.0*C;  /* Calculate B as if it is a Keys cubic filter */
-      }
-    }
-    /* Convert B,C values into Cubic Coefficents - See CubicBC() */
-    resize_filter->cubic[0]=(  6.0 -2.0*B       )/6.0;
+        {
+          B=StringToDouble(artifact);
+          C=(1.0-B)/2.0; /* Calculate C as if it is a Keys cubic filter */
+          artifact=GetImageArtifact(image,"filter:c");
+          if (artifact != (const char *) NULL)
+            C=StringToDouble(artifact);
+        }
+      else
+        {
+          artifact=GetImageArtifact(image,"filter:c");
+          if (artifact != (const char *) NULL)
+            {
+              C=StringToDouble(artifact);
+              B=1.0-2.0*C;  /* Calculate B as if it is a Keys cubic filter */
+            }
+        }
+    /*
+      Convert B,C values into Cubic Coefficents.  See CubicBC()
+    */
+    resize_filter->cubic[0]=(6.0-2.0*B)/6.0;
     resize_filter->cubic[1]=0.0;
-    resize_filter->cubic[2]=(-18.0+12.0*B+ 6.0*C)/6.0;
-    resize_filter->cubic[3]=( 12.0- 9.0*B- 6.0*C)/6.0;
-    resize_filter->cubic[4]=(       8.0*B+24.0*C)/6.0;
-    resize_filter->cubic[5]=(     -12.0*B-48.0*C)/6.0;
-    resize_filter->cubic[6]=(       6.0*B+30.0*C)/6.0;
-    resize_filter->cubic[7]=(     - 1.0*B- 6.0*C)/6.0;
+    resize_filter->cubic[2]=(-18.0+12.0*B+6.0*C)/6.0;
+    resize_filter->cubic[3]=(12.0-9.0*B-6.0*C)/6.0;
+    resize_filter->cubic[4]=(8.0*B+24.0*C)/6.0;
+    resize_filter->cubic[5]=(-12.0*B-48.0*C)/6.0;
+    resize_filter->cubic[6]=(6.0*B+30.0*C)/6.0;
+    resize_filter->cubic[7]=(- 1.0*B-6.0*C)/6.0;
   }
   artifact=GetImageArtifact(image,"filter:verbose");
   if (artifact != (const char *) NULL)


AEC: Startup phase only runs if reported_delay_enabled

TESTED=trybots, modules_unittests
R=aluebs@webrtc.org, andrew@webrtc.org, kwiberg@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/20379005

git-svn-id: 917f5d3ca488f358c4d40eaec14422cf392ccec9@6005 4adac7df-926f-26a2-2b94-8c16560cd09d

--- webrtc/modules/audio_processing/aec/echo_cancellation.c
+++ webrtc/modules/audio_processing/aec/echo_cancellation.c
@@ -254,7 +254,7 @@
   aecpc->checkBuffSize = 1;
   aecpc->firstVal = 0;

-  aecpc->startup_phase = 1;
+  aecpc->startup_phase = WebRtcAec_reported_delay_enabled(aecpc->aec);
   aecpc->bufSizeStart = 0;
   aecpc->checkBufSizeCtr = 0;
   aecpc->msInSndCardBuf = 0;


comments

comments

--- magick/resize.c
+++ magick/resize.c
@@ -688,8 +688,8 @@
     { SincFastFilter,  BohmanFilter },   /* Bohman -- 2*cosine-sinc          */
     { SincFastFilter,  TriangleFilter }, /* Bartlett -- triangle-sinc        */
     { SincFastFilter,  BoxFilter },      /* Raw fast sinc ("Pade"-type)      */
-    { Lanczos2DFilter, JincFilter },     /* EWA SPECIAL: 2-lobed jinc-jinc   */
-    { RobidouxFilter,  BoxFilter },      /* EWA SPECIAL: cubic "jinc-jinc"   */
+    { Lanczos2DFilter, JincFilter },     /* SPECIAL: 2-lobed jinc-jinc       */
+    { RobidouxFilter,  BoxFilter },      /* SPECIAL: tuned Lanczos2D-like Keys */
   };
   /*
     Table mapping the filter/window from the above table to an actual


perf kmem: Show warning when trying to run stat without record

Sometimes one can mistakenly run 'perf kmem stat' without running 'perf
kmem record' before or with a different configuration like recording
--slab and stat --page.  Show a warning message like the one below to
inform the user:

  # perf kmem stat --page --caller
  No page allocation events found.  Have you run 'perf kmem record --page'?

Signed-off-by: Namhyung Kim <5c915a589b3ddf58cebf14bec41bcc143b37ac3c@kernel.org>
Acked-by: Pekka Enberg <add4fcd06328a394f0ad91feda7ee057316dc5ed@kernel.org>
Cc: David Ahern <b80c1600f604d3b0d768f26f90a76757e76005dd@gmail.com>
Cc: Jiri Olsa <2c6594f608aa3d41e98d48846a6328831f7084ad@redhat.com>
Cc: Joonsoo Kim <d91a346a9a76eb1627d34d097d6cb4c8e5067100@gmail.com>
Cc: Minchan Kim <eee62f459f15dcddf87a8df69e8328e2a2562028@kernel.org>
Cc: Peter Zijlstra <645ca7d3a8d3d4f60557176cd361ea8351edc32b@chello.nl>
Cc: eb778157e2286fdb10f8995701208f41dd1c36dc@kvack.org
Link: http://lkml.kernel.org/r/1430837572-31395-1-git-send-email-5c915a589b3ddf58cebf14bec41bcc143b37ac3c@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <293abb6b76d7791c0732cc517d38c4b5c734b87f@redhat.com>

--- tools/perf/builtin-kmem.c
+++ tools/perf/builtin-kmem.c
@@ -1882,6 +1882,7 @@
 	};
 	struct perf_session *session;
 	int ret = -1;
+	const char errmsg[] = "No %s allocation events found.  Have you run 'perf kmem record --%s'?\n";

 	perf_config(kmem_config, NULL);
 	argc = parse_options_subcommand(argc, argv, kmem_options,
@@ -1908,11 +1909,21 @@
 	if (session == NULL)
 		return -1;

+	if (kmem_slab) {
+		if (!perf_evlist__find_tracepoint_by_name(session->evlist,
+							  "kmem:kmalloc")) {
+			pr_err(errmsg, "slab", "slab");
+			return -1;
+		}
+	}
+
 	if (kmem_page) {
-		struct perf_evsel *evsel = perf_evlist__first(session->evlist);
-
-		if (evsel == NULL || evsel->tp_format == NULL) {
-			pr_err("invalid event found.. aborting\n");
+		struct perf_evsel *evsel;
+
+		evsel = perf_evlist__find_tracepoint_by_name(session->evlist,
+							     "kmem:mm_page_alloc");
+		if (evsel == NULL) {
+			pr_err(errmsg, "page", "page");
 			return -1;
 		}


perf lock: Add "info" subcommand for dumping misc information

This adds the "info" subcommand to perf lock which can be used
to dump metadata like threads or addresses of lock instances.
"map" was removed because info should do the work for it.

This will be useful not only for debugging but also for ordinary
analyzing.

v2: adding example of usage
% sudo ./perf lock info -t
 | Thread ID: comm
 | 	 0: swapper
 |         1: init
 |        18: migration/5
 |        29: events/2
 |        32: events/5
 |        33: events/6
...

% sudo ./perf lock info -m
| Address of instance: name of class
|  0xffff8800b95adae0: &(&sighand->siglock)->rlock
|  0xffff8800bbb41ae0: &(&sighand->siglock)->rlock
|  0xffff8800bf165ae0: &(&sighand->siglock)->rlock
|  0xffff8800b9576a98: &p->cred_guard_mutex
|  0xffff8800bb890a08: &(&p->alloc_lock)->rlock
|  0xffff8800b9522a08: &(&p->alloc_lock)->rlock
|  0xffff8800bb8aaa08: &(&p->alloc_lock)->rlock
|  0xffff8800bba72a08: &(&p->alloc_lock)->rlock
|  0xffff8800bf18ea08: &(&p->alloc_lock)->rlock
|  0xffff8800b8a0d8a0: &(&ip->i_lock)->mr_lock
|  0xffff88009bf818a0: &(&ip->i_lock)->mr_lock
|  0xffff88004c66b8a0: &(&ip->i_lock)->mr_lock
|  0xffff8800bb6478a0: &(shost->host_lock)->rlock

v3: fixed some problems Frederic pointed out
 * better rbtree tracking in dump_threads()
 * removed printf() and used pr_info() and pr_debug()

Signed-off-by: Hitoshi Mitake <8e178328bc156b05d7ba5a975f9f97af5eaf2346@dcl.info.waseda.ac.jp>
Cc: Ingo Molnar <9dbbbf0688fedc85ad4da37637f1a64b8c718ee2@elte.hu>
Cc: Peter Zijlstra <645ca7d3a8d3d4f60557176cd361ea8351edc32b@chello.nl>
Cc: Paul Mackerras <19a0ba370c443ba08d20b5061586430ab449ee8c@samba.org>
Cc: Arnaldo Carvalho de Melo <293abb6b76d7791c0732cc517d38c4b5c734b87f@redhat.com>
Cc: Jens Axboe <165ab144a3ccfd9429d5c6466b275f24fafdb114@oracle.com>
Cc: Jason Baron <af9bd1db766a43cb09b647251c97dbddcd2e59dc@redhat.com>
Cc: Xiao Guangrong <1e0036c3819c78880ef9e9a8457e99783a5661e3@cn.fujitsu.com>
LKML-Reference: <1272863520-16179-1-git-send-email-8e178328bc156b05d7ba5a975f9f97af5eaf2346@dcl.info.waseda.ac.jp>
Signed-off-by: Frederic Weisbecker <e8a1bf9163cb25e93cfd6540f223b3872ea7ee55@gmail.com>

--- tools/perf/builtin-lock.c
+++ tools/perf/builtin-lock.c
@@ -720,15 +720,15 @@
 	char cut_name[20];
 	int bad, total;

-	printf("%20s ", "Name");
-	printf("%10s ", "acquired");
-	printf("%10s ", "contended");
-
-	printf("%15s ", "total wait (ns)");
-	printf("%15s ", "max wait (ns)");
-	printf("%15s ", "min wait (ns)");
-
-	printf("\n\n");
+	pr_info("%20s ", "Name");
+	pr_info("%10s ", "acquired");
+	pr_info("%10s ", "contended");
+
+	pr_info("%15s ", "total wait (ns)");
+	pr_info("%15s ", "max wait (ns)");
+	pr_info("%15s ", "min wait (ns)");
+
+	pr_info("\n\n");

 	bad = total = 0;
 	while ((st = pop_from_result())) {
@@ -741,7 +741,7 @@

 		if (strlen(st->name) < 16) {
 			/* output raw name */
-			printf("%20s ", st->name);
+			pr_info("%20s ", st->name);
 		} else {
 			strncpy(cut_name, st->name, 16);
 			cut_name[16] = '.';
@@ -749,17 +749,17 @@
 			cut_name[18] = '.';
 			cut_name[19] = '\0';
 			/* cut off name for saving output style */
-			printf("%20s ", cut_name);
+			pr_info("%20s ", cut_name);
 		}

-		printf("%10u ", st->nr_acquired);
-		printf("%10u ", st->nr_contended);
-
-		printf("%15llu ", st->wait_time_total);
-		printf("%15llu ", st->wait_time_max);
-		printf("%15llu ", st->wait_time_min == ULLONG_MAX ?
+		pr_info("%10u ", st->nr_acquired);
+		pr_info("%10u ", st->nr_contended);
+
+		pr_info("%15llu ", st->wait_time_total);
+		pr_info("%15llu ", st->wait_time_max);
+		pr_info("%15llu ", st->wait_time_min == ULLONG_MAX ?
 		       0 : st->wait_time_min);
-		printf("\n");
+		pr_info("\n");
 	}

 	{
@@ -768,14 +768,34 @@
 		const char *name[4] =
 			{ "acquire", "acquired", "contended", "release" };

-		printf("\n=== output for debug===\n\n");
-		printf("bad:%d, total:%d\n", bad, total);
-		printf("bad rate:%f\n", (double)(bad / total));
-
-		printf("histogram of events caused bad sequence\n");
+		pr_debug("\n=== output for debug===\n\n");
+		pr_debug("bad:%d, total:%d\n", bad, total);
+		pr_debug("bad rate:%f\n", (double)(bad / total));
+
+		pr_debug("histogram of events caused bad sequence\n");
 		for (i = 0; i < 4; i++)
-			printf(" %10s: %d\n", name[i], bad_hist[i]);
-	}
+			pr_debug(" %10s: %d\n", name[i], bad_hist[i]);
+	}
+}
+
+static int			info_threads;
+static int			info_map;
+
+static void dump_threads(void)
+{
+	struct thread_stat *st;
+	struct rb_node *node;
+	struct thread *t;
+
+	pr_info("%10s: comm\n", "Thread ID");
+
+	node = rb_first(&thread_stats);
+	while (node) {
+		st = container_of(node, struct thread_stat, rb);
+		t = perf_session__findnew(session, st->tid);
+		pr_info("%10d: %s\n", st->tid, t->comm);
+		node = rb_next(node);
+	};
 }

 static void dump_map(void)
@@ -783,11 +803,22 @@
 	unsigned int i;
 	struct lock_stat *st;

+	pr_info("Address of instance: name of class\n");
 	for (i = 0; i < LOCKHASH_SIZE; i++) {
 		list_for_each_entry(st, &lockhash_table[i], hash_entry) {
-			printf("%p: %s\n", st->addr, st->name);
+			pr_info(" %p: %s\n", st->addr, st->name);
 		}
 	}
+}
+
+static void dump_info(void)
+{
+	if (info_threads)
+		dump_threads();
+	else if (info_map)
+		dump_map();
+	else
+		die("Unknown type of information\n");
 }

 static int process_sample_event(event_t *self, struct perf_session *s)
@@ -855,6 +886,19 @@
 	OPT_STRING('k', "key", &sort_key, "acquired",
 		    "key for sorting"),
 	/* TODO: type */
+	OPT_END()
+};
+
+static const char * const info_usage[] = {
+	"perf lock info [<options>]",
+	NULL
+};
+
+static const struct option info_options[] = {
+	OPT_BOOLEAN('t', "threads", &info_threads,
+		    "dump thread list in perf.data"),
+	OPT_BOOLEAN('m', "map", &info_map,
+		    "map of lock instances (name:address table)"),
 	OPT_END()
 };

@@ -929,12 +973,18 @@
 	} else if (!strcmp(argv[0], "trace")) {
 		/* Aliased to 'perf trace' */
 		return cmd_trace(argc, argv, prefix);
-	} else if (!strcmp(argv[0], "map")) {
+	} else if (!strcmp(argv[0], "info")) {
+		if (argc) {
+			argc = parse_options(argc, argv,
+					     info_options, info_usage, 0);
+			if (argc)
+				usage_with_options(info_usage, info_options);
+		}
 		/* recycling report_lock_ops */
 		trace_handler = &report_lock_ops;
 		setup_pager();
 		read_events();
-		dump_map();
+		dump_info();
 	} else {
 		usage_with_options(lock_usage, lock_options);
 	}


perf kvm: Guest userspace samples should not be lumped with host uspace

e.g., perf kvm --host  --guest report -i perf.data --stdio -D
shows:

1 599127912065356 0x143b8 [0x48]: PERF_RECORD_SAMPLE(IP, 5): 5671/5676: 0x7fdf95a061c0 period: 1 addr: 0
... chain: nr:2
.....  0: ffffffffffffff80
.....  1: fffffffffffffe00
 ... thread: qemu-kvm:5671
 ...... dso: <not found>

(IP, 5) means sample in guest userspace. Those samples should not be lumped
into the VMM's host thread. i.e, the report output:

    56.86%  qemu-kvm  [unknown]         [u] 0x00007fdf95a061c0

With this patch the output emphasizes it is a guest userspace hit:

    56.86%  [guest/5671]  [unknown]         [u] 0x00007fdf95a061c0

Looking at 3 VMs (2 64-bit, 1 32-bit) with each running a CPU bound
process (openssl speed), perf report currently shows:

  93.84%  117726   qemu-kvm  [unknown]   [u] 0x00007fd7dcaea8e5

which is wrong. With this patch you get:

  31.50%   39258   [guest/18772]  [unknown]   [u] 0x00007fd7dcaea8e5
  31.50%   39236   [guest/11230]  [unknown]   [u] 0x0000000000a57340
  30.84%   39232   [guest/18395]  [unknown]   [u] 0x00007f66f641e107

Tested-by: Jiri Olsa <2c6594f608aa3d41e98d48846a6328831f7084ad@redhat.com>
Signed-off-by: David Ahern <b80c1600f604d3b0d768f26f90a76757e76005dd@gmail.com>
Cc: Frederic Weisbecker <e8a1bf9163cb25e93cfd6540f223b3872ea7ee55@gmail.com>
Cc: Ingo Molnar <9dbbbf0688fedc85ad4da37637f1a64b8c718ee2@kernel.org>
Cc: Jiri Olsa <2c6594f608aa3d41e98d48846a6328831f7084ad@redhat.com>
Cc: Namhyung Kim <5c915a589b3ddf58cebf14bec41bcc143b37ac3c@kernel.org>
Cc: Peter Zijlstra <3fddac958924aef220f202ca567388ddab3f14a8@infradead.org>
Link: http://lkml.kernel.org/r/1342826756-64663-4-git-send-email-b80c1600f604d3b0d768f26f90a76757e76005dd@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <293abb6b76d7791c0732cc517d38c4b5c734b87f@redhat.com>

--- tools/perf/util/session.c
+++ tools/perf/util/session.c
@@ -918,7 +918,9 @@
 {
 	const u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;

-	if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL && perf_guest) {
+	if (perf_guest &&
+	    ((cpumode == PERF_RECORD_MISC_GUEST_KERNEL) ||
+	     (cpumode == PERF_RECORD_MISC_GUEST_USER))) {
 		u32 pid;

 		if (event->header.type == PERF_RECORD_MMAP)


cc2520: Rework the logic of reading packets

This helps saving stack but also fixes an error when unrelevant packet
detection is made and thus calls read_packet recursively.

Change-Id: I5c1130a369b573f204f30230417e5bcbb97257bc
Signed-off-by: Tomasz Bursztyka <ba81a3a719836727e6857ae83462b9f52ec41006@linux.intel.com>

--- drivers/802.15.4/cc2520.c
+++ drivers/802.15.4/cc2520.c
@@ -830,15 +830,9 @@
 	return true;
 }

-#if CONFIG_TI_CC2520_DEBUG
-#define read_packet() read_packet_debug(__func__)
-static void read_packet_debug(const char *caller);
-#else
-static void read_packet(void);
-#endif
-
 static int cc2520_read(void *buf, unsigned short bufsize)
 {
+	struct cc2520_config *info = cc2520_sgl_dev->config->config_info;
 	uint8_t footer[2];
 	uint8_t len;

@@ -854,22 +848,16 @@

 	getrxbyte(&len);

-	DBG("Incoming packet length: %d\n", len);
-
-	if (len > CC2520_MAX_PACKET_LEN) {
-		/* Oops, we must be out of sync. */
-		flushrx();
-		return 0;
-	}
-
-	if (len <= FOOTER_LEN) {
-		flushrx();
-		return 0;
-	}
-
-	if (len - FOOTER_LEN > bufsize) {
-		flushrx();
-		return 0;
+	DBG("%s: Incoming packet length: %d\n", __func__, len);
+
+	/* Error cases:
+	 * 1     -> out of sync!
+	 * 2 & 3 -> bogus length
+	 */
+	if ((len > CC2520_MAX_PACKET_LEN) ||
+	    (len - FOOTER_LEN > bufsize) ||
+	    (len <= FOOTER_LEN)) {
+		goto error;
 	}

 	getrxdata(buf, len - FOOTER_LEN);
@@ -884,8 +872,7 @@
 				   cc2520_last_correlation);

 	} else {
-		flushrx();
-		len = FOOTER_LEN;
+		goto error;
 	}

 	if (cc2520_pending_packet()) {
@@ -896,53 +883,51 @@
 			 */
 			flushrx();
 		} else {
-			/* Another packet has been received and needs attention. */
-			read_packet();
-		}
-	}
-
-	if (len < FOOTER_LEN) {
-		return 0;
+			/* Another packet might be waiting
+			 * Let's unlock reading_packet_fiber()
+			 */
+			nano_fiber_sem_give(&info->read_lock);
+		}
 	}

 	return len - FOOTER_LEN;
-}
-
-#if CONFIG_TI_CC2520_DEBUG
-static void read_packet_debug(const char *caller)
-#else
+
+error:
+	flushrx();
+	return 0;
+}
+
 static void read_packet(void)
-#endif
 {
 	struct net_buf *buf;
+	int len;

 	buf = l2_buf_get_reserve(0);
-	if (buf) {
-		int len;
-
-		packetbuf_set_attr(buf, PACKETBUF_ATTR_TIMESTAMP,
-				   last_packet_timestamp);
-
-		len = cc2520_read(packetbuf_dataptr(buf), PACKETBUF_SIZE);
-		if (len < 0) {
-			l2_buf_unref(buf);
-			return;
-		}
-
-		packetbuf_set_datalen(buf, len);
-
-#if CONFIG_TI_CC2520_DEBUG
-		DBG("%s: %s: received %d bytes\n", caller, __func__, len);
-#endif
-
-		if (net_driver_15_4_recv_from_hw(buf) < 0) {
-#if CONFIG_TI_CC2520_DEBUG
-			DBG("%s: %s: rdc input failed, packet discarded\n",
-			       caller, __func__);
-#endif
-			l2_buf_unref(buf);
-		}
-	}
+	if (!buf) {
+		DBG("%s: Could not allocate buffer\n", __func__);
+		return;
+	}
+
+	packetbuf_set_attr(buf, PACKETBUF_ATTR_TIMESTAMP,
+			   last_packet_timestamp);
+
+	len = cc2520_read(packetbuf_dataptr(buf), PACKETBUF_SIZE);
+	if (len < 0) {
+		goto out;
+	}
+
+	packetbuf_set_datalen(buf, len);
+
+	DBG("%s: received %d bytes\n", __func__, len);
+
+	if (net_driver_15_4_recv_from_hw(buf) < 0) {
+		DBG("%s: rdc input failed, packet discarded\n", __func__);
+		goto out;
+	}
+
+	return;
+out:
+	l2_buf_unref(buf);
 }

 /* Reading incoming packet, so through SPI, cannot be done directly
@@ -959,9 +944,7 @@
 		nano_fiber_sem_take(&info->read_lock, TICKS_UNLIMITED);

 		cc2520_radio_lock();
-
 		read_packet();
-
 		cc2520_radio_unlock();

 		last_packet_timestamp = cc2520_sfd_start_time;


libata: use flush_work()

libata: use flush_work()

(akpm: bypassed maintainers, sorry.  There are other patches which depend on
this)

Cc: "Maciej W. Rozycki" <78f3a3d9d6e4d907a7d12e475d0a751d6b7e256b@linux-mips.org>
Cc: David Howells <ebac1d06c1688626821bb0e574a037a7a5354e49@redhat.com>
Cc: Jeff Garzik <f3e731dfa293c7a83119d8aacfa41b5d2d780be9@garzik.org>
Cc: Oleg Nesterov <20b70f0af00562e63758b9ee42012ecc96c58590@tv-sign.ru>
Cc: Tejun Heo <ccfba69985e72fbcd9ba8bbb6db43d42971ad06d@gmail.com>
Signed-off-by: Andrew Morton <5c1e68b099950c134891f0b6e179498a8ebe9cf9@linux-foundation.org>
Signed-off-by: Linus Torvalds <69652caca27c8b940640ad396ab71f93cacec34f@linux-foundation.org>

--- drivers/ata/libata-core.c
+++ drivers/ata/libata-core.c
@@ -1316,7 +1316,7 @@
 	spin_unlock_irqrestore(ap->lock, flags);

 	DPRINTK("flush #1\n");
-	flush_workqueue(ata_wq);
+	flush_work(ata_wq, &ap->port_task.work); /* akpm: seems unneeded */

 	/*
 	 * At this point, if a task is running, it's guaranteed to see
@@ -1327,7 +1327,7 @@
 		if (ata_msg_ctl(ap))
 			ata_port_printk(ap, KERN_DEBUG, "%s: flush #2\n",
 					__FUNCTION__);
-		flush_workqueue(ata_wq);
+		flush_work(ata_wq, &ap->port_task.work);
 	}

 	spin_lock_irqsave(ap->lock, flags);
@@ -6475,9 +6475,9 @@
 	/* Flush hotplug task.  The sequence is similar to
 	 * ata_port_flush_task().
 	 */
-	flush_workqueue(ata_aux_wq);
+	flush_work(ata_aux_wq, &ap->hotplug_task.work); /* akpm: why? */
 	cancel_delayed_work(&ap->hotplug_task);
-	flush_workqueue(ata_aux_wq);
+	flush_work(ata_aux_wq, &ap->hotplug_task.work);

  skip_eh:
 	/* remove the associated SCSI host */


测试c语言锁的效率，与java synchronized函数比较，居然java速度更快

error: pathspec 'thread/thread_lock_time.c' did not match any file(s) known to git

--- thread/thread_lock_time.c
+++ thread/thread_lock_time.c
@@ -0,0 +1,64 @@
+#include <stdio.h>
+#include <pthread.h>
+#include <sys/time.h>
+static int value = 0;
+pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+int getValue()
+{
+	pthread_mutex_lock(&mutex);
+	value++;
+	pthread_mutex_unlock(&mutex);
+	return value;
+}
+void *work_thread1(void *p)
+{
+	struct timeval tv1, tv2;
+        gettimeofday(&tv1, NULL);
+        printf("thread1start %ld,%ld\n", tv1.tv_sec, tv1.tv_usec);
+
+        int i = 0;
+        for(i = 0; i < 10000000; i++)
+        {
+		pthread_mutex_lock(&mutex);
+        	value++;
+        	pthread_mutex_unlock(&mutex);
+
+        }
+        gettimeofday(&tv2, NULL);
+        printf("thread1end %ld,%ld value = %d\n", tv2.tv_sec, tv2.tv_usec, value);
+
+	return NULL;
+}
+
+void *work_thread2(void *p)
+{
+	struct timeval tv1, tv2;
+        gettimeofday(&tv1, NULL);
+	printf("thread2start %ld,%ld\n", tv1.tv_sec, tv1.tv_usec);
+
+        int i = 0;
+        for(i = 0; i < 10000000; i++)
+        {
+		pthread_mutex_lock(&mutex);
+        	value++;
+        	pthread_mutex_unlock(&mutex);
+
+        }
+	gettimeofday(&tv2, NULL);
+	printf("thread2end %ld,%ld value = %d\n", tv2.tv_sec, tv2.tv_usec, value);
+        return NULL;
+}
+int main(int argc, char *argv[])
+{
+	pthread_t pid1, pid2;
+	struct timeval tv1, tv2;
+	gettimeofday(&tv1, NULL);
+	printf("main %ld,%ld\n", tv1.tv_sec, tv1.tv_usec);
+	pthread_create(&pid1, NULL, work_thread1, NULL);
+	pthread_create(&pid2, NULL, work_thread2, NULL);
+	pthread_join(pid1, NULL);
+	pthread_join(pid2, NULL);
+	gettimeofday(&tv2, NULL);
+	printf("main %ld,%ld\n", tv2.tv_sec, tv2.tv_usec);
+
+}


pata_cs5536: forward port changes from cs5536

* Fix cable detection to also account for the slave device cable bit.

* Disable UDMA when programming MWDMA in cs5536_set_dmamode().

* Don't change UDMA settings in cs5536_set_piomode().

* Add cs5536_program_dtc() helper.

* Cleanup and uninline cs5536_[read,write]() methods.

Cc: Martin K. Petersen <ec79fe3cf06526bf7a0bbaaf3b589fce59faebb5@mkp.net>
Signed-off-by: Bartlomiej Zolnierkiewicz <248de9df611a028e5eceb9d893a2ed6c24c89ef4@gmail.com>
Signed-off-by: Jeff Garzik <15f615bf7d20c2937c7eb5aa759110fd6768848c@redhat.com>

--- drivers/ata/pata_cs5536.c
+++ drivers/ata/pata_cs5536.c
@@ -1,6 +1,7 @@
 /*
  * pata_cs5536.c	- CS5536 PATA for new ATA layer
  *			  (C) 2007 Martin K. Petersen <mkp@mkp.net>
+ *			  (C) 2011 Bartlomiej Zolnierkiewicz
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
@@ -55,24 +56,16 @@
 #define DRV_VERSION	"0.0.8"

 enum {
+	MSR_IDE_CFG		= 0x51300010,
+	PCI_IDE_CFG		= 0x40,
+
 	CFG			= 0,
-	DTC			= 1,
-	CAST			= 2,
-	ETC			= 3,
-
-	MSR_IDE_BASE		= 0x51300000,
-	MSR_IDE_CFG		= (MSR_IDE_BASE + 0x10),
-	MSR_IDE_DTC		= (MSR_IDE_BASE + 0x12),
-	MSR_IDE_CAST		= (MSR_IDE_BASE + 0x13),
-	MSR_IDE_ETC		= (MSR_IDE_BASE + 0x14),
-
-	PCI_IDE_CFG		= 0x40,
-	PCI_IDE_DTC		= 0x48,
-	PCI_IDE_CAST		= 0x4c,
-	PCI_IDE_ETC		= 0x50,
-
-	IDE_CFG_CHANEN		= 0x2,
-	IDE_CFG_CABLE		= 0x10000,
+	DTC			= 2,
+	CAST			= 3,
+	ETC			= 4,
+
+	IDE_CFG_CHANEN		= (1 << 1),
+	IDE_CFG_CABLE		= (1 << 17) | (1 << 16),

 	IDE_D0_SHIFT		= 24,
 	IDE_D1_SHIFT		= 16,
@@ -84,45 +77,50 @@
 	IDE_CAST_CMD_MASK	= 0xff,
 	IDE_CAST_CMD_SHIFT	= 24,

-	IDE_ETC_NODMA		= 0x03,
-};
-
-static const u32 msr_reg[4] = {
-	MSR_IDE_CFG, MSR_IDE_DTC, MSR_IDE_CAST, MSR_IDE_ETC,
-};
-
-static const u8 pci_reg[4] = {
-	PCI_IDE_CFG, PCI_IDE_DTC, PCI_IDE_CAST, PCI_IDE_ETC,
-};
-
-static inline int cs5536_read(struct pci_dev *pdev, int reg, u32 *val)
+	IDE_ETC_UDMA_MASK	= 0xc0,
+};
+
+static int cs5536_read(struct pci_dev *pdev, int reg, u32 *val)
 {
 	if (unlikely(use_msr)) {
 		u32 dummy __maybe_unused;

-		rdmsr(msr_reg[reg], *val, dummy);
+		rdmsr(MSR_IDE_CFG + reg, *val, dummy);
 		return 0;
 	}

-	return pci_read_config_dword(pdev, pci_reg[reg], val);
-}
-
-static inline int cs5536_write(struct pci_dev *pdev, int reg, int val)
+	return pci_read_config_dword(pdev, PCI_IDE_CFG + reg * 4, val);
+}
+
+static int cs5536_write(struct pci_dev *pdev, int reg, int val)
 {
 	if (unlikely(use_msr)) {
-		wrmsr(msr_reg[reg], val, 0);
+		wrmsr(MSR_IDE_CFG + reg, val, 0);
 		return 0;
 	}

-	return pci_write_config_dword(pdev, pci_reg[reg], val);
+	return pci_write_config_dword(pdev, PCI_IDE_CFG + reg * 4, val);
+}
+
+static void cs5536_program_dtc(struct ata_device *adev, u8 tim)
+{
+	struct pci_dev *pdev = to_pci_dev(adev->link->ap->host->dev);
+	int dshift = adev->devno ? IDE_D1_SHIFT : IDE_D0_SHIFT;
+	u32 dtc;
+
+	cs5536_read(pdev, DTC, &dtc);
+	dtc &= ~(IDE_DRV_MASK << dshift);
+	dtc |= tim << dshift;
+	cs5536_write(pdev, DTC, dtc);
 }

 /**
  *	cs5536_cable_detect	-	detect cable type
  *	@ap: Port to detect on
  *
- *	Perform cable detection for ATA66 capable cable. Return a libata
- *	cable type.
+ *	Perform cable detection for ATA66 capable cable.
+ *
+ *	Returns a cable type.
  */

 static int cs5536_cable_detect(struct ata_port *ap)
@@ -132,7 +130,7 @@

 	cs5536_read(pdev, CFG, &cfg);

-	if (cfg & (IDE_CFG_CABLE << ap->port_no))
+	if (cfg & IDE_CFG_CABLE)
 		return ATA_CBL_PATA80;
 	else
 		return ATA_CBL_PATA40;
@@ -162,19 +160,15 @@
 	struct ata_device *pair = ata_dev_pair(adev);
 	int mode = adev->pio_mode - XFER_PIO_0;
 	int cmdmode = mode;
-	int dshift = adev->devno ? IDE_D1_SHIFT : IDE_D0_SHIFT;
 	int cshift = adev->devno ? IDE_CAST_D1_SHIFT : IDE_CAST_D0_SHIFT;
-	u32 dtc, cast, etc;
+	u32 cast;

 	if (pair)
 		cmdmode = min(mode, pair->pio_mode - XFER_PIO_0);

-	cs5536_read(pdev, DTC, &dtc);
+	cs5536_program_dtc(adev, drv_timings[mode]);
+
 	cs5536_read(pdev, CAST, &cast);
-	cs5536_read(pdev, ETC, &etc);
-
-	dtc &= ~(IDE_DRV_MASK << dshift);
-	dtc |= drv_timings[mode] << dshift;

 	cast &= ~(IDE_CAST_DRV_MASK << cshift);
 	cast |= addr_timings[mode] << cshift;
@@ -182,12 +176,7 @@
 	cast &= ~(IDE_CAST_CMD_MASK << IDE_CAST_CMD_SHIFT);
 	cast |= cmd_timings[cmdmode] << IDE_CAST_CMD_SHIFT;

-	etc &= ~(IDE_DRV_MASK << dshift);
-	etc |= IDE_ETC_NODMA << dshift;
-
-	cs5536_write(pdev, DTC, dtc);
 	cs5536_write(pdev, CAST, cast);
-	cs5536_write(pdev, ETC, etc);
 }

 /**
@@ -208,25 +197,21 @@
 	};

 	struct pci_dev *pdev = to_pci_dev(ap->host->dev);
-	u32 dtc, etc;
+	u32 etc;
 	int mode = adev->dma_mode;
 	int dshift = adev->devno ? IDE_D1_SHIFT : IDE_D0_SHIFT;

+	cs5536_read(pdev, ETC, &etc);
+
 	if (mode >= XFER_UDMA_0) {
-		cs5536_read(pdev, ETC, &etc);
-
 		etc &= ~(IDE_DRV_MASK << dshift);
 		etc |= udma_timings[mode - XFER_UDMA_0] << dshift;
-
-		cs5536_write(pdev, ETC, etc);
 	} else { /* MWDMA */
-		cs5536_read(pdev, DTC, &dtc);
-
-		dtc &= ~(IDE_DRV_MASK << dshift);
-		dtc |= mwdma_timings[mode - XFER_MW_DMA_0] << dshift;
-
-		cs5536_write(pdev, DTC, dtc);
-	}
+		etc &= ~(IDE_ETC_UDMA_MASK << dshift);
+		cs5536_program_dtc(adev, mwdma_timings[mode - XFER_MW_DMA_0]);
+	}
+
+	cs5536_write(pdev, ETC, etc);
 }

 static struct scsi_host_template cs5536_sht = {


[INTERNAL] CompressedSA: pass TConfig to SparseString

--- core/include/seqan/index/index_fm_compressed_sa.h
+++ core/include/seqan/index/index_fm_compressed_sa.h
@@ -111,7 +111,7 @@
     typedef typename SAValue<TText>::Type               TSAValue_;
     typedef typename DefaultIndexStringSpec<TCSA>::Type TSASpec_;
     typedef String<TSAValue_, TSASpec_>                 TSA_;
-    typedef SparseString<TSA_, TSpec>                   Type;
+    typedef SparseString<TSA_, TConfig>                 Type;
 };

 template <typename TText, typename TSpec, typename TConfig>


PM: Permit registration of parentless devices during system suspend

The registration of a new parentless device during system suspend
will not lead to any complications affecting the PM core (the device
will be effectively seen after the subsequent resume has completed),
so remove the code used for detection of such events.

Signed-off-by: Rafael J. Wysocki <a11f87183a953ab11f50fbafff689c5a7fa3506c@sisk.pl>

--- drivers/base/power/main.c
+++ drivers/base/power/main.c
@@ -49,12 +49,6 @@
 static DEFINE_MUTEX(dpm_list_mtx);
 static pm_message_t pm_transition;

-/*
- * Set once the preparation of devices for a PM transition has started, reset
- * before starting to resume devices.  Protected by dpm_list_mtx.
- */
-static bool transition_started;
-
 static int async_error;

 /**
@@ -97,19 +91,9 @@
 		 dev->bus ? dev->bus->name : "No Bus",
 		 kobject_name(&dev->kobj));
 	mutex_lock(&dpm_list_mtx);
-	if (dev->parent) {
-		if (dev->parent->power.in_suspend)
-			dev_warn(dev, "parent %s should not be sleeping\n",
-				 dev_name(dev->parent));
-	} else if (transition_started) {
-		/*
-		 * We refuse to register parentless devices while a PM
-		 * transition is in progress in order to avoid leaving them
-		 * unhandled down the road
-		 */
-		dev_WARN(dev, "Parentless device registered during a PM transaction\n");
-	}
-
+	if (dev->parent && dev->parent->power.in_suspend)
+		dev_warn(dev, "parent %s should not be sleeping\n",
+			dev_name(dev->parent));
 	list_add_tail(&dev->power.entry, &dpm_list);
 	mutex_unlock(&dpm_list_mtx);
 }
@@ -482,7 +466,6 @@
 	ktime_t starttime = ktime_get();

 	mutex_lock(&dpm_list_mtx);
-	transition_started = false;
 	while (!list_empty(&dpm_noirq_list)) {
 		struct device *dev = to_device(dpm_noirq_list.next);
 		int error;
@@ -684,7 +667,6 @@

 	INIT_LIST_HEAD(&list);
 	mutex_lock(&dpm_list_mtx);
-	transition_started = false;
 	while (!list_empty(&dpm_prepared_list)) {
 		struct device *dev = to_device(dpm_prepared_list.prev);

@@ -1020,7 +1002,6 @@
 	int error = 0;

 	mutex_lock(&dpm_list_mtx);
-	transition_started = true;
 	while (!list_empty(&dpm_list)) {
 		struct device *dev = to_device(dpm_list.next);


removed thrust/set_intersection.h resolves issue #239

--- thrust/set_intersection.h
+++ thrust/set_intersection.h
@@ -1,37 +0,0 @@
-/*
- *  Copyright 2008-2010 NVIDIA Corporation
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- */
-
-
-#pragma once
-
-#include <thrust/detail/config.h>
-#include <thrust/set_operations.h>
-
-#if THRUST_HOST_COMPILER == THRUST_HOST_COMPILER_MSVC
-#pragma message("-----------------------------------------------------------------------")
-#pragma message("| DEPRECATION WARNING:                                                 ")
-#pragma message("| thrust/set_intersection.h has been deprecated and will be removed   ")
-#pragma message("| Use thrust/set_operations.h instead                                  ")
-#pragma message("-----------------------------------------------------------------------")
-#else
-#warning -----------------------------------------------------------------------
-#warning | DEPRECATION WARNING:
-#warning | thrust/set_intersection.h has been deprecated and will be removed
-#warning | Use thrust/set_operations.h instead
-#warning -----------------------------------------------------------------------
-#endif // THRUST_HOST_COMPILER_MSVC
-
-


NVMe: Fix FS mount issue (hot-remove followed by hot-add)

After Hot-remove of a device with a mounted partition,
when the device is hot-added again, the new node reappears
as nvme0n1. Mounting this new node fails with the error:

mount: mount /dev/nvme0n1p1 on /mnt failed: File exists.

The old nodes's FS entries still exist and the kernel can't re-create
procfs and sysfs entries for the new node with the same name.
The patch fixes this issue.

Acked-by: Keith Busch <695e2a2c1e39535baaa147c5eb4e5da14054d59f@intel.com>
Signed-off-by: Indraneel M <104a98dc3056695396cec43c74f99640a494375b@samsung.com>
Signed-off-by: Jens Axboe <cd8c6775e60d6f67a6984377324e5290df3d5358@fb.com>


NVMe: Fix IO for extended metadata formats

This fixes io submit ioctl handling when using extended metadata
formats. When these formats are used, the user provides a single virtually
contiguous buffer containing both the block and metadata interleaved,
so the metadata size needs to be added to the total length and not mapped
as a separate transfer.

The command is also driver generated, so this patch does not enforce
blk-integrity extensions provide the metadata buffer.

Reported-by: Marcin Dziegielewski <e4d48ece375657db97fdc5b4571bbed9af09d172@intel.com>
Signed-off-by: Keith Busch <695e2a2c1e39535baaa147c5eb4e5da14054d59f@intel.com>
Signed-off-by: Jens Axboe <cd8c6775e60d6f67a6984377324e5290df3d5358@fb.com>


Bluetooth: Set HCI_QUIRK_STRICT_DUPLICATE_FILTER for BTUSB_INTEL

The Bluetooth controllers from Intel use a strict scanning filter
policy that filters based on Bluetooth device addresses and not on
RSSI. So tell the core about this.

Signed-off-by: Jakub Pawlowski <7e910bc94ec2be6aec7264bab8402b89ddbe3dd7@google.com>
Signed-off-by: Marcel Holtmann <44592b4eea36663c86b994bb0ea99d15309c1c7d@holtmann.org>


drivers: can: can_stm32h7: Fix min timings

Assertions in can_mcan failed because the driver expects values
strictly greater than 0

Signed-off-by: Tomislav Milkovic <2161fd1c3ce8f78557aeb421b2032be96a827bf6@gmail.com>

--- drivers/can/can_stm32h7.c
+++ drivers/can/can_stm32h7.c
@@ -113,14 +113,14 @@
 	 * (FDCAN_NBTP).
 	 */
 	.timing_min = {
-		.sjw = 0x00,
+		.sjw = 0x01,
 		.prop_seg = 0x00,
-		.phase_seg1 = 0x00,
-		.phase_seg2 = 0x00,
-		.prescaler = 0x00
+		.phase_seg1 = 0x01,
+		.phase_seg2 = 0x01,
+		.prescaler = 0x01
 	},
 	.timing_max = {
-		.sjw = 0x7f,
+		.sjw = 0x80,
 		.prop_seg = 0x00,
 		.phase_seg1 = 0x100,
 		.phase_seg2 = 0x80,
@@ -133,11 +133,11 @@
 	 * register (FDCAN_DBTP).
 	 */
 	.timing_data_min = {
-		.sjw = 0x00,
+		.sjw = 0x01,
 		.prop_seg = 0x00,
-		.phase_seg1 = 0x00,
-		.phase_seg2 = 0x00,
-		.prescaler = 0x00
+		.phase_seg1 = 0x01,
+		.phase_seg2 = 0x01,
+		.prescaler = 0x01
 	},
 	.timing_data_max = {
 		.sjw = 0x10,


cpufreq: improve error checking on return values of __cpufreq_governor()

The __cpufreq_governor() function can fail in rare cases especially
if there are bugs in cpufreq drivers.  Thus we must stop processing
as soon as this routine fails, otherwise it may result in undefined
behavior.

This patch adds error checking code whenever this routine is called
from any place.

Signed-off-by: Viresh Kumar <5ff32272b3d9f86512eddc8e0af523fc6f7924e5@linaro.org>
Signed-off-by: Rafael J. Wysocki <27ffc44a8ec6a212fba98cfc3246c6ce8ab131e0@intel.com>


crypto: omap-aes - Staticize local symbols

Local symbols used only in this file are made static.

Signed-off-by: Sachin Kamat <1c3b1584a6008857f36c03c58f657c0fc16fc09e@linaro.org>
Cc: Dmitry Kasatkin <8adb5f95ce8fa26dbddb33bd46c9f98f39d4d75f@nokia.com>
Signed-off-by: Herbert Xu <ef65de1c7be0aa837fe7b25ba9a7739905af6a55@gondor.apana.org.au>


dmaengine: mpc512x: add support for peripheral transfers

Introduce support for slave s/g transfer preparation and the associated
device control callback in the MPC512x DMA controller driver, which adds
support for data transfers between memory and peripheral I/O to the
previously supported mem-to-mem transfers.

Signed-off-by: Alexander Popov <fbe0c0f4048e586113572e612343dfbbb493e306@gmail.com>
[fixed subsytem name]
Signed-off-by: Vinod Koul <5cf69c63beb17bf38d63aa0e923ee8256af0e205@intel.com>

--- drivers/dma/mpc512x_dma.c
+++ drivers/dma/mpc512x_dma.c
@@ -2,6 +2,7 @@
  * Copyright (C) Freescale Semicondutor, Inc. 2007, 2008.
  * Copyright (C) Semihalf 2009
  * Copyright (C) Ilya Yanok, Emcraft Systems 2010
+ * Copyright (C) Alexander Popov, Promcontroller 2014
  *
  * Written by Piotr Ziecik <kosmo@semihalf.com>. Hardware description
  * (defines, structures and comments) was taken from MPC5121 DMA driver
@@ -29,8 +30,18 @@
  */

 /*
- * This is initial version of MPC5121 DMA driver. Only memory to memory
- * transfers are supported (tested using dmatest module).
+ * MPC512x and MPC8308 DMA driver. It supports
+ * memory to memory data transfers (tested using dmatest module) and
+ * data transfers between memory and peripheral I/O memory
+ * by means of slave scatter/gather with these limitations:
+ *  - chunked transfers (described by s/g lists with more than one item)
+ *     are refused as long as proper support for scatter/gather is missing;
+ *  - transfers on MPC8308 always start from software as this SoC appears
+ *     not to have external request lines for peripheral flow control;
+ *  - only peripheral devices with 4-byte FIFO access register are supported;
+ *  - minimal memory <-> I/O memory transfer chunk is 4 bytes and consequently
+ *     source and destination addresses must be 4-byte aligned
+ *     and transfer size must be aligned on (4 * maxburst) boundary;
  */

 #include <linux/module.h>
@@ -189,6 +200,7 @@
 	dma_addr_t			tcd_paddr;
 	int				error;
 	struct list_head		node;
+	int				will_access_peripheral;
 };

 struct mpc_dma_chan {
@@ -200,6 +212,12 @@
 	struct list_head		completed;
 	struct mpc_dma_tcd		*tcd;
 	dma_addr_t			tcd_paddr;
+
+	/* Settings for access to peripheral FIFO */
+	dma_addr_t			src_per_paddr;
+	u32				src_tcd_nunits;
+	dma_addr_t			dst_per_paddr;
+	u32				dst_tcd_nunits;

 	/* Lock for this structure */
 	spinlock_t			lock;
@@ -251,8 +269,23 @@
 	struct mpc_dma_desc *mdesc;
 	int cid = mchan->chan.chan_id;

-	/* Move all queued descriptors to active list */
-	list_splice_tail_init(&mchan->queued, &mchan->active);
+	while (!list_empty(&mchan->queued)) {
+		mdesc = list_first_entry(&mchan->queued,
+						struct mpc_dma_desc, node);
+		/*
+		 * Grab either several mem-to-mem transfer descriptors
+		 * or one peripheral transfer descriptor,
+		 * don't mix mem-to-mem and peripheral transfer descriptors
+		 * within the same 'active' list.
+		 */
+		if (mdesc->will_access_peripheral) {
+			if (list_empty(&mchan->active))
+				list_move_tail(&mdesc->node, &mchan->active);
+			break;
+		} else {
+			list_move_tail(&mdesc->node, &mchan->active);
+		}
+	}

 	/* Chain descriptors into one transaction */
 	list_for_each_entry(mdesc, &mchan->active, node) {
@@ -278,7 +311,17 @@

 	if (first != prev)
 		mdma->tcd[cid].e_sg = 1;
-	out_8(&mdma->regs->dmassrt, cid);
+
+	if (mdma->is_mpc8308) {
+		/* MPC8308, no request lines, software initiated start */
+		out_8(&mdma->regs->dmassrt, cid);
+	} else if (first->will_access_peripheral) {
+		/* Peripherals involved, start by external request signal */
+		out_8(&mdma->regs->dmaserq, cid);
+	} else {
+		/* Memory to memory transfer, software initiated start */
+		out_8(&mdma->regs->dmassrt, cid);
+	}
 }

 /* Handle interrupt on one half of DMA controller (32 channels) */
@@ -596,6 +639,7 @@
 	}

 	mdesc->error = 0;
+	mdesc->will_access_peripheral = 0;
 	tcd = mdesc->tcd;

 	/* Prepare Transfer Control Descriptor for this transaction */
@@ -643,6 +687,193 @@
 	return &mdesc->desc;
 }

+static struct dma_async_tx_descriptor *
+mpc_dma_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
+		unsigned int sg_len, enum dma_transfer_direction direction,
+		unsigned long flags, void *context)
+{
+	struct mpc_dma *mdma = dma_chan_to_mpc_dma(chan);
+	struct mpc_dma_chan *mchan = dma_chan_to_mpc_dma_chan(chan);
+	struct mpc_dma_desc *mdesc = NULL;
+	dma_addr_t per_paddr;
+	u32 tcd_nunits;
+	struct mpc_dma_tcd *tcd;
+	unsigned long iflags;
+	struct scatterlist *sg;
+	size_t len;
+	int iter, i;
+
+	/* Currently there is no proper support for scatter/gather */
+	if (sg_len != 1)
+		return NULL;
+
+	if (!is_slave_direction(direction))
+		return NULL;
+
+	for_each_sg(sgl, sg, sg_len, i) {
+		spin_lock_irqsave(&mchan->lock, iflags);
+
+		mdesc = list_first_entry(&mchan->free,
+						struct mpc_dma_desc, node);
+		if (!mdesc) {
+			spin_unlock_irqrestore(&mchan->lock, iflags);
+			/* Try to free completed descriptors */
+			mpc_dma_process_completed(mdma);
+			return NULL;
+		}
+
+		list_del(&mdesc->node);
+
+		if (direction == DMA_DEV_TO_MEM) {
+			per_paddr = mchan->src_per_paddr;
+			tcd_nunits = mchan->src_tcd_nunits;
+		} else {
+			per_paddr = mchan->dst_per_paddr;
+			tcd_nunits = mchan->dst_tcd_nunits;
+		}
+
+		spin_unlock_irqrestore(&mchan->lock, iflags);
+
+		if (per_paddr == 0 || tcd_nunits == 0)
+			goto err_prep;
+
+		mdesc->error = 0;
+		mdesc->will_access_peripheral = 1;
+
+		/* Prepare Transfer Control Descriptor for this transaction */
+		tcd = mdesc->tcd;
+
+		memset(tcd, 0, sizeof(struct mpc_dma_tcd));
+
+		if (!IS_ALIGNED(sg_dma_address(sg), 4))
+			goto err_prep;
+
+		if (direction == DMA_DEV_TO_MEM) {
+			tcd->saddr = per_paddr;
+			tcd->daddr = sg_dma_address(sg);
+			tcd->soff = 0;
+			tcd->doff = 4;
+		} else {
+			tcd->saddr = sg_dma_address(sg);
+			tcd->daddr = per_paddr;
+			tcd->soff = 4;
+			tcd->doff = 0;
+		}
+
+		tcd->ssize = MPC_DMA_TSIZE_4;
+		tcd->dsize = MPC_DMA_TSIZE_4;
+
+		len = sg_dma_len(sg);
+		tcd->nbytes = tcd_nunits * 4;
+		if (!IS_ALIGNED(len, tcd->nbytes))
+			goto err_prep;
+
+		iter = len / tcd->nbytes;
+		if (iter >= 1 << 15) {
+			/* len is too big */
+			goto err_prep;
+		}
+		/* citer_linkch contains the high bits of iter */
+		tcd->biter = iter & 0x1ff;
+		tcd->biter_linkch = iter >> 9;
+		tcd->citer = tcd->biter;
+		tcd->citer_linkch = tcd->biter_linkch;
+
+		tcd->e_sg = 0;
+		tcd->d_req = 1;
+
+		/* Place descriptor in prepared list */
+		spin_lock_irqsave(&mchan->lock, iflags);
+		list_add_tail(&mdesc->node, &mchan->prepared);
+		spin_unlock_irqrestore(&mchan->lock, iflags);
+	}
+
+	return &mdesc->desc;
+
+err_prep:
+	/* Put the descriptor back */
+	spin_lock_irqsave(&mchan->lock, iflags);
+	list_add_tail(&mdesc->node, &mchan->free);
+	spin_unlock_irqrestore(&mchan->lock, iflags);
+
+	return NULL;
+}
+
+static int mpc_dma_device_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
+							unsigned long arg)
+{
+	struct mpc_dma_chan *mchan;
+	struct mpc_dma *mdma;
+	struct dma_slave_config *cfg;
+	unsigned long flags;
+
+	mchan = dma_chan_to_mpc_dma_chan(chan);
+	switch (cmd) {
+	case DMA_TERMINATE_ALL:
+		/* Disable channel requests */
+		mdma = dma_chan_to_mpc_dma(chan);
+
+		spin_lock_irqsave(&mchan->lock, flags);
+
+		out_8(&mdma->regs->dmacerq, chan->chan_id);
+		list_splice_tail_init(&mchan->prepared, &mchan->free);
+		list_splice_tail_init(&mchan->queued, &mchan->free);
+		list_splice_tail_init(&mchan->active, &mchan->free);
+
+		spin_unlock_irqrestore(&mchan->lock, flags);
+
+		return 0;
+
+	case DMA_SLAVE_CONFIG:
+		/*
+		 * Software constraints:
+		 *  - only transfers between a peripheral device and
+		 *     memory are supported;
+		 *  - only peripheral devices with 4-byte FIFO access register
+		 *     are supported;
+		 *  - minimal transfer chunk is 4 bytes and consequently
+		 *     source and destination addresses must be 4-byte aligned
+		 *     and transfer size must be aligned on (4 * maxburst)
+		 *     boundary;
+		 *  - during the transfer RAM address is being incremented by
+		 *     the size of minimal transfer chunk;
+		 *  - peripheral port's address is constant during the transfer.
+		 */
+
+		cfg = (void *)arg;
+
+		if (cfg->src_addr_width != DMA_SLAVE_BUSWIDTH_4_BYTES ||
+		    cfg->dst_addr_width != DMA_SLAVE_BUSWIDTH_4_BYTES ||
+		    !IS_ALIGNED(cfg->src_addr, 4) ||
+		    !IS_ALIGNED(cfg->dst_addr, 4)) {
+			return -EINVAL;
+		}
+
+		spin_lock_irqsave(&mchan->lock, flags);
+
+		mchan->src_per_paddr = cfg->src_addr;
+		mchan->src_tcd_nunits = cfg->src_maxburst;
+		mchan->dst_per_paddr = cfg->dst_addr;
+		mchan->dst_tcd_nunits = cfg->dst_maxburst;
+
+		/* Apply defaults */
+		if (mchan->src_tcd_nunits == 0)
+			mchan->src_tcd_nunits = 1;
+		if (mchan->dst_tcd_nunits == 0)
+			mchan->dst_tcd_nunits = 1;
+
+		spin_unlock_irqrestore(&mchan->lock, flags);
+
+		return 0;
+
+	default:
+		/* Unknown command */
+		break;
+	}
+
+	return -ENXIO;
+}
+
 static int mpc_dma_probe(struct platform_device *op)
 {
 	struct device_node *dn = op->dev.of_node;
@@ -733,9 +964,12 @@
 	dma->device_issue_pending = mpc_dma_issue_pending;
 	dma->device_tx_status = mpc_dma_tx_status;
 	dma->device_prep_dma_memcpy = mpc_dma_prep_memcpy;
+	dma->device_prep_slave_sg = mpc_dma_prep_slave_sg;
+	dma->device_control = mpc_dma_device_control;

 	INIT_LIST_HEAD(&dma->channels);
 	dma_cap_set(DMA_MEMCPY, dma->cap_mask);
+	dma_cap_set(DMA_SLAVE, dma->cap_mask);

 	for (i = 0; i < dma->chancnt; i++) {
 		mchan = &mdma->channels[i];


drivers: eth_dw: changed stranded error message

Replaced CONFIG_NET_DEBUG_L2_ETHERNET with
CONFIG_ETHERNET_LOG_LEVEL >= LOG_LEVEL_DBG

Signed-off-by: Andrei Gansari <f1330555a90b7a22d81843f3c4366f58b50eae34@nxp.com>

--- drivers/ethernet/eth_dw.c
+++ drivers/ethernet/eth_dw.c
@@ -136,7 +136,7 @@

 static void eth_tx_data(struct eth_runtime *context, u8_t *data, u16_t len)
 {
-#ifdef CONFIG_NET_DEBUG_L2_ETHERNET
+#if CONFIG_ETHERNET_LOG_LEVEL >= LOG_LEVEL_DBG
 	/* Check whether an error occurred transmitting the previous frame. */
 	if (context->tx_desc.err_summary) {
 		LOG_ERR("Error transmitting frame: TDES0 = %08x,"


drm: Make sure the DRM offset matches the CPU

The pgoff option in mmap() is defined as an unsigned long
so the offset generated by DRM needs to fit into
BITS_PER_LONG for the CPU in question.

Signed-off-by: Jordan Crouse <fec53db8c4887e6e95defbb5052bc6438029c1e6@codeaurora.org>
Signed-off-by: Dave Airlie <f2295d84e358395675bc8031be58672073ae065e@redhat.com>

--- drivers/gpu/drm/drm_gem.c
+++ drivers/gpu/drm/drm_gem.c
@@ -68,8 +68,18 @@
  * We make up offsets for buffer objects so we can recognize them at
  * mmap time.
  */
+
+/* pgoff in mmap is an unsigned long, so we need to make sure that
+ * the faked up offset will fit
+ */
+
+#if BITS_PER_LONG == 64
 #define DRM_FILE_PAGE_OFFSET_START ((0xFFFFFFFFUL >> PAGE_SHIFT) + 1)
 #define DRM_FILE_PAGE_OFFSET_SIZE ((0xFFFFFFFFUL >> PAGE_SHIFT) * 16)
+#else
+#define DRM_FILE_PAGE_OFFSET_START ((0xFFFFFFFUL >> PAGE_SHIFT) + 1)
+#define DRM_FILE_PAGE_OFFSET_SIZE ((0xFFFFFFFUL >> PAGE_SHIFT) * 16)
+#endif

 /**
  * Initialize the GEM device fields


drm: simplify kcalloc() call to kzalloc().

Calls to kcalloc() for a single element can be simplified to calls to
kzalloc().

Signed-off-by: Robert P. J. Day <01aa5cd9a29907856ec6ddeebcb643ede4c45b8b@crashcourse.ca>
Cc: Dave Airlie <f2295d84e358395675bc8031be58672073ae065e@linux.ie>
Cc: Eric Anholt <96f164ad4d9b2b0dacf8ebee2bb1eeb3aa69adf1@anholt.net>
Signed-off-by: Andrew Morton <5c1e68b099950c134891f0b6e179498a8ebe9cf9@linux-foundation.org>
Signed-off-by: Dave Airlie <f2295d84e358395675bc8031be58672073ae065e@redhat.com>

--- drivers/gpu/drm/drm_gem.c
+++ drivers/gpu/drm/drm_gem.c
@@ -133,7 +133,7 @@

 	BUG_ON((size & (PAGE_SIZE - 1)) != 0);

-	obj = kcalloc(1, sizeof(*obj), GFP_KERNEL);
+	obj = kzalloc(sizeof(*obj), GFP_KERNEL);

 	obj->dev = dev;
 	obj->filp = shmem_file_setup("drm mm object", size, VM_NORESERVE);


drm/gem: replace misleading comment

drm/gem: replace misleading comment

shmem supports page-relocations during swapin since quite some time. It
was implemented in:

    commit bde05d1ccd512696b09db9dd2e5f33ad19152605
    Author: Hugh Dickins <hughd@google.com>
    Date:   Tue May 29 15:06:38 2012 -0700

        shmem: replace page if mapping excludes its zone

The gem-comment about wrongly placed DMA32 pages is no longer valid.
Replace it with a proper comment but keep the BUG_ON() to verify correct
shmem behavior.

Signed-off-by: David Herrmann <fb53b2ddb8d141e0cb39d7c67c2f81b6bc2eb0f7@gmail.com>
Reviewed-by: Daniel Vetter <c1b6782c4af8f0673da8923a0702a1832e5940f4@ffwll.ch>
Signed-off-by: Dave Airlie <f2295d84e358395675bc8031be58672073ae065e@redhat.com>


drm/pci: add missing variable initialization

Fixed build warning as below:

drivers/gpu/drm/drm_pci.c: In function 'drm_pcie_get_speed_cap_mask':
drivers/gpu/drm/drm_pci.c:496:9: warning: 'lnkcap' may be used uninitialized in this function [-Wuninitialized]
drivers/gpu/drm/drm_pci.c:497:10: warning: 'lnkcap2' may be used uninitialized in this function [-Wuninitialized]

Signed-off-by: Jingoo Han <fc379137a64feb86ce38ec5811a14280acc1ccfc@samsung.com>
Signed-off-by: Dave Airlie <f2295d84e358395675bc8031be58672073ae065e@redhat.com>

--- drivers/gpu/drm/drm_pci.c
+++ drivers/gpu/drm/drm_pci.c
@@ -470,7 +470,7 @@
 {
 	struct pci_dev *root;
 	int pos;
-	u32 lnkcap, lnkcap2;
+	u32 lnkcap = 0, lnkcap2 = 0;

 	*mask = 0;
 	if (!dev->pdev)


V4L/DVB (8942): mxb: coding style cleanups

Signed-off-by: Hans Verkuil <f625be9dbdcbbd12a043857af148e8fb895d9a1d@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <ad86ba2154032c9f55743a190faa2459a9d61d42@redhat.com>

--- drivers/media/video/mxb.c
+++ drivers/media/video/mxb.c
@@ -137,12 +137,12 @@

 	struct i2c_adapter	i2c_adapter;

-	struct i2c_client*	saa7111a;
-	struct i2c_client*	tda9840;
-	struct i2c_client*	tea6415c;
-	struct i2c_client*	tuner;
-	struct i2c_client*	tea6420_1;
-	struct i2c_client*	tea6420_2;
+	struct i2c_client	*saa7111a;
+	struct i2c_client	*tda9840;
+	struct i2c_client	*tea6415c;
+	struct i2c_client	*tuner;
+	struct i2c_client	*tea6420_1;
+	struct i2c_client	*tea6420_2;

 	int	cur_mode;	/* current audio mode (mono, stereo, ...) */
 	int	cur_input;	/* current input */
@@ -154,7 +154,7 @@

 static int mxb_check_clients(struct device *dev, void *data)
 {
-	struct mxb* mxb = data;
+	struct mxb *mxb = data;
 	struct i2c_client *client = i2c_verify_client(dev);

 	if (!client)
@@ -298,7 +298,7 @@
 	{ 9, { 0x1d, 0xed, 0xd0, 0x68, 0x29, 0xb4, 0xe1, 0x00, 0xb8 } },
 	{ 9, { 0x3d, 0xed, 0xd0, 0x68, 0x29, 0xb4, 0xe1, 0x00, 0xb8 } },
 	{ 3, { 0x80, 0xb3, 0x0a } },
-	{-1, { 0} }
+	{-1, { 0 } }
 };

 /* bring hardware to a sane state. this has to be done, just in case someone
@@ -314,10 +314,9 @@
 	struct v4l2_routing route;

 	int i = 0, err = 0;
-	struct	tea6415c_multiplex vm;
+	struct tea6415c_multiplex vm;

 	/* select video mode in saa7111a */
-	/* fixme: currently pointless: gets overwritten by configuration below */
 	mxb->saa7111a->driver->command(mxb->saa7111a, VIDIOC_S_STD, &std);

 	/* select tuner-output on saa7111a */
@@ -342,20 +341,20 @@
 	mxb->tuner->driver->command(mxb->tuner, VIDIOC_S_STD, &std);

 	/* mute audio on tea6420s */
-	mxb->tea6420_1->driver->command(mxb->tea6420_1,TEA6420_SWITCH, &TEA6420_line[6][0]);
-	mxb->tea6420_2->driver->command(mxb->tea6420_2,TEA6420_SWITCH, &TEA6420_line[6][1]);
-	mxb->tea6420_1->driver->command(mxb->tea6420_1,TEA6420_SWITCH, &TEA6420_cd[6][0]);
-	mxb->tea6420_2->driver->command(mxb->tea6420_2,TEA6420_SWITCH, &TEA6420_cd[6][1]);
+	mxb->tea6420_1->driver->command(mxb->tea6420_1, TEA6420_SWITCH, &TEA6420_line[6][0]);
+	mxb->tea6420_2->driver->command(mxb->tea6420_2, TEA6420_SWITCH, &TEA6420_line[6][1]);
+	mxb->tea6420_1->driver->command(mxb->tea6420_1, TEA6420_SWITCH, &TEA6420_cd[6][0]);
+	mxb->tea6420_2->driver->command(mxb->tea6420_2, TEA6420_SWITCH, &TEA6420_cd[6][1]);

 	/* switch to tuner-channel on tea6415c*/
 	vm.out = 17;
 	vm.in  = 3;
-	mxb->tea6415c->driver->command(mxb->tea6415c,TEA6415C_SWITCH, &vm);
+	mxb->tea6415c->driver->command(mxb->tea6415c, TEA6415C_SWITCH, &vm);

 	/* select tuner-output on multicable on tea6415c*/
 	vm.in  = 3;
 	vm.out = 13;
-	mxb->tea6415c->driver->command(mxb->tea6415c,TEA6415C_SWITCH, &vm);
+	mxb->tea6415c->driver->command(mxb->tea6415c, TEA6415C_SWITCH, &vm);

 	/* the rest for mxb */
 	mxb->cur_input = 0;
@@ -372,21 +371,22 @@
 	msg.len = mxb_saa7740_init[0].length;
 	msg.buf = &mxb_saa7740_init[0].data[0];

-	if( 1 == (err = i2c_transfer(&mxb->i2c_adapter, &msg, 1))) {
+	err = i2c_transfer(&mxb->i2c_adapter, &msg, 1);
+	if (err == 1) {
 		/* the sound arena module is a pos, that's probably the reason
 		   philips refuses to hand out a datasheet for the saa7740...
 		   it seems to screw up the i2c bus, so we disable fast irq
 		   based i2c transactions here and rely on the slow and safe
 		   polling method ... */
 		extension.flags &= ~SAA7146_USE_I2C_IRQ;
-		for(i = 1;;i++) {
-			if( -1 == mxb_saa7740_init[i].length ) {
+		for (i = 1; ; i++) {
+			if (-1 == mxb_saa7740_init[i].length)
 				break;
-			}

 			msg.len = mxb_saa7740_init[i].length;
 			msg.buf = &mxb_saa7740_init[i].data[0];
-			if( 1 != (err = i2c_transfer(&mxb->i2c_adapter, &msg, 1))) {
+			err = i2c_transfer(&mxb->i2c_adapter, &msg, 1);
+			if (err != 1) {
 				DEB_D(("failed to initialize 'sound arena module'.\n"));
 				goto err;
 			}
@@ -400,7 +400,8 @@
 	/* ext->saa has been filled by the core driver */

 	/* some stuff is done via variables */
-	saa7146_set_hps_source_and_sync(dev, input_port_selection[mxb->cur_input].hps_source, input_port_selection[mxb->cur_input].hps_sync);
+	saa7146_set_hps_source_and_sync(dev, input_port_selection[mxb->cur_input].hps_source,
+			input_port_selection[mxb->cur_input].hps_sync);

 	/* some stuff is done via direct write to the registers */

@@ -425,11 +426,11 @@
 static struct saa7146_ext_vv vv_data;

 /* this function only gets called when the probing was successful */
-static int mxb_attach(struct saa7146_dev* dev, struct saa7146_pci_extension_data *info)
-{
-	struct mxb* mxb = (struct mxb*)dev->ext_priv;
-
-	DEB_EE(("dev:%p\n",dev));
+static int mxb_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_data *info)
+{
+	struct mxb *mxb = (struct mxb *)dev->ext_priv;
+
+	DEB_EE(("dev:%p\n", dev));

 	/* checking for i2c-devices can be omitted here, because we
 	   already did this in "mxb_vl42_probe" */
@@ -461,11 +462,11 @@
 	return 0;
 }

-static int mxb_detach(struct saa7146_dev* dev)
-{
-	struct mxb* mxb = (struct mxb*)dev->ext_priv;
-
-	DEB_EE(("dev:%p\n",dev));
+static int mxb_detach(struct saa7146_dev *dev)
+{
+	struct mxb *mxb = (struct mxb *)dev->ext_priv;
+
+	DEB_EE(("dev:%p\n", dev));

 	i2c_release_client(mxb->tea6420_1);
 	i2c_release_client(mxb->tea6420_2);
@@ -475,9 +476,8 @@
 	i2c_release_client(mxb->tuner);

 	saa7146_unregister_device(&mxb->video_dev,dev);
-	if( 0 != MXB_BOARD_CAN_DO_VBI(dev)) {
-		saa7146_unregister_device(&mxb->vbi_dev,dev);
-	}
+	if (MXB_BOARD_CAN_DO_VBI(dev))
+		saa7146_unregister_device(&mxb->vbi_dev, dev);
 	saa7146_vv_release(dev);

 	mxb_num--;
@@ -491,7 +491,7 @@
 static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
 {
 	struct saa7146_dev *dev = fh->dev;
-	struct mxb* mxb = (struct mxb*)dev->ext_priv;
+	struct mxb *mxb = (struct mxb *)dev->ext_priv;
 	struct saa7146_vv *vv = dev->vv_data;

 	switch(cmd) {
@@ -500,11 +500,9 @@
 		struct v4l2_input *i = arg;

 		DEB_EE(("VIDIOC_ENUMINPUT %d.\n",i->index));
-		if( i->index < 0 || i->index >= MXB_INPUTS) {
-			return -EINVAL;
-		}
+		if (i->index < 0 || i->index >= MXB_INPUTS)
+			return -EINVAL;
 		memcpy(i, &mxb_inputs[i->index], sizeof(struct v4l2_input));
-
 		return 0;
 	}
 	/* the saa7146 provides some controls (brightness, contrast, saturation)
@@ -518,7 +516,7 @@
 		for (i = MAXCONTROLS - 1; i >= 0; i--) {
 			if (mxb_controls[i].id == qc->id) {
 				*qc = mxb_controls[i];
-				DEB_D(("VIDIOC_QUERYCTRL %d.\n",qc->id));
+				DEB_D(("VIDIOC_QUERYCTRL %d.\n", qc->id));
 				return 0;
 			}
 		}
@@ -530,56 +528,51 @@
 		int i;

 		for (i = MAXCONTROLS - 1; i >= 0; i--) {
-			if (mxb_controls[i].id == vc->id) {
+			if (mxb_controls[i].id == vc->id)
 				break;
+		}
+
+		if (i < 0)
+			return -EAGAIN;
+
+		if (vc->id == V4L2_CID_AUDIO_MUTE) {
+			vc->value = mxb->cur_mute;
+			DEB_D(("VIDIOC_G_CTRL V4L2_CID_AUDIO_MUTE:%d.\n", vc->value));
+			return 0;
+		}
+
+		DEB_EE(("VIDIOC_G_CTRL V4L2_CID_AUDIO_MUTE:%d.\n", vc->value));
+		return 0;
+	}
+
+	case VIDIOC_S_CTRL:
+	{
+		struct v4l2_control *vc = arg;
+		int i = 0;
+
+		for (i = MAXCONTROLS - 1; i >= 0; i--) {
+			if (mxb_controls[i].id == vc->id)
+				break;
+		}
+
+		if (i < 0)
+			return -EAGAIN;
+
+		if (vc->id == V4L2_CID_AUDIO_MUTE) {
+			mxb->cur_mute = vc->value;
+			if (!vc->value) {
+				/* switch the audio-source */
+				mxb->tea6420_1->driver->command(mxb->tea6420_1, TEA6420_SWITCH,
+						&TEA6420_line[video_audio_connect[mxb->cur_input]][0]);
+				mxb->tea6420_2->driver->command(mxb->tea6420_2, TEA6420_SWITCH,
+						&TEA6420_line[video_audio_connect[mxb->cur_input]][1]);
+			} else {
+				mxb->tea6420_1->driver->command(mxb->tea6420_1, TEA6420_SWITCH,
+						&TEA6420_line[6][0]);
+				mxb->tea6420_2->driver->command(mxb->tea6420_2, TEA6420_SWITCH,
+						&TEA6420_line[6][1]);
 			}
-		}
-
-		if( i < 0 ) {
-			return -EAGAIN;
-		}
-
-		switch (vc->id ) {
-			case V4L2_CID_AUDIO_MUTE: {
-				vc->value = mxb->cur_mute;
-				DEB_D(("VIDIOC_G_CTRL V4L2_CID_AUDIO_MUTE:%d.\n",vc->value));
-				return 0;
-			}
-		}
-
-		DEB_EE(("VIDIOC_G_CTRL V4L2_CID_AUDIO_MUTE:%d.\n",vc->value));
-		return 0;
-	}
-
-	case VIDIOC_S_CTRL:
-	{
-		struct	v4l2_control	*vc = arg;
-		int i = 0;
-
-		for (i = MAXCONTROLS - 1; i >= 0; i--) {
-			if (mxb_controls[i].id == vc->id) {
-				break;
-			}
-		}
-
-		if( i < 0 ) {
-			return -EAGAIN;
-		}
-
-		switch (vc->id ) {
-			case V4L2_CID_AUDIO_MUTE: {
-				mxb->cur_mute = vc->value;
-				if( 0 == vc->value ) {
-					/* switch the audio-source */
-					mxb->tea6420_1->driver->command(mxb->tea6420_1,TEA6420_SWITCH, &TEA6420_line[video_audio_connect[mxb->cur_input]][0]);
-					mxb->tea6420_2->driver->command(mxb->tea6420_2,TEA6420_SWITCH, &TEA6420_line[video_audio_connect[mxb->cur_input]][1]);
-				} else {
-					mxb->tea6420_1->driver->command(mxb->tea6420_1,TEA6420_SWITCH, &TEA6420_line[6][0]);
-					mxb->tea6420_2->driver->command(mxb->tea6420_2,TEA6420_SWITCH, &TEA6420_line[6][1]);
-				}
-				DEB_EE(("VIDIOC_S_CTRL, V4L2_CID_AUDIO_MUTE: %d.\n",vc->value));
-				break;
-			}
+			DEB_EE(("VIDIOC_S_CTRL, V4L2_CID_AUDIO_MUTE: %d.\n", vc->value));
 		}
 		return 0;
 	}
@@ -588,7 +581,7 @@
 		int *input = (int *)arg;
 		*input = mxb->cur_input;

-		DEB_EE(("VIDIOC_G_INPUT %d.\n",*input));
+		DEB_EE(("VIDIOC_G_INPUT %d.\n", *input));
 		return 0;
 	}
 	case VIDIOC_S_INPUT:
@@ -598,73 +591,60 @@
 		struct v4l2_routing route;
 		int i = 0;

-		DEB_EE(("VIDIOC_S_INPUT %d.\n",input));
-
-		if (input < 0 || input >= MXB_INPUTS) {
-			return -EINVAL;
-		}
+		DEB_EE(("VIDIOC_S_INPUT %d.\n", input));
+
+		if (input < 0 || input >= MXB_INPUTS)
+			return -EINVAL;

 		mxb->cur_input = input;

-		saa7146_set_hps_source_and_sync(dev, input_port_selection[input].hps_source, input_port_selection[input].hps_sync);
+		saa7146_set_hps_source_and_sync(dev, input_port_selection[input].hps_source,
+				input_port_selection[input].hps_sync);

 		/* prepare switching of tea6415c and saa7111a;
 		   have a look at the 'background'-file for further informations  */
-		switch( input ) {
-
-			case TUNER:
-			{
-				i = SAA7115_COMPOSITE0;
-				vm.in  = 3;
-				vm.out = 17;
-
-			if ( 0 != mxb->tea6415c->driver->command(mxb->tea6415c,TEA6415C_SWITCH, &vm)) {
-					printk("VIDIOC_S_INPUT: could not address tea6415c #1\n");
-					return -EFAULT;
-				}
-				/* connect tuner-output always to multicable */
-				vm.in  = 3;
-				vm.out = 13;
-				break;
+		switch (input) {
+		case TUNER:
+			i = SAA7115_COMPOSITE0;
+			vm.in  = 3;
+			vm.out = 17;
+
+			if (mxb->tea6415c->driver->command(mxb->tea6415c, TEA6415C_SWITCH, &vm)) {
+				printk(KERN_ERR "VIDIOC_S_INPUT: could not address tea6415c #1\n");
+				return -EFAULT;
 			}
-			case AUX3_YC:
-			{
-				/* nothing to be done here. aux3_yc is
-				   directly connected to the saa711a */
-				i = SAA7115_SVIDEO1;
-				break;
+			/* connect tuner-output always to multicable */
+			vm.in  = 3;
+			vm.out = 13;
+			break;
+		case AUX3_YC:
+			/* nothing to be done here. aux3_yc is
+			   directly connected to the saa711a */
+			i = SAA7115_SVIDEO1;
+			break;
+		case AUX3:
+			/* nothing to be done here. aux3 is
+			   directly connected to the saa711a */
+			i = SAA7115_COMPOSITE1;
+			break;
+		case AUX1:
+			i = SAA7115_COMPOSITE0;
+			vm.in  = 1;
+			vm.out = 17;
+			break;
+		}
+
+		/* switch video in tea6415c only if necessary */
+		switch (input) {
+		case TUNER:
+		case AUX1:
+			if (mxb->tea6415c->driver->command(mxb->tea6415c, TEA6415C_SWITCH, &vm)) {
+				printk(KERN_ERR "VIDIOC_S_INPUT: could not address tea6415c #3\n");
+				return -EFAULT;
 			}
-			case AUX3:
-			{
-				/* nothing to be done here. aux3 is
-				   directly connected to the saa711a */
-				i = SAA7115_COMPOSITE1;
-				break;
-			}
-			case AUX1:
-			{
-				i = SAA7115_COMPOSITE0;
-				vm.in  = 1;
-				vm.out = 17;
-				break;
-			}
-		}
-
-		/* switch video in tea6415c only if necessary */
-		switch( input ) {
-			case TUNER:
-			case AUX1:
-			{
-				if ( 0 != mxb->tea6415c->driver->command(mxb->tea6415c,TEA6415C_SWITCH, &vm)) {
-					printk("VIDIOC_S_INPUT: could not address tea6415c #3\n");
-					return -EFAULT;
-				}
-				break;
-			}
-			default:
-			{
-				break;
-			}
+			break;
+		default:
+			break;
 		}

 		/* switch video in saa7111a */
@@ -675,8 +655,10 @@

 		/* switch the audio-source only if necessary */
 		if( 0 == mxb->cur_mute ) {
-			mxb->tea6420_1->driver->command(mxb->tea6420_1,TEA6420_SWITCH, &TEA6420_line[video_audio_connect[input]][0]);
-			mxb->tea6420_2->driver->command(mxb->tea6420_2,TEA6420_SWITCH, &TEA6420_line[video_audio_connect[input]][1]);
+			mxb->tea6420_1->driver->command(mxb->tea6420_1, TEA6420_SWITCH,
+					&TEA6420_line[video_audio_connect[input]][0]);
+			mxb->tea6420_2->driver->command(mxb->tea6420_2, TEA6420_SWITCH,
+				       &TEA6420_line[video_audio_connect[input]][1]);
 		}

 		return 0;
@@ -719,8 +701,9 @@
 	{
 		struct v4l2_frequency *f = arg;

-		if(0 != mxb->cur_input) {
-			DEB_D(("VIDIOC_G_FREQ: channel %d does not have a tuner!\n",mxb->cur_input));
+		if (mxb->cur_input) {
+			DEB_D(("VIDIOC_G_FREQ: channel %d does not have a tuner!\n",
+						mxb->cur_input));
 			return -EINVAL;
 		}

@@ -733,7 +716,7 @@
 	{
 		struct v4l2_frequency *f = arg;

-		if (0 != f->tuner)
+		if (f->tuner)
 			return -EINVAL;

 		if (V4L2_TUNER_ANALOG_TV != f->type)
@@ -761,7 +744,7 @@
 	{
 		int i = *(int*)arg;

-		if( i < 0 || i >= MXB_AUDIOS ) {
+		if (i < 0 || i >= MXB_AUDIOS) {
 			DEB_D(("illegal argument to MXB_S_AUDIO_CD: i:%d.\n",i));
 			return -EINVAL;
 		}
@@ -777,7 +760,7 @@
 	{
 		int i = *(int*)arg;

-		if( i < 0 || i >= MXB_AUDIOS ) {
+		if (i < 0 || i >= MXB_AUDIOS) {
 			DEB_D(("illegal argument to MXB_S_AUDIO_LINE: i:%d.\n",i));
 			return -EINVAL;
 		}
@@ -792,12 +775,12 @@
 	{
 		struct v4l2_audio *a = arg;

-		if( a->index < 0 || a->index > MXB_INPUTS ) {
-			DEB_D(("VIDIOC_G_AUDIO %d out of range.\n",a->index));
-			return -EINVAL;
-		}
-
-		DEB_EE(("VIDIOC_G_AUDIO %d.\n",a->index));
+		if (a->index < 0 || a->index > MXB_INPUTS) {
+			DEB_D(("VIDIOC_G_AUDIO %d out of range.\n", a->index));
+			return -EINVAL;
+		}
+
+		DEB_EE(("VIDIOC_G_AUDIO %d.\n", a->index));
 		memcpy(a, &mxb_audios[video_audio_connect[mxb->cur_input]], sizeof(struct v4l2_audio));

 		return 0;
@@ -805,13 +788,16 @@
 	case VIDIOC_S_AUDIO:
 	{
 		struct v4l2_audio *a = arg;
-		DEB_D(("VIDIOC_S_AUDIO %d.\n",a->index));
-		return 0;
-	}
+
+		DEB_D(("VIDIOC_S_AUDIO %d.\n", a->index));
+		return 0;
+	}
+#ifdef CONFIG_VIDEO_ADV_DEBUG
 	case VIDIOC_DBG_S_REGISTER:
 	case VIDIOC_DBG_G_REGISTER:
 		i2c_clients_command(&mxb->i2c_adapter, cmd, arg);
-		break;
+		return 0;
+#endif
 	default:
 /*
 		DEB2(printk("does not handle this ioctl.\n"));
@@ -919,7 +905,7 @@

 static int __init mxb_init_module(void)
 {
-	if( 0 != saa7146_register_extension(&extension)) {
+	if (saa7146_register_extension(&extension)) {
 		DEB_S(("failed to register extension.\n"));
 		return -ENODEV;
 	}


mfd: arizona: Try to use interrupt flags from interrupt controller

If no irq_flags are passed in platform data then query the interrupt
controller for the trigger type and try to use that. This provides
default operation with a wider range of hardware and will be needed
for device tree support where the interrupt flags are configured on
the interrupt controller.

Signed-off-by: Mark Brown <b51b9a92386687a9ac927cebfa0f978adeb8cea5@opensource.wolfsonmicro.com>
Signed-off-by: Samuel Ortiz <0ba86cb3f08bbb861958e54bd3438887adb4263c@linux.intel.com>

--- drivers/mfd/arizona-irq.c
+++ drivers/mfd/arizona-irq.c
@@ -189,6 +189,7 @@
 	int ret, i;
 	const struct regmap_irq_chip *aod, *irq;
 	bool ctrlif_error = true;
+	struct irq_data *irq_data;

 	switch (arizona->type) {
 #ifdef CONFIG_MFD_WM5102
@@ -215,8 +216,30 @@
 	/* Disable all wake sources by default */
 	regmap_write(arizona->regmap, ARIZONA_WAKE_CONTROL, 0);

-	if (!arizona->pdata.irq_flags)
-		arizona->pdata.irq_flags = IRQF_TRIGGER_LOW;
+	/* Read the flags from the interrupt controller if not specified */
+	if (!arizona->pdata.irq_flags) {
+		irq_data = irq_get_irq_data(arizona->irq);
+		if (!irq_data) {
+			dev_err(arizona->dev, "Invalid IRQ: %d\n",
+				arizona->irq);
+			return -EINVAL;
+		}
+
+		arizona->pdata.irq_flags = irqd_get_trigger_type(irq_data);
+		switch (arizona->pdata.irq_flags) {
+		case IRQF_TRIGGER_LOW:
+		case IRQF_TRIGGER_HIGH:
+		case IRQF_TRIGGER_RISING:
+		case IRQF_TRIGGER_FALLING:
+			break;
+
+		case IRQ_TYPE_NONE:
+		default:
+			/* Device default */
+			arizona->pdata.irq_flags = IRQF_TRIGGER_LOW;
+			break;
+		}
+	}

 	if (arizona->pdata.irq_flags & (IRQF_TRIGGER_HIGH |
 					IRQF_TRIGGER_RISING)) {


mfd: Disable twl6030 IRQ during suspend

mfd: Disable twl6030 IRQ during suspend

Module IRQs may still be disabled by DPM at the time the TWL6030
ISR runs, causing handle_simple_irq() to silently do nothing.
This may result in missing TWL RTC alarm wakeups, for example,
since the RTC child module ISR is not called to ack the IRQ.

Disable the TWL6030 IRQ during suspend, enable it at DPM resume
time, at which time the child module IRQs will be re-enabled.

Signed-off-by: Todd Poynor <57cb0497077c01018e8c022963d2feeac2e977b4@google.com>
Acked-by: Santosh Shilimkar <5b4d8dc9ea337fff5fd1729321eda9873ade0b09@ti.com>
Signed-off-by: Samuel Ortiz <0ba86cb3f08bbb861958e54bd3438887adb4263c@linux.intel.com>

--- drivers/mfd/twl6030-irq.c
+++ drivers/mfd/twl6030-irq.c
@@ -109,7 +109,13 @@
 			twl_irq_wake_enabled = false;
 		}

+		disable_irq(twl_irq);
 		break;
+
+	case PM_POST_SUSPEND:
+		enable_irq(twl_irq);
+		break;
+
 	default:
 		break;
 	}


mmc: dw_mmc: Indicate that regulators may be absent

Use regulator_get_optional() to tell the core that requests for regulators
can fail in a real system.

Signed-off-by: Mark Brown <b51b9a92386687a9ac927cebfa0f978adeb8cea5@linaro.org>
Acked-by: Chris Ball <6ca7faee6ca9a094b1ee341f11b840a5608a8746@laptop.org>
Acked-by: Seungwon Jeon <a133bc924ee401eac4c4f97927180f14b8a9baec@samsung.com>
Acked-by: Jaehoon Chung <6d67df43a1b10a02c7c04e8346f9d9ca207335e5@samsung.com>


mmc: s3cmci: fix s3c2410_dma_config() arguments.

The s3cmci driver is calling s3c2410_dma_config with incorrect data for
the DCON register.  The S3C2410_DCON_HWTRIG is implicit in the channel
configuration and the device selection of S3C2410_DCON_CH0_SDI is
incorrect as the DMA system may not select channel 0.

Signed-off-by: Ben Dooks <73675debcd8a436be48ec22211dcf44fe0df0a64@simtec.co.uk>
Acked-by: Pierre Ossman <8b64f2aeec7ea42cd6838e5b2901f7aa61dfa5d4@drzeus.cx>
Signed-off-by: Andrew Morton <5c1e68b099950c134891f0b6e179498a8ebe9cf9@linux-foundation.org>
Signed-off-by: Linus Torvalds <69652caca27c8b940640ad396ab71f93cacec34f@linux-foundation.org>

--- drivers/mmc/host/s3cmci.c
+++ drivers/mmc/host/s3cmci.c
@@ -793,8 +793,7 @@
 			      host->mem->start + host->sdidata);

 	if (!setup_ok) {
-		s3c2410_dma_config(host->dma, 4,
-			(S3C2410_DCON_HWTRIG | S3C2410_DCON_CH0_SDI));
+		s3c2410_dma_config(host->dma, 4, 0);
 		s3c2410_dma_set_buffdone_fn(host->dma,
 					    s3cmci_dma_done_callback);
 		s3c2410_dma_setflags(host->dma, S3C2410_DMAF_AUTOSTART);


MySQL sequencing dumbed down, in the middle of GC hooks

--- drivers/mysql/dbd_mysql.c
+++ drivers/mysql/dbd_mysql.c
@@ -256,27 +256,11 @@
 }

 unsigned long long dbd_get_seq_last(dbi_conn_t *conn, const char *sequence) {
-	unsigned long long seq_next = dbd_get_seq_next(conn, sequence);
-	return (seq_next > 0) ? (seq_next - 1) : 0;
+	return mysql_insert_id((MYSQL *)conn->connection);
 }

 unsigned long long dbd_get_seq_next(dbi_conn_t *conn, const char *sequence) {
-	dbi_result_t *result;
-	char *sql_cmd;
-	unsigned long long seq_next = 0;
-
-	asprintf(&sql_cmd, "SHOW TABLE STATUS LIKE '%s'", sequence);
-	result = dbd_query(conn, sql_cmd);
-	free(sql_cmd);
-
-	/* grab #10 "Auto_increment" from result */
-	if (result && dbi_result_next_row((dbi_result)result)) {
-		seq_next = dbi_result_get_ulonglong((dbi_result)result, "Auto_increment");
-	}
-
-	dbi_result_free((dbi_result)result);
-
-	return seq_next;
+	return 0;
 }

 /* CORE MYSQL DATA FETCHING STUFF */


phy/marvell: fix 88e1121 support

phy/marvell: fix 88e1121 support

Commit c477d0447db08068a497e7beb892b2b2a7bff64b added support for RGMII
rx/tx delays except that it ends up clearing rx/tx delays bit for modes
differents that RGMII*ID. Due to this, ethernet is not working anymore
on my guruplug server +. This patch is fixing that.

Signed-off-by: Arnaud Patard <792745173c1ee81f4d7d786155d4c148b6e57204@rtp-net.org>
Signed-off-by: David S. Miller <fe08d3c717adf2ae63592e4c9aec6e3e404d8e3e@davemloft.net>

--- drivers/net/phy/marvell.c
+++ drivers/net/phy/marvell.c
@@ -196,20 +196,27 @@
 			MII_88E1121_PHY_MSCR_PAGE);
 	if (err < 0)
 		return err;
-	mscr = phy_read(phydev, MII_88E1121_PHY_MSCR_REG) &
-		MII_88E1121_PHY_MSCR_DELAY_MASK;
-
-	if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
-		mscr |= (MII_88E1121_PHY_MSCR_RX_DELAY |
-			 MII_88E1121_PHY_MSCR_TX_DELAY);
-	else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID)
-		mscr |= MII_88E1121_PHY_MSCR_RX_DELAY;
-	else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)
-		mscr |= MII_88E1121_PHY_MSCR_TX_DELAY;
-
-	err = phy_write(phydev, MII_88E1121_PHY_MSCR_REG, mscr);
-	if (err < 0)
-		return err;
+
+	if ((phydev->interface == PHY_INTERFACE_MODE_RGMII) ||
+	    (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) ||
+	    (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) ||
+	    (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)) {
+
+		mscr = phy_read(phydev, MII_88E1121_PHY_MSCR_REG) &
+			MII_88E1121_PHY_MSCR_DELAY_MASK;
+
+		if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
+			mscr |= (MII_88E1121_PHY_MSCR_RX_DELAY |
+				 MII_88E1121_PHY_MSCR_TX_DELAY);
+		else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID)
+			mscr |= MII_88E1121_PHY_MSCR_RX_DELAY;
+		else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)
+			mscr |= MII_88E1121_PHY_MSCR_TX_DELAY;
+
+		err = phy_write(phydev, MII_88E1121_PHY_MSCR_REG, mscr);
+		if (err < 0)
+			return err;
+	}

 	phy_write(phydev, MII_88E1121_PHY_PAGE, oldpage);


rtl8150: rtl8150_disconnect(...) does not need tasklet_disable(...)

Executing cmd 'rmmod rtl8150' does not return(if your device connects
to host), the root cause is tasklet_disable() causes tasklet_kill()
block, remove it from rtl8150_disconnect().

Signed-off-by: Huajun Li <25cd09582975b488bc2e330054237cbf478bce0a@gmail.com>
Signed-off-by: David S. Miller <fe08d3c717adf2ae63592e4c9aec6e3e404d8e3e@davemloft.net>

--- drivers/net/usb/rtl8150.c
+++ drivers/net/usb/rtl8150.c
@@ -977,7 +977,6 @@
 	usb_set_intfdata(intf, NULL);
 	if (dev) {
 		set_bit(RTL8150_UNPLUG, &dev->flags);
-		tasklet_disable(&dev->tl);
 		tasklet_kill(&dev->tl);
 		unregister_netdev(dev->netdev);
 		unlink_all_urbs(dev);


Chaging list to vector on collect() function and adding todo comment for optimizing it further.

--- include/IECore/bindings/WrapperGarbageCollector.h
+++ include/IECore/bindings/WrapperGarbageCollector.h
@@ -38,7 +38,7 @@
 #include <boost/python.hpp>
 #include <iostream>
 #include <cassert>
-#include <list>
+#include <vector>

 #include "IECore/RefCounted.h"
 #include "IECore/WrapperGarbageCollectorBase.h"
@@ -46,6 +46,7 @@
 namespace IECore
 {

+//\todo Optimize the collect() function. The function is taking too much tests on reference counting when many objects are allocated.
 class WrapperGarbageCollector : public WrapperGarbageCollectorBase
 {

@@ -70,7 +71,7 @@

 		static void collect()
 		{
-			std::list<PyObject*> toCollect;
+			std::vector<PyObject*> toCollect;

 			do
 			{
@@ -86,7 +87,7 @@
 					}
 				}

-				for (std::list<PyObject*>::const_iterator jt = toCollect.begin(); jt != toCollect.end(); ++jt)
+				for (std::vector<PyObject*>::const_iterator jt = toCollect.begin(); jt != toCollect.end(); ++jt)
 				{
 					Py_DECREF( *jt );
 				}


Remove commented code

Remove commented code

--- include/aerial_autonomy/logic_states/base_state.h
+++ include/aerial_autonomy/logic_states/base_state.h
@@ -22,13 +22,6 @@

 template <class RobotSystemT, class LogicStateMachineT, class ActionFctr>
 class BaseState : public msmf::state<> {
-  // Perform static asserts to ensure the ActionFctr is valid:
-  // TODO Make this internal action functor once all the transitions are done
-  // static_assert(std::is_base_of<EventAgnosticActionFunctor<RobotSystemT,
-  //                                                         LogicStateMachineT>,
-  //                              ActionFctr>::value,
-  //              "ActionFctr not a subclass of InternalActionFctr");
-
 public:
   /**
    * @brief The internal_transition_table to call run function in every state


intel-iommu: Add iommu_should_identity_map() function

We do this twice, and it's about to get more complicated. This makes the
code slightly clearer about what it's doing, too.

Signed-off-by: David Woodhouse <b460d66aaf00c296a3db1c1d9eeafc081d5f7d70@intel.com>

--- drivers/pci/intel-iommu.c
+++ drivers/pci/intel-iommu.c
@@ -2442,6 +2442,11 @@
 	return pdev->dev.archdata.iommu == DUMMY_DEVICE_DOMAIN_INFO;
 }

+static int iommu_should_identity_map(struct pci_dev *pdev)
+{
+	return pdev->dma_mask > DMA_BIT_MASK(32);
+}
+
 /* Check if the pdev needs to go through non-identity map and unmap process.*/
 static int iommu_no_mapping(struct pci_dev *pdev)
 {
@@ -2455,7 +2460,7 @@

 	found = identity_mapping(pdev);
 	if (found) {
-		if (pdev->dma_mask > DMA_BIT_MASK(32))
+		if (iommu_should_identity_map(pdev))
 			return 1;
 		else {
 			/*
@@ -2472,7 +2477,7 @@
 		 * In case of a detached 64 bit DMA device from vm, the device
 		 * is put into si_domain for identity mapping.
 		 */
-		if (pdev->dma_mask > DMA_BIT_MASK(32)) {
+		if (iommu_should_identity_map(pdev)) {
 			int ret;
 			ret = domain_add_dev_info(si_domain, pdev);
 			if (ret)


PCH fix

PCH fix

--- include/inviwo/core/datastructures/datasequence.h
+++ include/inviwo/core/datastructures/datasequence.h
@@ -31,6 +31,7 @@
 #define IVW_DATASEQUENCE_H

 #include <inviwo/core/common/inviwocoredefine.h>
+#include <inviwo/core/ports/port.h>

 namespace inviwo {


intel-iommu: Force-disable IOMMU for iGFX on broken Cantiga revisions.

Certain revisions of this chipset appear to be broken. There is a shadow
GTT which mirrors the real GTT but contains pre-translated physical
addresses, for performance reasons. When a GTT update happens, the
translations are done once and the resulting physical addresses written
back to the shadow GTT.

Except sometimes, the physical address is actually written back to the
_real_ GTT, not the shadow GTT. Thus we start to see faults when that
physical address is fed through translation again.

Signed-off-by: David Woodhouse <b460d66aaf00c296a3db1c1d9eeafc081d5f7d70@intel.com>

--- drivers/pci/intel-iommu.c
+++ drivers/pci/intel-iommu.c
@@ -340,7 +340,7 @@
 int dmar_disabled = 1;
 #endif /*CONFIG_DMAR_DEFAULT_ON*/

-static int __initdata dmar_map_gfx = 1;
+static int dmar_map_gfx = 1;
 static int dmar_forcedac;
 static int intel_iommu_strict;

@@ -3721,6 +3721,12 @@
 	 */
 	printk(KERN_INFO "DMAR: Forcing write-buffer flush capability\n");
 	rwbf_quirk = 1;
+
+	/* https://bugzilla.redhat.com/show_bug.cgi?id=538163 */
+	if (dev->revision == 0x07) {
+		printk(KERN_INFO "DMAR: Disabling IOMMU for graphics on this chipset\n");
+		dmar_map_gfx = 0;
+	}
 }

 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x2a40, quirk_iommu_rwbf);


Small memory leak

Small memory leak

--- drivers/pgsql/dbd_pgsql.c
+++ drivers/pgsql/dbd_pgsql.c
@@ -21,7 +21,7 @@
  * Copyright (C) 2001-2002, David A. Parker <david@neongoat.com>.
  * http://libdbi.sourceforge.net
  *
- * $Id: dbd_pgsql.c,v 1.34 2003/06/17 06:35:42 dap24 Exp $
+ * $Id: dbd_pgsql.c,v 1.35 2003/09/02 20:55:03 bhazer Exp $
  */

 #ifdef HAVE_CONFIG_H
@@ -115,6 +115,8 @@
 		password ? password : "",
 		options ? options : "",
 		tty ? tty : "");
+
+	if (conninfo_kludge) free(conninfo_kludge);

 	pgconn = PQconnectdb(conninfo);
 	if (conninfo) free(conninfo);


cms's query/queryf patch. WARNING: this breaks old code!

--- drivers/pgsql/dbd_pgsql.c
+++ drivers/pgsql/dbd_pgsql.c
@@ -21,7 +21,7 @@
  * Copyright (C) 2001-2002, David A. Parker <david@neongoat.com>.
  * http://libdbi.sourceforge.net
  *
- * $Id: dbd_pgsql.c,v 1.22 2002/10/16 05:58:25 dap Exp $
+ * $Id: dbd_pgsql.c,v 1.23 2002/10/21 06:21:50 dap Exp $
  */

 #ifdef HAVE_CONFIG_H
@@ -187,10 +187,10 @@
 	}

 	if (pattern == NULL) {
-		return (dbi_result_t *)dbi_conn_query((dbi_conn)conn, "SELECT relname FROM pg_class WHERE relname !~ '^pg_' AND relkind = 'r' AND relowner = (SELECT datdba FROM pg_database WHERE datname = '%s') ORDER BY relname", db);
+		return (dbi_result_t *)dbi_conn_queryf((dbi_conn)conn, "SELECT relname FROM pg_class WHERE relname !~ '^pg_' AND relkind = 'r' AND relowner = (SELECT datdba FROM pg_database WHERE datname = '%s') ORDER BY relname", db);
 	}
 	else {
-		return (dbi_result_t *)dbi_conn_query((dbi_conn)conn, "SELECT relname FROM pg_class WHERE relname !~ '^pg_' AND relname LIKE '%s' AND relkind = 'r' AND relowner = (SELECT datdba FROM pg_database WHERE datname = '%s') ORDER BY relname", pattern, db);
+		return (dbi_result_t *)dbi_conn_queryf((dbi_conn)conn, "SELECT relname FROM pg_class WHERE relname !~ '^pg_' AND relname LIKE '%s' AND relkind = 'r' AND relowner = (SELECT datdba FROM pg_database WHERE datname = '%s') ORDER BY relname", pattern, db);
 	}
 }