Re: [PATCH v3 1/5] arch_topology: validate input frequencies to arch_set_freq_scale()

2020-08-24 Thread Viresh Kumar
On 24-08-20, 22:02, Ionela Voinescu wrote:
> The current frequency passed to arch_set_freq_scale() could end up
> being 0, signaling an error in setting a new frequency. Also, if the
> maximum frequency in 0, this will result in a division by 0 error.
> 
> Therefore, validate these input values before using them for the
> setting of the frequency scale factor.
> 
> Signed-off-by: Ionela Voinescu 
> Cc: Sudeep Holla 
> Cc: Rafael J. Wysocki 
> ---
>  drivers/base/arch_topology.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c
> index 75f72d684294..1aca82fcceb8 100644
> --- a/drivers/base/arch_topology.c
> +++ b/drivers/base/arch_topology.c
> @@ -33,6 +33,9 @@ void arch_set_freq_scale(struct cpumask *cpus, unsigned 
> long cur_freq,
>   unsigned long scale;
>   int i;
>  
> + if (!cur_freq || !max_freq)

We should probably use unlikely() here.

Rafael: Shouldn't this have a WARN_ON_ONCE() as well ?

> + return;
> +
>   /*
>* If the use of counters for FIE is enabled, just return as we don't
>* want to update the scale factor with information from CPUFREQ.
> -- 
> 2.17.1

-- 
viresh


kernel/dma/pool.c:79 cma_in_zone() warn: always true condition '(end <= ((((32) == 64)) << (32)) - 1))) => (0-u32max <= u32max)'

2020-08-24 Thread kernel test robot
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
master
head:   6a9dc5fd6170d0a41c8a14eb19e63d94bea5705a
commit: d7e673ec2c8e0ea39c4c70fc490d67d7fbda869d dma-pool: Only allocate from 
CMA when in same memory zone
date:   11 days ago
config: arc-randconfig-m031-20200824 (attached as .config)
compiler: arc-elf-gcc (GCC) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot 

New smatch warnings:
kernel/dma/pool.c:79 cma_in_zone() warn: always true condition '(end <= 32) 
== 64)) ?~0:((1 << (32)) - 1))) => (0-u32max <= u32max)'

Old smatch warnings:
arch/arc/include/asm/thread_info.h:65 current_thread_info() error: 
uninitialized symbol 'sp'.

# 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d7e673ec2c8e0ea39c4c70fc490d67d7fbda869d
git remote add linus 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
git fetch --no-tags linus master
git checkout d7e673ec2c8e0ea39c4c70fc490d67d7fbda869d
vim +79 kernel/dma/pool.c

59  
60  static bool cma_in_zone(gfp_t gfp)
61  {
62  unsigned long size;
63  phys_addr_t end;
64  struct cma *cma;
65  
66  cma = dev_get_cma_area(NULL);
67  if (!cma)
68  return false;
69  
70  size = cma_get_size(cma);
71  if (!size)
72  return false;
73  
74  /* CMA can't cross zone boundaries, see cma_activate_area() */
75  end = cma_get_base(cma) + size - 1;
76  if (IS_ENABLED(CONFIG_ZONE_DMA) && (gfp & GFP_DMA))
77  return end <= DMA_BIT_MASK(zone_dma_bits);
78  if (IS_ENABLED(CONFIG_ZONE_DMA32) && (gfp & GFP_DMA32))
  > 79  return end <= DMA_BIT_MASK(32);
80  return true;
81  }
82  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-...@lists.01.org


.config.gz
Description: application/gzip


[PATCH v2] can: m_can: Set device to software init mode before closing

2020-08-24 Thread Faiz Abbas
There might be some requests pending in the buffer when the
interface close sequence occurs. In some devices, these
pending requests might lead to the module not shutting down
properly when m_can_clk_stop() is called.

Therefore, move the device to init state before potentially
powering it down.

Signed-off-by: Faiz Abbas 
---

changes since v1: Rebased to latest mainline

 drivers/net/can/m_can/m_can.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index 02c5795b7393..d0c458f7f6e1 100644
--- a/drivers/net/can/m_can/m_can.c
+++ b/drivers/net/can/m_can/m_can.c
@@ -1414,6 +1414,9 @@ static void m_can_stop(struct net_device *dev)
/* disable all interrupts */
m_can_disable_all_interrupts(cdev);
 
+   /* Set init mode to disengage from the network */
+   m_can_config_endisable(cdev, true);
+
/* set the state as STOPPED */
cdev->can.state = CAN_STATE_STOPPED;
 }
-- 
2.17.1



Re: [PATCH v2 3/9] ASoC: audio-graph: Identify 'no_pcm' DAI links for DPCM

2020-08-24 Thread Sameer Pujar

Hi Morimoto-san,


Yes, I'm posting fixup patch.

  https://patchwork.kernel.org/patch/11719919/

Just curious that why snd_soc_find_dai() itself cannot be protected,
instead of leaving this to callers.

Because, snd_soc_find_dai() is called both with/without client_mutex.
(same/sof are calling it with mutex, simple-card/audio-graph are calling 
without mutex)

Other solution is create both snd_soc_find_dai_with_mutex()/without_mutex().
I'm not sure which style is best.


I don't know how complex it is to have a unified solution. But if we can 
protect snd_soc_find_dai() itself, things would be simpler may be in 
long term. Right now there are separate source files for soc-core, 
soc-dai and soc-component, but because of two approaches looks like the 
function need to be moved around and need to be placed in soc-core. Also 
the issue might go unnoticed if LOCKDEP is not enabled.


May be start with a wrapper for now and eventually unify?

Thanks,
Sameer.



Re: [PATCH 5.4 000/109] 5.4.61-rc2 review

2020-08-24 Thread Naresh Kamboju
On Mon, 24 Aug 2020 at 22:19, Greg Kroah-Hartman
 wrote:
>
> This is the start of the stable review cycle for the 5.4.61 release.
> There are 109 patches in this series, all will be posted as a response
> to this one.  If anyone has any issues with these being applied, please
> let me know.
>
> Responses should be made by Wed, 26 Aug 2020 16:47:07 +.
> Anything received after that time might be too late.
>
> The whole patch series can be found in one patch at:
> 
> https://www.kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.4.61-rc2.gz
> or in the git tree and branch at:
> 
> git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git 
> linux-5.4.y
> and the diffstat can be found below.
>
> thanks,
>
> greg k-h
>


Results from Linaro’s test farm.
No regressions on arm64, arm, x86_64, and i386.

Summary


kernel: 5.4.61-rc2
git repo: 
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git
git branch: linux-5.4.y
git commit: d3dbec480949413c968365e6f8c25b1e7847e4dd
git describe: v5.4.60-110-gd3dbec480949
Test details: 
https://qa-reports.linaro.org/lkft/linux-stable-rc-5.4-oe/build/v5.4.60-110-gd3dbec480949

No regressions (compared to build v5.4.60)

No fixes (compared to build v5.4.60)


Ran 36416 total tests in the following environments and test suites.

Environments
--
- dragonboard-410c
- hi6220-hikey
- i386
- juno-r2
- juno-r2-compat
- juno-r2-kasan
- nxp-ls2088
- qemu_arm
- qemu_arm64
- qemu_i386
- qemu_x86_64
- x15
- x86
- x86-kasan

Test Suites
---
* build
* igt-gpu-tools
* install-android-platform-tools-r2600
* kselftest
* kselftest/drivers
* kselftest/filesystems
* kselftest/net
* libhugetlbfs
* linux-log-parser
* ltp-containers-tests
* ltp-cve-tests
* ltp-dio-tests
* ltp-fs-tests
* ltp-hugetlb-tests
* ltp-io-tests
* ltp-ipc-tests
* ltp-mm-tests
* ltp-syscalls-tests
* perf
* v4l2-compliance
* ltp-cap_bounds-tests
* ltp-commands-tests
* ltp-cpuhotplug-tests
* ltp-crypto-tests
* ltp-math-tests
* ltp-nptl-tests
* ltp-pty-tests
* ltp-sched-tests
* ltp-securebits-tests
* network-basic-tests
* ltp-controllers-tests
* ltp-fcntl-locktests-tests
* ltp-filecaps-tests
* ltp-fs_bind-tests
* ltp-fs_perms_simple-tests
* ltp-fsx-tests
* ltp-open-posix-tests
* ltp-tracing-tests
* kselftest-vsyscall-mode-native
* kselftest-vsyscall-mode-native/drivers
* kselftest-vsyscall-mode-native/filesystems
* kselftest-vsyscall-mode-native/net
* kselftest-vsyscall-mode-none
* kselftest-vsyscall-mode-none/drivers
* kselftest-vsyscall-mode-none/filesystems
* kselftest-vsyscall-mode-none/net
* ssuite

-- 
Linaro LKFT
https://lkft.linaro.org


Re: [PATCH V2] cpufreq: tegra186: Fix initial frequency

2020-08-24 Thread Viresh Kumar
On 24-08-20, 15:59, Jon Hunter wrote:
> Commit 6cc3d0e9a097 ("cpufreq: tegra186: add
> CPUFREQ_NEED_INITIAL_FREQ_CHECK flag") fixed CPUFREQ support for
> Tegra186 but as a consequence the following warnings are now seen on
> boot ...
> 
>  cpufreq: cpufreq_online: CPU0: Running at unlisted freq: 0 KHz
>  cpufreq: cpufreq_online: CPU0: Unlisted initial frequency changed to: 
> 2035200 KHz
>  cpufreq: cpufreq_online: CPU1: Running at unlisted freq: 0 KHz
>  cpufreq: cpufreq_online: CPU1: Unlisted initial frequency changed to: 
> 2035200 KHz
>  cpufreq: cpufreq_online: CPU2: Running at unlisted freq: 0 KHz
>  cpufreq: cpufreq_online: CPU2: Unlisted initial frequency changed to: 
> 2035200 KHz
>  cpufreq: cpufreq_online: CPU3: Running at unlisted freq: 0 KHz
>  cpufreq: cpufreq_online: CPU3: Unlisted initial frequency changed to: 
> 2035200 KHz
>  cpufreq: cpufreq_online: CPU4: Running at unlisted freq: 0 KHz
>  cpufreq: cpufreq_online: CPU4: Unlisted initial frequency changed to: 
> 2035200 KHz
>  cpufreq: cpufreq_online: CPU5: Running at unlisted freq: 0 KHz
>  cpufreq: cpufreq_online: CPU5: Unlisted initial frequency changed to: 
> 2035200 KHz
> 
> Fix this by adding a 'get' callback for the Tegra186 CPUFREQ driver to
> retrieve the current operating frequency for a given CPU. The 'get'
> callback uses the current 'ndiv' value that is programmed to determine
> that current operating frequency.
> 
> Signed-off-by: Jon Hunter 
> ---
> Changes since V1:
> - Moved code into a 'get' callback
> 
>  drivers/cpufreq/tegra186-cpufreq.c | 30 ++
>  1 file changed, 30 insertions(+)
> 
> diff --git a/drivers/cpufreq/tegra186-cpufreq.c 
> b/drivers/cpufreq/tegra186-cpufreq.c
> index 01e1f58ba422..0d0fcff60765 100644
> --- a/drivers/cpufreq/tegra186-cpufreq.c
> +++ b/drivers/cpufreq/tegra186-cpufreq.c
> @@ -14,6 +14,7 @@
>  
>  #define EDVD_CORE_VOLT_FREQ(core)(0x20 + (core) * 0x4)
>  #define EDVD_CORE_VOLT_FREQ_F_SHIFT  0
> +#define EDVD_CORE_VOLT_FREQ_F_MASK   0x
>  #define EDVD_CORE_VOLT_FREQ_V_SHIFT  16
>  
>  struct tegra186_cpufreq_cluster_info {
> @@ -91,10 +92,39 @@ static int tegra186_cpufreq_set_target(struct 
> cpufreq_policy *policy,
>   return 0;
>  }
>  
> +static unsigned int tegra186_cpufreq_get(unsigned int cpu)
> +{
> + struct cpufreq_frequency_table *tbl;
> + struct cpufreq_policy *policy;
> + void __iomem *edvd_reg;
> + unsigned int i, freq = 0;
> + u32 ndiv;
> +
> + policy = cpufreq_cpu_get(cpu);
> + if (!policy)
> + return -EINVAL;

This should be return 0;

Applied with that change. Thanks.

-- 
viresh


Re: [PATCH v4 17/17] media: mtk-vcodec: venc: fix invalid time per frame in S_PARM

2020-08-24 Thread Tiffany Lin
On Fri, 2020-08-21 at 19:36 +0900, Alexandre Courbot wrote:
> v4l2-compliance expects the driver to adjust the time per frame if it is
> invalid (numerator or denominator set to 0). Adjust it to the default
> value in these cases.
> 

Acked-by: Tiffany Lin 

> Signed-off-by: Alexandre Courbot 
> ---
>  drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c | 12 
>  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c 
> b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
> index 09baac2dbc36..82b04714f750 100644
> --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
> +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
> @@ -200,14 +200,18 @@ static int vidioc_venc_s_parm(struct file *file, void 
> *priv,
> struct v4l2_streamparm *a)
>  {
>   struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
> + struct v4l2_fract *timeperframe = >parm.output.timeperframe;
>  
>   if (a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
>   return -EINVAL;
>  
> - ctx->enc_params.framerate_num =
> - a->parm.output.timeperframe.denominator;
> - ctx->enc_params.framerate_denom =
> - a->parm.output.timeperframe.numerator;
> + if (timeperframe->numerator == 0 || timeperframe->denominator == 0) {
> + timeperframe->numerator = MTK_DEFAULT_FRAMERATE_NUM;
> + timeperframe->denominator = MTK_DEFAULT_FRAMERATE_DENOM;
> + }
> +
> + ctx->enc_params.framerate_num = timeperframe->denominator;
> + ctx->enc_params.framerate_denom = timeperframe->numerator;
>   ctx->param_change |= MTK_ENCODE_PARAM_FRAMERATE;
>  
>   a->parm.output.capability = V4L2_CAP_TIMEPERFRAME;



Re: [PATCH v4 16/17] media: mtk-vcodec: venc: set default time per frame

2020-08-24 Thread Tiffany Lin
On Fri, 2020-08-21 at 19:36 +0900, Alexandre Courbot wrote:
> The time per frame was left initialized to 0/0, which make the driver
> fail v4l2-compliance, and also leaves it potentially exposed to doing a
> division by zero.
> 
Acked-by: Tiffany Lin 

> Signed-off-by: Alexandre Courbot 
> ---
>  drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c | 5 +
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c 
> b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
> index 1b79185cf922..09baac2dbc36 100644
> --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
> +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
> @@ -24,6 +24,9 @@
>  #define DFT_CFG_HEIGHT   MTK_VENC_MIN_H
>  #define MTK_MAX_CTRLS_HINT   20
>  
> +#define MTK_DEFAULT_FRAMERATE_NUM 1001
> +#define MTK_DEFAULT_FRAMERATE_DENOM 3
> +
>  static void mtk_venc_worker(struct work_struct *work);
>  
>  static const struct v4l2_frmsize_stepwise mtk_venc_framesizes = {
> @@ -1197,6 +1200,8 @@ void mtk_vcodec_enc_set_default_params(struct 
> mtk_vcodec_ctx *ctx)
>   DFT_CFG_WIDTH * DFT_CFG_HEIGHT;
>   ctx->q_data[MTK_Q_DATA_DST].bytesperline[0] = 0;
>  
> + ctx->enc_params.framerate_num = MTK_DEFAULT_FRAMERATE_NUM;
> + ctx->enc_params.framerate_denom = MTK_DEFAULT_FRAMERATE_DENOM;
>  }
>  
>  int mtk_vcodec_enc_ctrls_setup(struct mtk_vcodec_ctx *ctx)



Re: [PATCH v4 15/17] media: mtk-vcodec: venc: support ENUM_FRAMESIZES on OUTPUT formats

2020-08-24 Thread Tiffany Lin
On Fri, 2020-08-21 at 19:36 +0900, Alexandre Courbot wrote:
> v4l2-compliance requires ENUM_FRAMESIZES to support OUTPUT formats.
> Reuse mtk_venc_find_format() to make sure both queues are considered
> when serving an ENUM_FRAMESIZES.
> 
Acked-by: Tiffany Lin 

> Signed-off-by: Alexandre Courbot 
> ---
>  .../platform/mtk-vcodec/mtk_vcodec_enc.c  | 71 +--
>  1 file changed, 33 insertions(+), 38 deletions(-)
> 
> diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c 
> b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
> index f8d4fbe927f9..1b79185cf922 100644
> --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
> +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
> @@ -123,28 +123,44 @@ static int vidioc_enum_fmt(struct v4l2_fmtdesc *f,
>   return 0;
>  }
>  
> +static const struct mtk_video_fmt *mtk_venc_find_format(u32 fourcc,
> + const struct mtk_vcodec_enc_pdata *pdata)
> +{
> + const struct mtk_video_fmt *fmt;
> + unsigned int k;
> +
> + for (k = 0; k < pdata->num_capture_formats; k++) {
> + fmt = >capture_formats[k];
> + if (fmt->fourcc == fourcc)
> + return fmt;
> + }
> +
> + for (k = 0; k < pdata->num_output_formats; k++) {
> + fmt = >output_formats[k];
> + if (fmt->fourcc == fourcc)
> + return fmt;
> + }
> +
> + return NULL;
> +}
> +
>  static int vidioc_enum_framesizes(struct file *file, void *fh,
> struct v4l2_frmsizeenum *fsize)
>  {
> - const struct mtk_vcodec_enc_pdata *pdata =
> - fh_to_ctx(fh)->dev->venc_pdata;
> - int i = 0;
> + const struct mtk_video_fmt *fmt;
>  
>   if (fsize->index != 0)
>   return -EINVAL;
>  
> - for (i = 0; i < pdata->num_capture_formats; ++i) {
> - const struct mtk_video_fmt *fmt = >capture_formats[i];
> + fmt = mtk_venc_find_format(fsize->pixel_format,
> +fh_to_ctx(fh)->dev->venc_pdata);
> + if (!fmt)
> + return -EINVAL;
>  
> - if (fsize->pixel_format != fmt->fourcc)
> - continue;
> + fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
> + fsize->stepwise = mtk_venc_framesizes;
>  
> - fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
> - fsize->stepwise = mtk_venc_framesizes;
> - return 0;
> - }
> -
> - return -EINVAL;
> + return 0;
>  }
>  
>  static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
> @@ -222,27 +238,6 @@ static struct mtk_q_data *mtk_venc_get_q_data(struct 
> mtk_vcodec_ctx *ctx,
>   return >q_data[MTK_Q_DATA_DST];
>  }
>  
> -static const struct mtk_video_fmt *mtk_venc_find_format(struct v4l2_format 
> *f,
> - const struct mtk_vcodec_enc_pdata *pdata)
> -{
> - const struct mtk_video_fmt *fmt;
> - unsigned int k;
> -
> - for (k = 0; k < pdata->num_capture_formats; k++) {
> - fmt = >capture_formats[k];
> - if (fmt->fourcc == f->fmt.pix.pixelformat)
> - return fmt;
> - }
> -
> - for (k = 0; k < pdata->num_output_formats; k++) {
> - fmt = >output_formats[k];
> - if (fmt->fourcc == f->fmt.pix.pixelformat)
> - return fmt;
> - }
> -
> - return NULL;
> -}
> -
>  /* V4L2 specification suggests the driver corrects the format struct if any 
> of
>   * the dimensions is unsupported
>   */
> @@ -403,7 +398,7 @@ static int vidioc_venc_s_fmt_cap(struct file *file, void 
> *priv,
>   return -EINVAL;
>   }
>  
> - fmt = mtk_venc_find_format(f, pdata);
> + fmt = mtk_venc_find_format(f->fmt.pix.pixelformat, pdata);
>   if (!fmt) {
>   fmt = >dev->venc_pdata->capture_formats[0];
>   f->fmt.pix.pixelformat = fmt->fourcc;
> @@ -467,7 +462,7 @@ static int vidioc_venc_s_fmt_out(struct file *file, void 
> *priv,
>   return -EINVAL;
>   }
>  
> - fmt = mtk_venc_find_format(f, pdata);
> + fmt = mtk_venc_find_format(f->fmt.pix.pixelformat, pdata);
>   if (!fmt) {
>   fmt = >dev->venc_pdata->output_formats[0];
>   f->fmt.pix.pixelformat = fmt->fourcc;
> @@ -550,7 +545,7 @@ static int vidioc_try_fmt_vid_cap_mplane(struct file 
> *file, void *priv,
>   struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
>   const struct mtk_vcodec_enc_pdata *pdata = ctx->dev->venc_pdata;
>  
> - fmt = mtk_venc_find_format(f, pdata);
> + fmt = mtk_venc_find_format(f->fmt.pix.pixelformat, pdata);
>   if (!fmt) {
>   fmt = >dev->venc_pdata->capture_formats[0];
>   f->fmt.pix.pixelformat = fmt->fourcc;
> @@ -570,7 +565,7 @@ static int vidioc_try_fmt_vid_out_mplane(struct file 
> *file, void *priv,
>   struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
>   const struct mtk_vcodec_enc_pdata *pdata = ctx->dev->venc_pdata;
>  
> - fmt = 

Re: [PATCH v2 3/9] ASoC: audio-graph: Identify 'no_pcm' DAI links for DPCM

2020-08-24 Thread Kuninori Morimoto


Hi Sameer

> > Yes, I'm posting fixup patch.
> > 
> >  https://patchwork.kernel.org/patch/11719919/
> 
> Just curious that why snd_soc_find_dai() itself cannot be protected,
> instead of leaving this to callers.

Because, snd_soc_find_dai() is called both with/without client_mutex.
(same/sof are calling it with mutex, simple-card/audio-graph are calling 
without mutex)

Other solution is create both snd_soc_find_dai_with_mutex()/without_mutex().
I'm not sure which style is best.

Thank you for your help !!

Best regards
---
Kuninori Morimoto


Re: [PATCH v4 14/17] media: mtk-vcodec: venc: use platform data for ENUM_FRAMESIZES

2020-08-24 Thread Tiffany Lin
On Fri, 2020-08-21 at 19:36 +0900, Alexandre Courbot wrote:
> vidioc_enum_framesizes() assumes that all encoders support H.264 and VP8,
> which is not necessarily true and requires to duplicate information about
> the supported codecs which is already stored in the platform data.
> 
> Fix this by referring to the platform data to find out whether a given
> format is supported. Since the supported sizes are all the same
> regardless of the format, we can then return a copy of a static value if
> the format is supported.
> 

Acked-by: Tiffany Lin 

> Signed-off-by: Alexandre Courbot 
> ---
>  .../platform/mtk-vcodec/mtk_vcodec_enc.c  | 24 ---
>  1 file changed, 10 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c 
> b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
> index 1a981d842c19..f8d4fbe927f9 100644
> --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
> +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
> @@ -26,17 +26,9 @@
>  
>  static void mtk_venc_worker(struct work_struct *work);
>  
> -static const struct mtk_codec_framesizes mtk_venc_framesizes[] = {
> - {
> - .fourcc = V4L2_PIX_FMT_H264,
> - .stepwise = { MTK_VENC_MIN_W, MTK_VENC_MAX_W, 16,
> -   MTK_VENC_MIN_H, MTK_VENC_MAX_H, 16 },
> - },
> - {
> - .fourcc = V4L2_PIX_FMT_VP8,
> - .stepwise = { MTK_VENC_MIN_W, MTK_VENC_MAX_W, 16,
> -   MTK_VENC_MIN_H, MTK_VENC_MAX_H, 16 },
> - },
> +static const struct v4l2_frmsize_stepwise mtk_venc_framesizes = {
> + MTK_VENC_MIN_W, MTK_VENC_MAX_W, 16,
> + MTK_VENC_MIN_H, MTK_VENC_MAX_H, 16,
>  };
>  
>  #define NUM_SUPPORTED_FRAMESIZE ARRAY_SIZE(mtk_venc_framesizes)
> @@ -134,17 +126,21 @@ static int vidioc_enum_fmt(struct v4l2_fmtdesc *f,
>  static int vidioc_enum_framesizes(struct file *file, void *fh,
> struct v4l2_frmsizeenum *fsize)
>  {
> + const struct mtk_vcodec_enc_pdata *pdata =
> + fh_to_ctx(fh)->dev->venc_pdata;
>   int i = 0;
>  
>   if (fsize->index != 0)
>   return -EINVAL;
>  
> - for (i = 0; i < NUM_SUPPORTED_FRAMESIZE; ++i) {
> - if (fsize->pixel_format != mtk_venc_framesizes[i].fourcc)
> + for (i = 0; i < pdata->num_capture_formats; ++i) {
> + const struct mtk_video_fmt *fmt = >capture_formats[i];
> +
> + if (fsize->pixel_format != fmt->fourcc)
>   continue;
>  
>   fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
> - fsize->stepwise = mtk_venc_framesizes[i].stepwise;
> + fsize->stepwise = mtk_venc_framesizes;
>   return 0;
>   }
>  



[PATCH v2] MAINTAINERS: update QUALCOMM IOMMU after Arm SMMU drivers move

2020-08-24 Thread Lukas Bulwahn
Commit e86d1aa8b60f ("iommu/arm-smmu: Move Arm SMMU drivers into their own
subdirectory") moved drivers/iommu/qcom_iommu.c to
drivers/iommu/arm/arm-smmu/qcom_iommu.c amongst other moves, adjusted some
sections in MAINTAINERS, but missed adjusting the QUALCOMM IOMMU section.

Hence, ./scripts/get_maintainer.pl --self-test=patterns complains:

  warning: no file matchesF:drivers/iommu/qcom_iommu.c

Update the file entry in MAINTAINERS to the new location.

Signed-off-by: Lukas Bulwahn 
Acked-by: Will Deacon 
---
v1: https://lore.kernel.org/lkml/20200802065320.7470-1-lukas.bulw...@gmail.com/
v1 -> v2: typo fixed; added Will's Ack.

Joerg, please pick this minor non-urgent patch for your -next branch.

applies cleanly on next-20200731

 MAINTAINERS | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 1469cb81261d..e175c0741653 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -14358,7 +14358,7 @@ M:  Rob Clark 
 L: io...@lists.linux-foundation.org
 L: linux-arm-...@vger.kernel.org
 S: Maintained
-F: drivers/iommu/qcom_iommu.c
+F: drivers/iommu/arm/arm-smmu/qcom_iommu.c
 
 QUALCOMM IPCC MAILBOX DRIVER
 M: Manivannan Sadhasivam 
-- 
2.17.1



Re: [PATCH for v5.9] mm/page_alloc: handle a missing case for memalloc_nocma_{save/restore} APIs

2020-08-24 Thread Joonsoo Kim
2020년 8월 25일 (화) 오후 2:10, Andrew Morton 님이 작성:
>
> On Tue, 25 Aug 2020 13:59:42 +0900 js1...@gmail.com wrote:
>
> > From: Joonsoo Kim 
> >
> > memalloc_nocma_{save/restore} APIs can be used to skip page allocation
> > on CMA area, but, there is a missing case and the page on CMA area could
> > be allocated even if APIs are used. This patch handles this case to fix
> > the potential issue.
> >
> > Missing case is an allocation from the pcplist. MIGRATE_MOVABLE pcplist
> > could have the pages on CMA area so we need to skip it if ALLOC_CMA isn't
> > specified.
> >
> > This patch implements this behaviour by checking allocated page from
> > the pcplist rather than skipping an allocation from the pcplist entirely.
> > Skipping the pcplist entirely would result in a mismatch between watermark
> > check and actual page allocation. And, it requires to break current code
> > layering that order-0 page is always handled by the pcplist. I'd prefer
> > to avoid it so this patch uses different way to skip CMA page allocation
> > from the pcplist.
> >
> > ...
> >
> > --- a/mm/page_alloc.c
> > +++ b/mm/page_alloc.c
> > @@ -3341,6 +3341,22 @@ static struct page *rmqueue_pcplist(struct zone 
> > *preferred_zone,
> >   pcp = _cpu_ptr(zone->pageset)->pcp;
> >   list = >lists[migratetype];
> >   page = __rmqueue_pcplist(zone,  migratetype, alloc_flags, pcp, list);
> > +#ifdef CONFIG_CMA
> > + if (page) {
> > + int mt = get_pcppage_migratetype(page);
> > +
> > + /*
> > +  * pcp could have the pages on CMA area and we need to skip it
> > +  * when !ALLOC_CMA. Free all pcplist and retry allocation.
> > +  */
> > + if (is_migrate_cma(mt) && !(alloc_flags & ALLOC_CMA)) {
> > + list_add(>lru, >lists[migratetype]);
> > + pcp->count++;
> > + free_pcppages_bulk(zone, pcp->count, pcp);
> > + page = __rmqueue_pcplist(zone, migratetype, 
> > alloc_flags, pcp, list);
> > + }
> > + }
> > +#endif
> >   if (page) {
> >   __count_zid_vm_events(PGALLOC, page_zonenum(page), 1);
> >   zone_statistics(preferred_zone, zone);
>
> That's a bunch more code on a very hot path to serve an obscure feature
> which has a single obscure callsite.
>
> Can we instead put the burden on that callsite rather than upon
> everyone?  For (dumb) example, teach __gup_longterm_locked() to put the
> page back if it's CMA and go get another one?

Hmm... Unfortunately, it cannot ensure that we eventually get the non-CMA page.
I think that the only way to ensure it is to implement the
functionality here. We can
use 'unlikely' or 'static branch' to reduce the overhead for a really
rare case but
for now I have no idea how to completely remove the overhead.

Thanks.


Re: [PATCH 5.7 000/127] 5.7.18-rc2 review

2020-08-24 Thread Naresh Kamboju
On Mon, 24 Aug 2020 at 22:18, Greg Kroah-Hartman
 wrote:
>
> This is the start of the stable review cycle for the 5.7.18 release.
> There are 127 patches in this series, all will be posted as a response
> to this one.  If anyone has any issues with these being applied, please
> let me know.
>
> Responses should be made by Wed, 26 Aug 2020 16:47:07 +.
> Anything received after that time might be too late.
>
> The whole patch series can be found in one patch at:
> 
> https://www.kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.7.18-rc2.gz
> or in the git tree and branch at:
> 
> git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git 
> linux-5.7.y
> and the diffstat can be found below.
>
> thanks,
>
> greg k-h
>

Results from Linaro’s test farm.
No regressions on arm64, arm, x86_64, and i386.

Summary


kernel: 5.7.18-rc2
git repo: 
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git
git branch: linux-5.7.y
git commit: f16d132bb2de3adb5e9470242c50c83b6d5d9a54
git describe: v5.7.17-128-gf16d132bb2de
Test details: 
https://qa-reports.linaro.org/lkft/linux-stable-rc-5.7-oe/build/v5.7.17-128-gf16d132bb2de

No regressions (compared to build v5.7.17)

No fixes (compared to build v5.7.17)

Ran 34887 total tests in the following environments and test suites.

Environments
--
- dragonboard-410c
- hi6220-hikey
- i386
- juno-r2
- juno-r2-compat
- juno-r2-kasan
- nxp-ls2088
- qemu_arm
- qemu_arm64
- qemu_i386
- qemu_x86_64
- x15
- x86
- x86-kasan

Test Suites
---
* build
* igt-gpu-tools
* install-android-platform-tools-r2600
* linux-log-parser
* ltp-cap_bounds-tests
* ltp-containers-tests
* ltp-cpuhotplug-tests
* ltp-crypto-tests
* ltp-cve-tests
* ltp-dio-tests
* ltp-hugetlb-tests
* ltp-io-tests
* ltp-ipc-tests
* ltp-mm-tests
* ltp-nptl-tests
* ltp-pty-tests
* ltp-sched-tests
* ltp-securebits-tests
* ltp-tracing-tests
* v4l2-compliance
* kselftest
* kselftest/drivers
* kselftest/filesystems
* ltp-commands-tests
* ltp-controllers-tests
* ltp-math-tests
* perf
* kselftest/net
* libhugetlbfs
* ltp-fcntl-locktests-tests
* ltp-filecaps-tests
* ltp-fs-tests
* ltp-fs_bind-tests
* ltp-fs_perms_simple-tests
* ltp-fsx-tests
* ltp-open-posix-tests
* ltp-syscalls-tests
* network-basic-tests
* ssuite
* kselftest-vsyscall-mode-native
* kselftest-vsyscall-mode-native/drivers
* kselftest-vsyscall-mode-native/filesystems
* kselftest-vsyscall-mode-native/net
* kselftest-vsyscall-mode-none
* kselftest-vsyscall-mode-none/drivers
* kselftest-vsyscall-mode-none/filesystems
* kselftest-vsyscall-mode-none/net

-- 
Linaro LKFT
https://lkft.linaro.org


Re: [PATCH] CHROMIUM: arm64: dts: mt8183-elm: Set GPU power regulator to always on

2020-08-24 Thread Anand K. Mistry
:facepalm: sorry about the subject line. I'll fix it up in the next revision.

On Tue, 25 Aug 2020 at 15:26, Anand K Mistry  wrote:
>
> Keep the da9212 BUCKB always-on. This works around an issue on Elm/Hana
> devices where sometimes, the regulator is disabled before scpsys is
> suspended, causing the suspension of scpsys to fail.
>
> Usually, the GPU and scpsys are suspended by the runtime PM before the
> system is suspended, due to the GPU being idle. In this case, scpsys is
> suspended inline with the GPU suspend, which then disables the
> regulator. However, if the GPU is still active when system is suspended,
> GPU suspend occurs but defers suspending scpsys to the PM's noirq phase.
> Since GPU suspend disables the regulator, scpsys isn't powered and
> suspending it fails with the following error:
> [  523.773227] mtk-scpsys 10006000.scpsys: Failed to power off domain mfg_2d
>
> On resume, scpsys is resumed in the noirq phase. Since scpsys requires
> power from the regulator, which is still disabled at this point,
> attempting to turn it on will hang the CPU. A HW watchdog eventually
> reboots the system.
>
> The obvious solution would be to add a link to the regulator from scpsys
> in the devicetree. This would prevent the regulator from being disabled
> until scpsys is suspended. However, in the case where suspending scpsys
> is deferred to the noirq phase, disabling the regulator will fail since
> it is connected over I2C which requires IRQs to be enabled. Even in the
> usual case where scpsys is suspended inline with the GPU, PM will always
> attempt to resume scpsys in noirq. This will attempt to enable the
> regulator, which will also fail due to being unable to communicate over
> I2C.
>
> Since I2C can't be using with IRQs disabled, a workaround is to never
> turn off the regulator.
>
> Measuring power on the GPU rail on a Elm DVT shows that the change in
> power usage is negligible. The two relavent cases are S0 with an idle
> GPU, and S3.
>
> In S0 with an idle GPU, current behaviour with the regulator off:
> @@   NAME  COUNT  AVERAGE  STDDEV  MAXMIN
> @@ gpu_mw600 1.741.31 6.75   0.00
> ... and with the regulator on, but no load:
> @@   NAME  COUNT  AVERAGE  STDDEV MAXMIN
> @@ gpu_mw600 1.681.257.13   0.00
> The difference being well within the margin of error.
>
> In S3, current behaviour with the regulator off:
> @@   NAME  COUNT  AVERAGE  STDDEV MAXMIN
> @@ gpu_mw600 0.940.743.25   0.00
> ... and with the regulator on:
> @@   NAME  COUNT  AVERAGE  STDDEV MAX MIN
> @@ gpu_mw600 0.830.663.250.00
>
> Signed-off-by: Anand K Mistry 
>
> ---
>
>  arch/arm64/boot/dts/mediatek/mt8173-elm.dtsi | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/arch/arm64/boot/dts/mediatek/mt8173-elm.dtsi 
> b/arch/arm64/boot/dts/mediatek/mt8173-elm.dtsi
> index a5a12b2599a4..1294f27b21c1 100644
> --- a/arch/arm64/boot/dts/mediatek/mt8173-elm.dtsi
> +++ b/arch/arm64/boot/dts/mediatek/mt8173-elm.dtsi
> @@ -304,6 +304,7 @@ da9211_vgpu_reg: BUCKB {
> regulator-min-microamp  = <200>;
> regulator-max-microamp  = <300>;
> regulator-ramp-delay = <1>;
> +   regulator-always-on;
> };
> };
> };
> --
> 2.28.0.297.g1956fa8f8d-goog
>


-- 
Anand K. Mistry
Software Engineer
Google Australia


[PATCH net backport 5.6.14-5.8.3 v1] net: openvswitch: introduce common code for flushing flows

2020-08-24 Thread xiangxia . m . yue
From: Tonghao Zhang 

[ Upstream commit 77b981c82c1df7c7ad32a046f17f007450b46954 ]

Backport this commit to 5.6.14 - 5.8.3.

To avoid some issues, for example RCU usage warning and double free,
we should flush the flows under ovs_lock. This patch refactors
table_instance_destroy and introduces table_instance_flow_flush
which can be invoked by __dp_destroy or ovs_flow_tbl_flush.

Fixes: 50b0e61b32ee ("net: openvswitch: fix possible memleak on destroy 
flow-table")
Reported-by: Johan Knöös 
Reported-at: 
https://mail.openvswitch.org/pipermail/ovs-discuss/2020-August/050489.html
Signed-off-by: Tonghao Zhang 
Reviewed-by: Cong Wang 
Signed-off-by: David S. Miller 
---
 net/openvswitch/datapath.c   | 10 +-
 net/openvswitch/flow_table.c | 35 +++
 net/openvswitch/flow_table.h |  3 +++
 3 files changed, 27 insertions(+), 21 deletions(-)

diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
index 94b024534987..03b81aa99975 100644
--- a/net/openvswitch/datapath.c
+++ b/net/openvswitch/datapath.c
@@ -1736,6 +1736,7 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct 
genl_info *info)
 /* Called with ovs_mutex. */
 static void __dp_destroy(struct datapath *dp)
 {
+   struct flow_table *table = >table;
int i;
 
for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++) {
@@ -1754,7 +1755,14 @@ static void __dp_destroy(struct datapath *dp)
 */
ovs_dp_detach_port(ovs_vport_ovsl(dp, OVSP_LOCAL));
 
-   /* RCU destroy the flow table */
+   /* Flush sw_flow in the tables. RCU cb only releases resource
+* such as dp, ports and tables. That may avoid some issues
+* such as RCU usage warning.
+*/
+   table_instance_flow_flush(table, ovsl_dereference(table->ti),
+ ovsl_dereference(table->ufid_ti));
+
+   /* RCU destroy the ports, meters and flow tables. */
call_rcu(>rcu, destroy_dp_rcu);
 }
 
diff --git a/net/openvswitch/flow_table.c b/net/openvswitch/flow_table.c
index 2398d7238300..f198bbb0c517 100644
--- a/net/openvswitch/flow_table.c
+++ b/net/openvswitch/flow_table.c
@@ -345,19 +345,15 @@ static void table_instance_flow_free(struct flow_table 
*table,
flow_mask_remove(table, flow->mask);
 }
 
-static void table_instance_destroy(struct flow_table *table,
-  struct table_instance *ti,
-  struct table_instance *ufid_ti,
-  bool deferred)
+/* Must be called with OVS mutex held. */
+void table_instance_flow_flush(struct flow_table *table,
+  struct table_instance *ti,
+  struct table_instance *ufid_ti)
 {
int i;
 
-   if (!ti)
-   return;
-
-   BUG_ON(!ufid_ti);
if (ti->keep_flows)
-   goto skip_flows;
+   return;
 
for (i = 0; i < ti->n_buckets; i++) {
struct sw_flow *flow;
@@ -369,18 +365,16 @@ static void table_instance_destroy(struct flow_table 
*table,
 
table_instance_flow_free(table, ti, ufid_ti,
 flow, false);
-   ovs_flow_free(flow, deferred);
+   ovs_flow_free(flow, true);
}
}
+}
 
-skip_flows:
-   if (deferred) {
-   call_rcu(>rcu, flow_tbl_destroy_rcu_cb);
-   call_rcu(_ti->rcu, flow_tbl_destroy_rcu_cb);
-   } else {
-   __table_instance_destroy(ti);
-   __table_instance_destroy(ufid_ti);
-   }
+static void table_instance_destroy(struct table_instance *ti,
+  struct table_instance *ufid_ti)
+{
+   call_rcu(>rcu, flow_tbl_destroy_rcu_cb);
+   call_rcu(_ti->rcu, flow_tbl_destroy_rcu_cb);
 }
 
 /* No need for locking this function is called from RCU callback or
@@ -393,7 +387,7 @@ void ovs_flow_tbl_destroy(struct flow_table *table)
 
free_percpu(table->mask_cache);
kfree_rcu(rcu_dereference_raw(table->mask_array), rcu);
-   table_instance_destroy(table, ti, ufid_ti, false);
+   table_instance_destroy(ti, ufid_ti);
 }
 
 struct sw_flow *ovs_flow_tbl_dump_next(struct table_instance *ti,
@@ -511,7 +505,8 @@ int ovs_flow_tbl_flush(struct flow_table *flow_table)
flow_table->count = 0;
flow_table->ufid_count = 0;
 
-   table_instance_destroy(flow_table, old_ti, old_ufid_ti, true);
+   table_instance_flow_flush(flow_table, old_ti, old_ufid_ti);
+   table_instance_destroy(old_ti, old_ufid_ti);
return 0;
 
 err_free_ti:
diff --git a/net/openvswitch/flow_table.h b/net/openvswitch/flow_table.h
index 8a5cea6ae111..8ea8fc957377 100644
--- a/net/openvswitch/flow_table.h
+++ b/net/openvswitch/flow_table.h
@@ -86,4 +86,7 @@ bool ovs_flow_cmp(const struct sw_flow *, const struct 
sw_flow_match *);
 
 void ovs_flow_mask_key(struct sw_flow_key 

Re: [PATCH 5.8 000/149] 5.8.4-rc2 review

2020-08-24 Thread Naresh Kamboju
On Mon, 24 Aug 2020 at 22:18, Greg Kroah-Hartman
 wrote:
>
> This is the start of the stable review cycle for the 5.8.4 release.
> There are 149 patches in this series, all will be posted as a response
> to this one.  If anyone has any issues with these being applied, please
> let me know.
>
> Responses should be made by Wed, 26 Aug 2020 16:47:07 +.
> Anything received after that time might be too late.
>
> The whole patch series can be found in one patch at:
> 
> https://www.kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.8.4-rc2.gz
> or in the git tree and branch at:
> 
> git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git 
> linux-5.8.y
> and the diffstat can be found below.
>
> thanks,
>
> greg k-h

Results from Linaro’s test farm.
No regressions on arm64, arm, x86_64, and i386.

Summary


kernel: 5.8.4-rc2
git repo: 
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git
git branch: linux-5.8.y
git commit: ff3effda97baca98b891a29109810f3045ac
git describe: v5.8.3-150-gff3effda97ba
Test details: 
https://qa-reports.linaro.org/lkft/linux-stable-rc-5.8-oe/build/v5.8.3-150-gff3effda97ba

No regressions (compared to build v5.8.3)

No fixes (compared to build v5.8.3)


Ran 37993 total tests in the following environments and test suites.

Environments
--
- dragonboard-410c
- hi6220-hikey
- i386
- juno-r2
- juno-r2-compat
- juno-r2-kasan
- nxp-ls2088
- qemu_arm
- qemu_arm64
- qemu_i386
- qemu_x86_64
- x15
- x86
- x86-kasan

Test Suites
---
* build
* install-android-platform-tools-r2600
* kselftest
* kselftest/drivers
* kselftest/filesystems
* kselftest/net
* libhugetlbfs
* linux-log-parser
* ltp-controllers-tests
* ltp-cve-tests
* ltp-fs-tests
* ltp-sched-tests
* ltp-tracing-tests
* perf
* ltp-cap_bounds-tests
* ltp-commands-tests
* ltp-containers-tests
* ltp-cpuhotplug-tests
* ltp-crypto-tests
* ltp-fcntl-locktests-tests
* ltp-filecaps-tests
* ltp-fs_bind-tests
* ltp-fs_perms_simple-tests
* ltp-fsx-tests
* ltp-ipc-tests
* ltp-math-tests
* ltp-nptl-tests
* ltp-pty-tests
* ltp-securebits-tests
* network-basic-tests
* ltp-dio-tests
* ltp-hugetlb-tests
* ltp-io-tests
* ltp-mm-tests
* ltp-open-posix-tests
* ltp-syscalls-tests
* v4l2-compliance
* igt-gpu-tools
* ssuite
* kselftest-vsyscall-mode-native
* kselftest-vsyscall-mode-native/drivers
* kselftest-vsyscall-mode-native/filesystems
* kselftest-vsyscall-mode-native/net
* kselftest-vsyscall-mode-none
* kselftest-vsyscall-mode-none/drivers
* kselftest-vsyscall-mode-none/filesystems
* kselftest-vsyscall-mode-none/net

-- 
Linaro LKFT
https://lkft.linaro.org


[PATCH] CHROMIUM: arm64: dts: mt8183-elm: Set GPU power regulator to always on

2020-08-24 Thread Anand K Mistry
Keep the da9212 BUCKB always-on. This works around an issue on Elm/Hana
devices where sometimes, the regulator is disabled before scpsys is
suspended, causing the suspension of scpsys to fail.

Usually, the GPU and scpsys are suspended by the runtime PM before the
system is suspended, due to the GPU being idle. In this case, scpsys is
suspended inline with the GPU suspend, which then disables the
regulator. However, if the GPU is still active when system is suspended,
GPU suspend occurs but defers suspending scpsys to the PM's noirq phase.
Since GPU suspend disables the regulator, scpsys isn't powered and
suspending it fails with the following error:
[  523.773227] mtk-scpsys 10006000.scpsys: Failed to power off domain mfg_2d

On resume, scpsys is resumed in the noirq phase. Since scpsys requires
power from the regulator, which is still disabled at this point,
attempting to turn it on will hang the CPU. A HW watchdog eventually
reboots the system.

The obvious solution would be to add a link to the regulator from scpsys
in the devicetree. This would prevent the regulator from being disabled
until scpsys is suspended. However, in the case where suspending scpsys
is deferred to the noirq phase, disabling the regulator will fail since
it is connected over I2C which requires IRQs to be enabled. Even in the
usual case where scpsys is suspended inline with the GPU, PM will always
attempt to resume scpsys in noirq. This will attempt to enable the
regulator, which will also fail due to being unable to communicate over
I2C.

Since I2C can't be using with IRQs disabled, a workaround is to never
turn off the regulator.

Measuring power on the GPU rail on a Elm DVT shows that the change in
power usage is negligible. The two relavent cases are S0 with an idle
GPU, and S3.

In S0 with an idle GPU, current behaviour with the regulator off:
@@   NAME  COUNT  AVERAGE  STDDEV  MAXMIN
@@ gpu_mw600 1.741.31 6.75   0.00
... and with the regulator on, but no load:
@@   NAME  COUNT  AVERAGE  STDDEV MAXMIN
@@ gpu_mw600 1.681.257.13   0.00
The difference being well within the margin of error.

In S3, current behaviour with the regulator off:
@@   NAME  COUNT  AVERAGE  STDDEV MAXMIN
@@ gpu_mw600 0.940.743.25   0.00
... and with the regulator on:
@@   NAME  COUNT  AVERAGE  STDDEV MAX MIN
@@ gpu_mw600 0.830.663.250.00

Signed-off-by: Anand K Mistry 

---

 arch/arm64/boot/dts/mediatek/mt8173-elm.dtsi | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm64/boot/dts/mediatek/mt8173-elm.dtsi 
b/arch/arm64/boot/dts/mediatek/mt8173-elm.dtsi
index a5a12b2599a4..1294f27b21c1 100644
--- a/arch/arm64/boot/dts/mediatek/mt8173-elm.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt8173-elm.dtsi
@@ -304,6 +304,7 @@ da9211_vgpu_reg: BUCKB {
regulator-min-microamp  = <200>;
regulator-max-microamp  = <300>;
regulator-ramp-delay = <1>;
+   regulator-always-on;
};
};
};
-- 
2.28.0.297.g1956fa8f8d-goog



Re: [PATCH 2/2] mm/rmap: Fixup copying of soft dirty and uffd ptes

2020-08-24 Thread Alistair Popple
On Tuesday, 25 August 2020 1:43:59 AM AEST Peter Xu wrote:
> > --- a/mm/migrate.c
> > +++ b/mm/migrate.c
> > @@ -2427,9 +2427,11 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp,
> > 
> > entry = make_migration_entry(page, mpfn &
> > 
> >  MIGRATE_PFN_WRITE);
> > 
> > swp_pte = swp_entry_to_pte(entry);
> > 
> > -   if (pte_soft_dirty(pte))
> > +   if ((is_swap_pte(pte) && pte_swp_soft_dirty(pte))
> > +   || (!is_swap_pte(pte) && pte_soft_dirty(pte)))
> > 
> > swp_pte = pte_swp_mksoft_dirty(swp_pte);
> > 
> > -   if (pte_uffd_wp(pte))
> > +   if ((is_swap_pte(pte) && pte_swp_uffd_wp(pte))
> > +   || (!is_swap_pte(pte) && pte_uffd_wp(pte)))
> > 
> > swp_pte = pte_swp_mkuffd_wp(swp_pte);
> > 
> > set_pte_at(mm, addr, ptep, swp_pte);
> 
> The worst case is we'll call is_swap_pte() four times for each entry. Also
> considering we know it's not a pte_none() when reach here, how about:
> 
>   if (pte_present(pte)) {
> // pte handling of both soft dirty and uffd-wp
>   } else {
> // swap handling of both soft dirty and uffd-wp
>   }
> 
> ?

Works for me, I'd missed we knew it was not a pte_none() so will respin. 
Thanks!

 - Alistair
 
> Thanks,






Re: [PATCH v2 3/9] ASoC: audio-graph: Identify 'no_pcm' DAI links for DPCM

2020-08-24 Thread Sameer Pujar

Hi Morimoto-san,



(snip)

I tried testing this with LOCKDEP config enabled at my end.
It seems I don't see warning originated from above function.
Are you suggesting that, in general, snd_soc_find_dai()
should be called with client_mutex held?

Hmm ? strange...


Yes indeed. For saftely I will follow the same as other callers are doing.

...


Yes, I'm posting fixup patch.

 https://patchwork.kernel.org/patch/11719919/


Just curious that why snd_soc_find_dai() itself cannot be protected, 
instead of leaving this to callers.



Thanks,
Sameer.


Re: [PATCH 07/14 v1] usb: typec: tcpci_maxim: Chip level TCPC driver

2020-08-24 Thread Randy Dunlap
On 8/24/20 9:22 PM, Badhri Jagan Sridharan wrote:
> diff --git a/drivers/usb/typec/tcpm/Kconfig b/drivers/usb/typec/tcpm/Kconfig
> index fa3f39336246..7c9722b02afe 100644
> --- a/drivers/usb/typec/tcpm/Kconfig
> +++ b/drivers/usb/typec/tcpm/Kconfig
> @@ -27,6 +27,12 @@ config TYPEC_RT1711H
> Type-C Port Controller Manager to provide USB PD and USB
> Type-C functionalities.
>  
> +config TYPEC_TCPCI_MAXIM
> + tristate "Maxim TCPCI based Type-C chip driver"
> + select USB_PSY

is thatUSB_PHY
?

> + help
> +   MAXIM TCPCI based Type-C chip driver

end that with '.' please.

> +
>  endif # TYPEC_TCPCI
>  
>  config TYPEC_FUSB302


-- 
~Randy



Re: jii hllo

2020-08-24 Thread neetu pal
i dropped by to say Gm sir


Re: [PATCH for v5.9] mm/page_alloc: handle a missing case for memalloc_nocma_{save/restore} APIs

2020-08-24 Thread Andrew Morton
On Tue, 25 Aug 2020 13:59:42 +0900 js1...@gmail.com wrote:

> From: Joonsoo Kim 
> 
> memalloc_nocma_{save/restore} APIs can be used to skip page allocation
> on CMA area, but, there is a missing case and the page on CMA area could
> be allocated even if APIs are used. This patch handles this case to fix
> the potential issue.
> 
> Missing case is an allocation from the pcplist. MIGRATE_MOVABLE pcplist
> could have the pages on CMA area so we need to skip it if ALLOC_CMA isn't
> specified.
> 
> This patch implements this behaviour by checking allocated page from
> the pcplist rather than skipping an allocation from the pcplist entirely.
> Skipping the pcplist entirely would result in a mismatch between watermark
> check and actual page allocation. And, it requires to break current code
> layering that order-0 page is always handled by the pcplist. I'd prefer
> to avoid it so this patch uses different way to skip CMA page allocation
> from the pcplist.
> 
> ...
>
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -3341,6 +3341,22 @@ static struct page *rmqueue_pcplist(struct zone 
> *preferred_zone,
>   pcp = _cpu_ptr(zone->pageset)->pcp;
>   list = >lists[migratetype];
>   page = __rmqueue_pcplist(zone,  migratetype, alloc_flags, pcp, list);
> +#ifdef CONFIG_CMA
> + if (page) {
> + int mt = get_pcppage_migratetype(page);
> +
> + /*
> +  * pcp could have the pages on CMA area and we need to skip it
> +  * when !ALLOC_CMA. Free all pcplist and retry allocation.
> +  */
> + if (is_migrate_cma(mt) && !(alloc_flags & ALLOC_CMA)) {
> + list_add(>lru, >lists[migratetype]);
> + pcp->count++;
> + free_pcppages_bulk(zone, pcp->count, pcp);
> + page = __rmqueue_pcplist(zone, migratetype, 
> alloc_flags, pcp, list);
> + }
> + }
> +#endif
>   if (page) {
>   __count_zid_vm_events(PGALLOC, page_zonenum(page), 1);
>   zone_statistics(preferred_zone, zone);

That's a bunch more code on a very hot path to serve an obscure feature
which has a single obscure callsite.

Can we instead put the burden on that callsite rather than upon
everyone?  For (dumb) example, teach __gup_longterm_locked() to put the
page back if it's CMA and go get another one?




[PATCH] spi: spi-fsl-espi: Remove use of %p

2020-08-24 Thread Chris Packham
The register offset is already included in the device name so even prior
%p values being hashed printing the base was redundant. Remove the %p
from the dev_info() output.

Signed-off-by: Chris Packham 
---
 drivers/spi/spi-fsl-espi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/spi/spi-fsl-espi.c b/drivers/spi/spi-fsl-espi.c
index e60581283a24..7e9b6f8d6243 100644
--- a/drivers/spi/spi-fsl-espi.c
+++ b/drivers/spi/spi-fsl-espi.c
@@ -730,7 +730,7 @@ static int fsl_espi_probe(struct device *dev, struct 
resource *mem,
if (ret < 0)
goto err_pm;
 
-   dev_info(dev, "at 0x%p (irq = %u)\n", espi->reg_base, irq);
+   dev_info(dev, "irq = %u\n", irq);
 
pm_runtime_mark_last_busy(dev);
pm_runtime_put_autosuspend(dev);
-- 
2.28.0



[PATCH v11 2/2] Add PWM fan controller driver for LGM SoC

2020-08-24 Thread Rahul Tanwar
Intel Lightning Mountain(LGM) SoC contains a PWM fan controller.
This PWM controller does not have any other consumer, it is a
dedicated PWM controller for fan attached to the system. Add
driver for this PWM fan controller.

Signed-off-by: Rahul Tanwar 
---
 drivers/pwm/Kconfig |  11 ++
 drivers/pwm/Makefile|   1 +
 drivers/pwm/pwm-intel-lgm.c | 253 
 3 files changed, 265 insertions(+)
 create mode 100644 drivers/pwm/pwm-intel-lgm.c

diff --git a/drivers/pwm/Kconfig b/drivers/pwm/Kconfig
index 7dbcf6973d33..4949c51fe90b 100644
--- a/drivers/pwm/Kconfig
+++ b/drivers/pwm/Kconfig
@@ -232,6 +232,17 @@ config PWM_IMX_TPM
  To compile this driver as a module, choose M here: the module
  will be called pwm-imx-tpm.
 
+config PWM_INTEL_LGM
+   tristate "Intel LGM PWM support"
+   depends on HAS_IOMEM
+   depends on (OF && X86) || COMPILE_TEST
+   select REGMAP_MMIO
+   help
+ Generic PWM fan controller driver for LGM SoC.
+
+ To compile this driver as a module, choose M here: the module
+ will be called pwm-intel-lgm.
+
 config PWM_IQS620A
tristate "Azoteq IQS620A PWM support"
depends on MFD_IQS62X || COMPILE_TEST
diff --git a/drivers/pwm/Makefile b/drivers/pwm/Makefile
index 2c2ba0a03557..e9431b151694 100644
--- a/drivers/pwm/Makefile
+++ b/drivers/pwm/Makefile
@@ -20,6 +20,7 @@ obj-$(CONFIG_PWM_IMG) += pwm-img.o
 obj-$(CONFIG_PWM_IMX1) += pwm-imx1.o
 obj-$(CONFIG_PWM_IMX27)+= pwm-imx27.o
 obj-$(CONFIG_PWM_IMX_TPM)  += pwm-imx-tpm.o
+obj-$(CONFIG_PWM_INTEL_LGM)+= pwm-intel-lgm.o
 obj-$(CONFIG_PWM_IQS620A)  += pwm-iqs620a.o
 obj-$(CONFIG_PWM_JZ4740)   += pwm-jz4740.o
 obj-$(CONFIG_PWM_LP3943)   += pwm-lp3943.o
diff --git a/drivers/pwm/pwm-intel-lgm.c b/drivers/pwm/pwm-intel-lgm.c
new file mode 100644
index ..8e9f8cd3b7fb
--- /dev/null
+++ b/drivers/pwm/pwm-intel-lgm.c
@@ -0,0 +1,253 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 Intel Corporation.
+ *
+ * Limitations:
+ * - The hardware supports fixed period which is dependent on 2/3 or 4
+ *   wire fan mode.
+ * - Supports normal polarity. Does not support changing polarity.
+ * - When PWM is disabled, output of PWM will become 0(inactive). It doesn't
+ *   keep track of running period.
+ * - When duty cycle is changed, PWM output may be a mix of previous setting
+ *   and new setting for the first period. From second period, the output is
+ *   based on new setting.
+ * - It is a dedicated PWM fan controller. There are no other consumers for
+ *   this PWM controller.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define LGM_PWM_FAN_CON0   0x0
+#define LGM_PWM_FAN_EN_EN  BIT(0)
+#define LGM_PWM_FAN_EN_DIS 0x0
+#define LGM_PWM_FAN_EN_MSK BIT(0)
+#define LGM_PWM_FAN_MODE_2WIRE 0x0
+#define LGM_PWM_FAN_MODE_MSK   BIT(1)
+#define LGM_PWM_FAN_DC_MSK GENMASK(23, 16)
+
+#define LGM_PWM_FAN_CON1   0x4
+#define LGM_PWM_FAN_MAX_RPM_MSKGENMASK(15, 0)
+
+#define LGM_PWM_MAX_RPM(BIT(16) - 1)
+#define LGM_PWM_DEFAULT_RPM4000
+#define LGM_PWM_MAX_DUTY_CYCLE (BIT(8) - 1)
+
+#define LGM_PWM_DC_BITS8
+
+#define LGM_PWM_PERIOD_2WIRE_NS(40 * NSEC_PER_MSEC)
+
+struct lgm_pwm_chip {
+   struct pwm_chip chip;
+   struct regmap *regmap;
+   struct clk *clk;
+   struct reset_control *rst;
+   u32 period;
+};
+
+static inline struct lgm_pwm_chip *to_lgm_pwm_chip(struct pwm_chip *chip)
+{
+   return container_of(chip, struct lgm_pwm_chip, chip);
+}
+
+static int lgm_pwm_enable(struct pwm_chip *chip, bool enable)
+{
+   struct lgm_pwm_chip *pc = to_lgm_pwm_chip(chip);
+   struct regmap *regmap = pc->regmap;
+
+   return regmap_update_bits(regmap, LGM_PWM_FAN_CON0, LGM_PWM_FAN_EN_MSK,
+ enable ? LGM_PWM_FAN_EN_EN : 
LGM_PWM_FAN_EN_DIS);
+}
+
+static int lgm_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
+const struct pwm_state *state)
+{
+   struct lgm_pwm_chip *pc = to_lgm_pwm_chip(chip);
+   u32 duty_cycle, val;
+   int ret;
+
+   /*
+* The hardware only supports
+* normal polarity and fixed period.
+*/
+   if (state->polarity != PWM_POLARITY_NORMAL || state->period < 
pc->period)
+   return -EINVAL;
+
+   if (!state->enabled)
+   return lgm_pwm_enable(chip, 0);
+
+   duty_cycle = min_t(u64, state->duty_cycle, pc->period);
+   val = duty_cycle * LGM_PWM_MAX_DUTY_CYCLE / pc->period;
+
+   ret = regmap_update_bits(pc->regmap, LGM_PWM_FAN_CON0, 
LGM_PWM_FAN_DC_MSK,
+FIELD_PREP(LGM_PWM_FAN_DC_MSK, val));
+   if (ret)
+  

[PATCH v11 1/2] Add DT bindings YAML schema for PWM fan controller of LGM SoC

2020-08-24 Thread Rahul Tanwar
Intel's LGM(Lightning Mountain) SoC contains a PWM fan controller
which is only used to control the fan attached to the system. This
PWM controller does not have any other consumer other than fan.
Add DT bindings documentation for this PWM fan controller.

Signed-off-by: Rahul Tanwar 
---
 .../devicetree/bindings/pwm/intel,lgm-pwm.yaml | 44 ++
 1 file changed, 44 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pwm/intel,lgm-pwm.yaml

diff --git a/Documentation/devicetree/bindings/pwm/intel,lgm-pwm.yaml 
b/Documentation/devicetree/bindings/pwm/intel,lgm-pwm.yaml
new file mode 100644
index ..11a606536169
--- /dev/null
+++ b/Documentation/devicetree/bindings/pwm/intel,lgm-pwm.yaml
@@ -0,0 +1,44 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/pwm/intel,lgm-pwm.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: LGM SoC PWM fan controller
+
+maintainers:
+  - Rahul Tanwar 
+
+properties:
+  compatible:
+const: intel,lgm-pwm
+
+  reg:
+maxItems: 1
+
+  "#pwm-cells":
+const: 2
+
+  clocks:
+maxItems: 1
+
+  resets:
+maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - resets
+
+additionalProperties: false
+
+examples:
+  - |
+pwm: pwm@e0d0 {
+compatible = "intel,lgm-pwm";
+reg = <0xe0d0 0x30>;
+#pwm-cells = <2>;
+clocks = < 126>;
+resets = < 0x30 21>;
+};
-- 
2.11.0



[PATCH v11 0/2] pwm: intel: Add PWM driver for a new SoC

2020-08-24 Thread Rahul Tanwar
Patch 1 adds dt binding document in YAML format.
Patch 2 add PWM fan controller driver for LGM SoC.

v11:
- Address below review concerns (Andy Shevchenko)
  * Fix a issue with dev_err_probe() usage & improve the usage.
  * Fix & improve a ordering issue with clk_enable/disable &
reset_control assert/deassert.

v10:
- Removed unused of_device.h and added platform_device.h
  & mod_devicetable.h

v9:
- Address code quality related review concerns (Andy Shevchenko)
- Use devm_add_action_or_reset() instead of explicit unwind calls.

v8:
- Remove fan related optional properties usage, keep
  them as default. If needed, change pwm-fan driver
  separately in future to add them as generic properties.

v7:
- Address code quality related review concerns.
- Rename fan related property to pwm-*.
- Fix one make dt_binding_check reported error.

v6:
- Readjust .apply op as per review feedback.
- Add back pwm-cells property to resolve make dt_binding_check error.
  pwm-cells is a required property for PWM driver.
- Add back fan related optional properties.

v5:
- Address below review concerns from Uwe Kleine-K�nig.
  * Improve comments about Limitations.
  * Use return value of regmap_update_bits if container function returns
error code.
  * Modify .apply op to have strict checking for fixed period supported
by PWM HW.
  * Use u64 as type when use min_t for duty_cycle.
  * Add reset_control_assert() in failure case in probe where it was missing
earlier.
- Remove fan specific optional properties from pwm dt binding document (Rob 
Herring)

v4:
- Address below review concerns from Uwe Kleine-K�nig.
  * Improve notes and limitations comments.
  * Add common prefixes for all #defines.
  * Modify/Improve logic in .apply & .get_state ops as advised.
  * Skip error messages in probe when error is -EPROBE_DEFER.
  * Add dependencies in Kconfig (OF & HAS_IOMEM) and add select REGMAP_MMIO.
  * Address other code quality related review concerns.
- Fix make dt_binding_check reported error in YAML file.

v3:
- Address below review concerns from Uwe Kleine-K�nig.
  * Remove fan rpm calibration task from the driver.
  * Modify apply op as per the review feedback.
  * Add roundup & round down where necessary.
  * Address other misc code quality related review concerns.
  * Use devm_reset_control_get_exclusive(). (Philipp Zabel)
  * Improve dt binding document.

v2:
- Address below review concerns from Uwe Kleine-K�nig.
  * Add notes and limitations about PWM HW.
  * Rename all functions and structure to lgm_pwm_* 
  * Readjust space aligninment in structure fields to single space.
  * Switch to using apply instead of config/enable/disable.
  * Address other code quality related concerns.
  * Rebase to 5.8-rc1.
- Address review concerns in dt binding YAML from Rob Herring.

v1:
- Initial version.


Rahul Tanwar (2):
  Add DT bindings YAML schema for PWM fan controller of LGM SoC
  Add PWM fan controller driver for LGM SoC

 .../devicetree/bindings/pwm/intel,lgm-pwm.yaml |  44 
 drivers/pwm/Kconfig|  11 +
 drivers/pwm/Makefile   |   1 +
 drivers/pwm/pwm-intel-lgm.c| 253 +
 4 files changed, 309 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pwm/intel,lgm-pwm.yaml
 create mode 100644 drivers/pwm/pwm-intel-lgm.c

-- 
2.11.0



[PATCH for v5.9] mm/page_alloc: handle a missing case for memalloc_nocma_{save/restore} APIs

2020-08-24 Thread js1304
From: Joonsoo Kim 

memalloc_nocma_{save/restore} APIs can be used to skip page allocation
on CMA area, but, there is a missing case and the page on CMA area could
be allocated even if APIs are used. This patch handles this case to fix
the potential issue.

Missing case is an allocation from the pcplist. MIGRATE_MOVABLE pcplist
could have the pages on CMA area so we need to skip it if ALLOC_CMA isn't
specified.

This patch implements this behaviour by checking allocated page from
the pcplist rather than skipping an allocation from the pcplist entirely.
Skipping the pcplist entirely would result in a mismatch between watermark
check and actual page allocation. And, it requires to break current code
layering that order-0 page is always handled by the pcplist. I'd prefer
to avoid it so this patch uses different way to skip CMA page allocation
from the pcplist.

Fixes: 8510e69c8efe (mm/page_alloc: fix memalloc_nocma_{save/restore} APIs)
Signed-off-by: Joonsoo Kim 
---
 mm/page_alloc.c | 16 
 1 file changed, 16 insertions(+)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 0e2bab4..c4abf58 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -3341,6 +3341,22 @@ static struct page *rmqueue_pcplist(struct zone 
*preferred_zone,
pcp = _cpu_ptr(zone->pageset)->pcp;
list = >lists[migratetype];
page = __rmqueue_pcplist(zone,  migratetype, alloc_flags, pcp, list);
+#ifdef CONFIG_CMA
+   if (page) {
+   int mt = get_pcppage_migratetype(page);
+
+   /*
+* pcp could have the pages on CMA area and we need to skip it
+* when !ALLOC_CMA. Free all pcplist and retry allocation.
+*/
+   if (is_migrate_cma(mt) && !(alloc_flags & ALLOC_CMA)) {
+   list_add(>lru, >lists[migratetype]);
+   pcp->count++;
+   free_pcppages_bulk(zone, pcp->count, pcp);
+   page = __rmqueue_pcplist(zone, migratetype, 
alloc_flags, pcp, list);
+   }
+   }
+#endif
if (page) {
__count_zid_vm_events(PGALLOC, page_zonenum(page), 1);
zone_statistics(preferred_zone, zone);
-- 
2.7.4



[PATCH 06/29] drbd: Avoid comma separated statements

2020-08-24 Thread Joe Perches
Use semicolons and braces.

Signed-off-by: Joe Perches 
---
 drivers/block/drbd/drbd_receiver.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/block/drbd/drbd_receiver.c 
b/drivers/block/drbd/drbd_receiver.c
index 422363daa618..87f732fb5456 100644
--- a/drivers/block/drbd/drbd_receiver.c
+++ b/drivers/block/drbd/drbd_receiver.c
@@ -111,8 +111,10 @@ static struct page *page_chain_tail(struct page *page, int 
*len)
 {
struct page *tmp;
int i = 1;
-   while ((tmp = page_chain_next(page)))
-   ++i, page = tmp;
+   while ((tmp = page_chain_next(page))) {
+   ++i;
+   page = tmp;
+   }
if (len)
*len = i;
return page;
-- 
2.26.0



[PATCH 13/29] bcache: Avoid comma separated statements

2020-08-24 Thread Joe Perches
Use semicolons and braces.

Signed-off-by: Joe Perches 
---
 drivers/md/bcache/bset.c  | 12 
 drivers/md/bcache/sysfs.c |  6 --
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/drivers/md/bcache/bset.c b/drivers/md/bcache/bset.c
index 67a2c47f4201..94d38e8a59b3 100644
--- a/drivers/md/bcache/bset.c
+++ b/drivers/md/bcache/bset.c
@@ -712,8 +712,10 @@ void bch_bset_build_written_tree(struct btree_keys *b)
for (j = inorder_next(0, t->size);
 j;
 j = inorder_next(j, t->size)) {
-   while (bkey_to_cacheline(t, k) < cacheline)
-   prev = k, k = bkey_next(k);
+   while (bkey_to_cacheline(t, k) < cacheline) {
+   prev = k;
+   k = bkey_next(k);
+   }
 
t->prev[j] = bkey_u64s(prev);
t->tree[j].m = bkey_to_cacheline_offset(t, cacheline++, k);
@@ -901,8 +903,10 @@ unsigned int bch_btree_insert_key(struct btree_keys *b, 
struct bkey *k,
status = BTREE_INSERT_STATUS_INSERT;
 
while (m != bset_bkey_last(i) &&
-  bkey_cmp(k, b->ops->is_extents ? _KEY(m) : m) > 0)
-   prev = m, m = bkey_next(m);
+  bkey_cmp(k, b->ops->is_extents ? _KEY(m) : m) > 0) {
+   prev = m;
+   m = bkey_next(m);
+   }
 
/* prev is in the tree, if we merge we're done */
status = BTREE_INSERT_STATUS_BACK_MERGE;
diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c
index ac06c0bc3c0a..1878c5ee53b6 100644
--- a/drivers/md/bcache/sysfs.c
+++ b/drivers/md/bcache/sysfs.c
@@ -1071,8 +1071,10 @@ SHOW(__bch_cache)
--n;
 
while (cached < p + n &&
-  *cached == BTREE_PRIO)
-   cached++, n--;
+  *cached == BTREE_PRIO) {
+   cached++;
+   n--;
+   }
 
for (i = 0; i < n; i++)
sum += INITIAL_PRIO - cached[i];
-- 
2.26.0



[PATCH 04/29] sparc: Avoid comma separated statements

2020-08-24 Thread Joe Perches
Use semicolons and braces.

Signed-off-by: Joe Perches 
---
 arch/sparc/kernel/smp_64.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
index e286e2badc8a..28c11f7871cd 100644
--- a/arch/sparc/kernel/smp_64.c
+++ b/arch/sparc/kernel/smp_64.c
@@ -186,8 +186,11 @@ static inline long get_delta (long *rt, long *master)
wmb();
t1 = tick_ops->get_tick();
 
-   if (t1 - t0 < best_t1 - best_t0)
-   best_t0 = t0, best_t1 = t1, best_tm = tm;
+   if (t1 - t0 < best_t1 - best_t0) {
+   best_t0 = t0;
+   best_t1 = t1;
+   best_tm = tm;
+   }
}
 
*rt = best_t1 - best_t0;
-- 
2.26.0



[PATCH 09/29] drm/gma500: Avoid comma separated statements

2020-08-24 Thread Joe Perches
Use semicolons and braces.

Signed-off-by: Joe Perches 
---
 drivers/gpu/drm/gma500/mdfld_intel_display.c | 44 +---
 1 file changed, 28 insertions(+), 16 deletions(-)

diff --git a/drivers/gpu/drm/gma500/mdfld_intel_display.c 
b/drivers/gpu/drm/gma500/mdfld_intel_display.c
index aae2d358364c..bfa330df9443 100644
--- a/drivers/gpu/drm/gma500/mdfld_intel_display.c
+++ b/drivers/gpu/drm/gma500/mdfld_intel_display.c
@@ -824,33 +824,45 @@ static int mdfld_crtc_mode_set(struct drm_crtc *crtc,
if ((ksel == KSEL_CRYSTAL_19) || (ksel == KSEL_BYPASS_19)) {
refclk = 19200;
 
-   if (is_mipi || is_mipi2)
-   clk_n = 1, clk_p2 = 8;
-   else if (is_hdmi)
-   clk_n = 1, clk_p2 = 10;
+   if (is_mipi || is_mipi2) {
+   clk_n = 1;
+   clk_p2 = 8;
+   } else if (is_hdmi) {
+   clk_n = 1;
+   clk_p2 = 10;
+   }
} else if (ksel == KSEL_BYPASS_25) {
refclk = 25000;
 
-   if (is_mipi || is_mipi2)
-   clk_n = 1, clk_p2 = 8;
-   else if (is_hdmi)
-   clk_n = 1, clk_p2 = 10;
+   if (is_mipi || is_mipi2) {
+   clk_n = 1;
+   clk_p2 = 8;
+   } else if (is_hdmi) {
+   clk_n = 1;
+   clk_p2 = 10;
+   }
} else if ((ksel == KSEL_BYPASS_83_100) &&
dev_priv->core_freq == 166) {
refclk = 83000;
 
-   if (is_mipi || is_mipi2)
-   clk_n = 4, clk_p2 = 8;
-   else if (is_hdmi)
-   clk_n = 4, clk_p2 = 10;
+   if (is_mipi || is_mipi2) {
+   clk_n = 4;
+   clk_p2 = 8;
+   } else if (is_hdmi) {
+   clk_n = 4;
+   clk_p2 = 10;
+   }
} else if ((ksel == KSEL_BYPASS_83_100) &&
(dev_priv->core_freq == 100 ||
dev_priv->core_freq == 200)) {
refclk = 10;
-   if (is_mipi || is_mipi2)
-   clk_n = 4, clk_p2 = 8;
-   else if (is_hdmi)
-   clk_n = 4, clk_p2 = 10;
+   if (is_mipi || is_mipi2) {
+   clk_n = 4;
+   clk_p2 = 8;
+   } else if (is_hdmi) {
+   clk_n = 4;
+   clk_p2 = 10;
+   }
}
 
if (is_mipi)
-- 
2.26.0



[PATCH 05/29] ata: Avoid comma separated statements

2020-08-24 Thread Joe Perches
Use semicolons and braces.

Signed-off-by: Joe Perches 
---
 drivers/ata/pata_icside.c | 21 +
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/drivers/ata/pata_icside.c b/drivers/ata/pata_icside.c
index 08543aeb0093..498383cb6e29 100644
--- a/drivers/ata/pata_icside.c
+++ b/drivers/ata/pata_icside.c
@@ -202,14 +202,19 @@ static void pata_icside_set_dmamode(struct ata_port *ap, 
struct ata_device *adev
 * Choose the IOMD cycle timing which ensure that the interface
 * satisfies the measured active, recovery and cycle times.
 */
-   if (t.active <= 50 && t.recover <= 375 && t.cycle <= 425)
-   iomd_type = 'D', cycle = 187;
-   else if (t.active <= 125 && t.recover <= 375 && t.cycle <= 500)
-   iomd_type = 'C', cycle = 250;
-   else if (t.active <= 200 && t.recover <= 550 && t.cycle <= 750)
-   iomd_type = 'B', cycle = 437;
-   else
-   iomd_type = 'A', cycle = 562;
+   if (t.active <= 50 && t.recover <= 375 && t.cycle <= 425) {
+   iomd_type = 'D';
+   cycle = 187;
+   } else if (t.active <= 125 && t.recover <= 375 && t.cycle <= 500) {
+   iomd_type = 'C';
+   cycle = 250;
+   } else if (t.active <= 200 && t.recover <= 550 && t.cycle <= 750) {
+   iomd_type = 'B';
+   cycle = 437;
+   } else {
+   iomd_type = 'A';
+   cycle = 562;
+   }
 
ata_dev_info(adev, "timings: act %dns rec %dns cyc %dns (%c)\n",
 t.active, t.recover, t.cycle, iomd_type);
-- 
2.26.0



[PATCH 08/29] dma-buf: Avoid comma separated statements

2020-08-24 Thread Joe Perches
Use semicolons and braces.

Signed-off-by: Joe Perches 
---
 drivers/dma-buf/st-dma-fence.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/dma-buf/st-dma-fence.c b/drivers/dma-buf/st-dma-fence.c
index e593064341c8..c8a12d7ad71a 100644
--- a/drivers/dma-buf/st-dma-fence.c
+++ b/drivers/dma-buf/st-dma-fence.c
@@ -471,8 +471,11 @@ static int thread_signal_callback(void *arg)
dma_fence_signal(f1);
 
smp_store_mb(cb.seen, false);
-   if (!f2 || dma_fence_add_callback(f2, , simple_callback))
-   miss++, cb.seen = true;
+   if (!f2 ||
+   dma_fence_add_callback(f2, , simple_callback)) {
+   miss++;
+   cb.seen = true;
+   }
 
if (!t->before)
dma_fence_signal(f1);
-- 
2.26.0



[PATCH 10/29] drm/i915: Avoid comma separated statements

2020-08-24 Thread Joe Perches
Use semicolons and braces.

Signed-off-by: Joe Perches 
---
 drivers/gpu/drm/i915/gt/gen8_ppgtt.c   | 8 +---
 drivers/gpu/drm/i915/gt/intel_gt_requests.c| 6 --
 drivers/gpu/drm/i915/gt/selftest_workarounds.c | 6 --
 drivers/gpu/drm/i915/intel_runtime_pm.c| 6 --
 4 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/i915/gt/gen8_ppgtt.c 
b/drivers/gpu/drm/i915/gt/gen8_ppgtt.c
index 699125928272..114c13285ff1 100644
--- a/drivers/gpu/drm/i915/gt/gen8_ppgtt.c
+++ b/drivers/gpu/drm/i915/gt/gen8_ppgtt.c
@@ -323,10 +323,12 @@ static int __gen8_ppgtt_alloc(struct i915_address_space * 
const vm,
}
 
spin_lock(>lock);
-   if (likely(!pd->entry[idx]))
+   if (likely(!pd->entry[idx])) {
set_pd_entry(pd, idx, pt);
-   else
-   alloc = pt, pt = pd->entry[idx];
+   } else {
+   alloc = pt;
+   pt = pd->entry[idx];
+   }
}
 
if (lvl) {
diff --git a/drivers/gpu/drm/i915/gt/intel_gt_requests.c 
b/drivers/gpu/drm/i915/gt/intel_gt_requests.c
index 66fcbf9d0fdd..54408d0b5e6e 100644
--- a/drivers/gpu/drm/i915/gt/intel_gt_requests.c
+++ b/drivers/gpu/drm/i915/gt/intel_gt_requests.c
@@ -139,8 +139,10 @@ long intel_gt_retire_requests_timeout(struct intel_gt *gt, 
long timeout)
LIST_HEAD(free);
 
interruptible = true;
-   if (unlikely(timeout < 0))
-   timeout = -timeout, interruptible = false;
+   if (unlikely(timeout < 0)) {
+   timeout = -timeout;
+   interruptible = false;
+   }
 
flush_submission(gt, timeout); /* kick the ksoftirqd tasklets */
spin_lock(>lock);
diff --git a/drivers/gpu/drm/i915/gt/selftest_workarounds.c 
b/drivers/gpu/drm/i915/gt/selftest_workarounds.c
index febc9e6692ba..3e4cbeed20bd 100644
--- a/drivers/gpu/drm/i915/gt/selftest_workarounds.c
+++ b/drivers/gpu/drm/i915/gt/selftest_workarounds.c
@@ -521,8 +521,10 @@ static int check_dirty_whitelist(struct intel_context *ce)
 
srm = MI_STORE_REGISTER_MEM;
lrm = MI_LOAD_REGISTER_MEM;
-   if (INTEL_GEN(engine->i915) >= 8)
-   lrm++, srm++;
+   if (INTEL_GEN(engine->i915) >= 8) {
+   lrm++;
+   srm++;
+   }
 
pr_debug("%s: Writing garbage to %x\n",
 engine->name, reg);
diff --git a/drivers/gpu/drm/i915/intel_runtime_pm.c 
b/drivers/gpu/drm/i915/intel_runtime_pm.c
index 153ca9e65382..f498f1c80755 100644
--- a/drivers/gpu/drm/i915/intel_runtime_pm.c
+++ b/drivers/gpu/drm/i915/intel_runtime_pm.c
@@ -201,8 +201,10 @@ __print_intel_runtime_pm_wakeref(struct drm_printer *p,
unsigned long rep;
 
rep = 1;
-   while (i + 1 < dbg->count && dbg->owners[i + 1] == stack)
-   rep++, i++;
+   while (i + 1 < dbg->count && dbg->owners[i + 1] == stack) {
+   rep++;
+   i++;
+   }
__print_depot_stack(stack, buf, PAGE_SIZE, 2);
drm_printf(p, "Wakeref x%lu taken at:\n%s", rep, buf);
}
-- 
2.26.0



[PATCH 28/29] sunrpc: Avoid comma separated statements

2020-08-24 Thread Joe Perches
Use semicolons and braces.

Signed-off-by: Joe Perches 
---
 net/sunrpc/sysctl.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/net/sunrpc/sysctl.c b/net/sunrpc/sysctl.c
index 999eee1ed61c..6c86e2a7d942 100644
--- a/net/sunrpc/sysctl.c
+++ b/net/sunrpc/sysctl.c
@@ -108,8 +108,10 @@ proc_dodebug(struct ctl_table *table, int write, void 
*buffer, size_t *lenp,
left -= (s - tmpbuf);
if (left && !isspace(*s))
return -EINVAL;
-   while (left && isspace(*s))
-   left--, s++;
+   while (left && isspace(*s)) {
+   left--;
+   s++;
+   }
} else
left = 0;
*(unsigned int *) table->data = value;
-- 
2.26.0



[PATCH 14/29] media: Avoid comma separated statements

2020-08-24 Thread Joe Perches
Use semicolons and braces.

Signed-off-by: Joe Perches 
---
 drivers/media/i2c/msp3400-kthreads.c  | 12 
 drivers/media/pci/bt8xx/bttv-cards.c  |  6 --
 drivers/media/pci/saa7134/saa7134-video.c |  7 +--
 3 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/drivers/media/i2c/msp3400-kthreads.c 
b/drivers/media/i2c/msp3400-kthreads.c
index d3b0d1c18efd..ac8752c63266 100644
--- a/drivers/media/i2c/msp3400-kthreads.c
+++ b/drivers/media/i2c/msp3400-kthreads.c
@@ -549,8 +549,10 @@ int msp3400c_thread(void *data)
val = msp_read_dsp(client, 0x1b);
if (val > 32767)
val -= 65536;
-   if (val1 < val)
-   val1 = val, max1 = i;
+   if (val1 < val) {
+   val1 = val;
+   max1 = i;
+   }
dev_dbg_lvl(>dev, 1, msp_debug,
"carrier1 val: %5d / %s\n", val, cd[i].name);
}
@@ -586,8 +588,10 @@ int msp3400c_thread(void *data)
val = msp_read_dsp(client, 0x1b);
if (val > 32767)
val -= 65536;
-   if (val2 < val)
-   val2 = val, max2 = i;
+   if (val2 < val) {
+   val2 = val;
+   max2 = i;
+   }
dev_dbg_lvl(>dev, 1, msp_debug,
"carrier2 val: %5d / %s\n", val, cd[i].name);
}
diff --git a/drivers/media/pci/bt8xx/bttv-cards.c 
b/drivers/media/pci/bt8xx/bttv-cards.c
index 16148802dabb..ca20b806e82d 100644
--- a/drivers/media/pci/bt8xx/bttv-cards.c
+++ b/drivers/media/pci/bt8xx/bttv-cards.c
@@ -3934,8 +3934,10 @@ static void osprey_eeprom(struct bttv *btv, const u8 
ee[256])
if (checksum != ee[21])
return;
cardid = BTTV_BOARD_OSPREY1x0_848;
-   for (i = 12; i < 21; i++)
-   serial *= 10, serial += ee[i] - '0';
+   for (i = 12; i < 21; i++) {
+   serial *= 10;
+   serial += ee[i] - '0';
+   }
}
} else {
unsigned short type;
diff --git a/drivers/media/pci/saa7134/saa7134-video.c 
b/drivers/media/pci/saa7134/saa7134-video.c
index a8ac94fadc14..f673cda57f30 100644
--- a/drivers/media/pci/saa7134/saa7134-video.c
+++ b/drivers/media/pci/saa7134/saa7134-video.c
@@ -868,8 +868,11 @@ static int buffer_activate(struct saa7134_dev *dev,
lines_uv = dev->height >> dev->fmt->vshift;
base2= base + bpl * dev->height;
base3= base2 + bpl_uv * lines_uv;
-   if (dev->fmt->uvswap)
-   tmp = base2, base2 = base3, base3 = tmp;
+   if (dev->fmt->uvswap) {
+   tmp = base2;
+   base2 = base3;
+   base3 = tmp;
+   }
video_dbg("uv: bpl=%ld lines=%ld base2/3=%ld/%ld\n",
bpl_uv,lines_uv,base2,base3);
if (V4L2_FIELD_HAS_BOTH(dev->field)) {
-- 
2.26.0



[PATCH 16/29] 8390: Avoid comma separated statements

2020-08-24 Thread Joe Perches
Use semicolons and braces.

Signed-off-by: Joe Perches 
---
 drivers/net/ethernet/8390/axnet_cs.c | 19 ---
 drivers/net/ethernet/8390/lib8390.c  | 14 +-
 drivers/net/ethernet/8390/pcnet_cs.c |  6 --
 3 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/drivers/net/ethernet/8390/axnet_cs.c 
b/drivers/net/ethernet/8390/axnet_cs.c
index a00b36f91d9f..d041b6dda012 100644
--- a/drivers/net/ethernet/8390/axnet_cs.c
+++ b/drivers/net/ethernet/8390/axnet_cs.c
@@ -657,8 +657,10 @@ static void block_input(struct net_device *dev, int count,
 outb_p(E8390_RREAD+E8390_START, nic_base + AXNET_CMD);
 
 insw(nic_base + AXNET_DATAPORT,buf,count>>1);
-if (count & 0x01)
-   buf[count-1] = inb(nic_base + AXNET_DATAPORT), xfer_count++;
+if (count & 0x01) {
+   buf[count-1] = inb(nic_base + AXNET_DATAPORT);
+   xfer_count++;
+}
 
 }
 
@@ -1270,10 +1272,12 @@ static void ei_tx_intr(struct net_device *dev)
ei_local->txing = 1;
NS8390_trigger_send(dev, ei_local->tx2, 
ei_local->tx_start_page + 6);
netif_trans_update(dev);
-   ei_local->tx2 = -1,
+   ei_local->tx2 = -1;
ei_local->lasttx = 2;
-   }
-   else ei_local->lasttx = 20, ei_local->txing = 0;
+   } else {
+   ei_local->lasttx = 20;
+   ei_local->txing = 0;
+   }   
}
else if (ei_local->tx2 < 0) 
{
@@ -1289,9 +1293,10 @@ static void ei_tx_intr(struct net_device *dev)
netif_trans_update(dev);
ei_local->tx1 = -1;
ei_local->lasttx = 1;
+   } else {
+   ei_local->lasttx = 10;
+   ei_local->txing = 0;
}
-   else
-   ei_local->lasttx = 10, ei_local->txing = 0;
}
 // else
 // netdev_warn(dev, "unexpected TX-done interrupt, lasttx=%d\n",
diff --git a/drivers/net/ethernet/8390/lib8390.c 
b/drivers/net/ethernet/8390/lib8390.c
index babc92e2692e..1f48d7f6365c 100644
--- a/drivers/net/ethernet/8390/lib8390.c
+++ b/drivers/net/ethernet/8390/lib8390.c
@@ -597,10 +597,12 @@ static void ei_tx_intr(struct net_device *dev)
ei_local->txing = 1;
NS8390_trigger_send(dev, ei_local->tx2, 
ei_local->tx_start_page + 6);
netif_trans_update(dev);
-   ei_local->tx2 = -1,
+   ei_local->tx2 = -1;
ei_local->lasttx = 2;
-   } else
-   ei_local->lasttx = 20, ei_local->txing = 0;
+   } else {
+   ei_local->lasttx = 20;
+   ei_local->txing = 0;
+   }
} else if (ei_local->tx2 < 0) {
if (ei_local->lasttx != 2  &&  ei_local->lasttx != -2)
pr_err("%s: bogus last_tx_buffer %d, tx2=%d\n",
@@ -612,8 +614,10 @@ static void ei_tx_intr(struct net_device *dev)
netif_trans_update(dev);
ei_local->tx1 = -1;
ei_local->lasttx = 1;
-   } else
-   ei_local->lasttx = 10, ei_local->txing = 0;
+   } else {
+   ei_local->lasttx = 10;
+   ei_local->txing = 0;
+   }
} /* else
netdev_warn(dev, "unexpected TX-done interrupt, lasttx=%d\n",
ei_local->lasttx);
diff --git a/drivers/net/ethernet/8390/pcnet_cs.c 
b/drivers/net/ethernet/8390/pcnet_cs.c
index 164c3ed550bf..9d3b1e0e425c 100644
--- a/drivers/net/ethernet/8390/pcnet_cs.c
+++ b/drivers/net/ethernet/8390/pcnet_cs.c
@@ -1178,8 +1178,10 @@ static void dma_block_input(struct net_device *dev, int 
count,
 outb_p(E8390_RREAD+E8390_START, nic_base + PCNET_CMD);
 
 insw(nic_base + PCNET_DATAPORT,buf,count>>1);
-if (count & 0x01)
-   buf[count-1] = inb(nic_base + PCNET_DATAPORT), xfer_count++;
+if (count & 0x01) {
+   buf[count-1] = inb(nic_base + PCNET_DATAPORT);
+   xfer_count++;
+}
 
 /* This was for the ALPHA version only, but enough people have been
encountering problems that it is still here. */
-- 
2.26.0



[PATCH 19/29] s390/tty3270: Avoid comma separated statements

2020-08-24 Thread Joe Perches
Use semicolons and braces.

Signed-off-by: Joe Perches 
---
 drivers/s390/char/tty3270.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/s390/char/tty3270.c b/drivers/s390/char/tty3270.c
index aec996de44d9..6acce975df26 100644
--- a/drivers/s390/char/tty3270.c
+++ b/drivers/s390/char/tty3270.c
@@ -424,8 +424,10 @@ tty3270_update(struct timer_list *t)
 * last output position matches the start address
 * of this line.
 */
-   if (s->string[1] == sba[0] && s->string[2] == sba[1])
-   str += 3, len -= 3;
+   if (s->string[1] == sba[0] && s->string[2] == sba[1]) {
+   str += 3;
+   len -= 3;
+   }
if (raw3270_request_add_data(wrq, str, len) != 0)
break;
list_del_init(>update);
-- 
2.26.0



[PATCH 21/29] media: atomisp: Avoid comma separated statements

2020-08-24 Thread Joe Perches
Use semicolons and braces.

Signed-off-by: Joe Perches 
---
 drivers/staging/media/atomisp/pci/atomisp_subdev.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/media/atomisp/pci/atomisp_subdev.c 
b/drivers/staging/media/atomisp/pci/atomisp_subdev.c
index 6ba817f15655..52b9fb18c87f 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_subdev.c
+++ b/drivers/staging/media/atomisp/pci/atomisp_subdev.c
@@ -410,8 +410,10 @@ int atomisp_subdev_set_selection(struct v4l2_subdev *sd,
 
if (atomisp_subdev_format_conversion(isp_sd,
 isp_sd->capture_pad)
-   && crop[pad]->width && crop[pad]->height)
-   crop[pad]->width -= padding_w, crop[pad]->height -= 
padding_h;
+   && crop[pad]->width && crop[pad]->height) {
+   crop[pad]->width -= padding_w;
+   crop[pad]->height -= padding_h;
+   }
 
/* if subdev type is SOC camera,we do not need to set DVS */
if (isp->inputs[isp_sd->input_curr].type == SOC_CAMERA)
-- 
2.26.0



[PATCH 15/29] mtd: Avoid comma separated statements

2020-08-24 Thread Joe Perches
Use semicolons and braces.

Signed-off-by: Joe Perches 
---
 drivers/mtd/devices/lart.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/devices/lart.c b/drivers/mtd/devices/lart.c
index 56f50d27b7fd..aecd441e4183 100644
--- a/drivers/mtd/devices/lart.c
+++ b/drivers/mtd/devices/lart.c
@@ -436,7 +436,10 @@ static int flash_read (struct mtd_info *mtd,loff_t 
from,size_t len,size_t *retle
 {
int gap = BUSWIDTH - (from & (BUSWIDTH - 1));
 
-   while (len && gap--) *buf++ = read8 (from++), len--;
+   while (len && gap--) {
+   *buf++ = read8 (from++);
+   len--;
+   }
 }
 
/* now we read dwords until we reach a non-dword boundary */
@@ -518,7 +521,10 @@ static int flash_write (struct mtd_info *mtd,loff_t 
to,size_t len,size_t *retlen
i = n = 0;
 
while (gap--) tmp[i++] = 0xFF;
-   while (len && i < BUSWIDTH) tmp[i++] = buf[n++], len--;
+   while (len && i < BUSWIDTH) {
+   tmp[i++] = buf[n++];
+   len--;
+   }
while (i < BUSWIDTH) tmp[i++] = 0xFF;
 
if (!write_dword (aligned,*((__u32 *) tmp))) return (-EIO);
-- 
2.26.0



RE: [PATCH] dt-bindings: mmc: Add missing description for clk_in/out_sd1

2020-08-24 Thread Manish Narani



> -Original Message-
> From: Michal Simek  On Behalf Of Michal Simek
> Sent: Monday, August 24, 2020 1:55 PM
> To: linux-kernel@vger.kernel.org; mon...@monstr.eu; Michal Simek
> ; git ; Manish Narani
> 
> Cc: Adrian Hunter ; Rob Herring
> ; Ulf Hansson ; Wan Ahmad
> Zainie ;
> devicet...@vger.kernel.org; linux-...@vger.kernel.org
> Subject: [PATCH] dt-bindings: mmc: Add missing description for clk_in/out_sd1
> 
> The commit a8fdb80f4d47 ("arm64: zynqmp: Add ZynqMP SDHCI compatible
> string") added clock-output-names for both SDHCIs before DT binding yaml
> conversion. But only clk_in/out_sd0 clock names have been covered by
> DT binding which ends up with dt yaml checking warnings as:
> From schema: .../Documentation/devicetree/bindings/mmc/arasan,sdhci.yaml
> ... mmc@ff17: clock-output-names:0: 'clk_out_sd0' was expected
> ... mmc@ff17: clock-output-names:1: 'clk_in_sd0' was expected
> 
> Fixes: 16ecd8f33c6e ("dt-bindings: mmc: convert arasan sdhci bindings to 
> yaml")
> Signed-off-by: Michal Simek 

Reviewed-by: Manish Narani 




[PATCH 18/29] wan: sbni: Avoid comma separated statements

2020-08-24 Thread Joe Perches
Use semicolons and braces.

Signed-off-by: Joe Perches 
---
 drivers/net/wan/sbni.c | 101 +++--
 1 file changed, 58 insertions(+), 43 deletions(-)

diff --git a/drivers/net/wan/sbni.c b/drivers/net/wan/sbni.c
index 40c04ea1200a..2fde439543fb 100644
--- a/drivers/net/wan/sbni.c
+++ b/drivers/net/wan/sbni.c
@@ -260,11 +260,12 @@ static int __init sbni_init(struct net_device *dev)
return  sbni_isa_probe( dev );
/* otherwise we have to perform search our adapter */
 
-   if( io[ num ] != -1 )
-   dev->base_addr  = io[ num ],
+   if( io[ num ] != -1 ) {
+   dev->base_addr  = io[ num ];
dev->irq= irq[ num ];
-   else if( scandone  ||  io[ 0 ] != -1 )
+   } else if( scandone  ||  io[ 0 ] != -1 ) {
return  -ENODEV;
+   }
 
/* if io[ num ] contains non-zero address, then that is on ISA bus */
if( dev->base_addr )
@@ -399,12 +400,13 @@ sbni_probe1( struct net_device  *dev,  unsigned long  
ioaddr,  int  irq )
nl->maxframe  = DEFAULT_FRAME_LEN;
nl->csr1.rate = baud[ num ];
 
-   if( (nl->cur_rxl_index = rxl[ num ]) == -1 )
+   if( (nl->cur_rxl_index = rxl[ num ]) == -1 ) {
/* autotune rxl */
-   nl->cur_rxl_index = DEF_RXL,
+   nl->cur_rxl_index = DEF_RXL;
nl->delta_rxl = DEF_RXL_DELTA;
-   else
+   } else {
nl->delta_rxl = 0;
+   }
nl->csr1.rxl  = rxl_tab[ nl->cur_rxl_index ];
if( inb( ioaddr + CSR0 ) & 0x01 )
nl->state |= FL_SLOW_MODE;
@@ -512,13 +514,15 @@ sbni_interrupt( int  irq,  void  *dev_id )
 
do {
repeat = 0;
-   if( inb( dev->base_addr + CSR0 ) & (RC_RDY | TR_RDY) )
-   handle_channel( dev ),
+   if( inb( dev->base_addr + CSR0 ) & (RC_RDY | TR_RDY) ) {
+   handle_channel( dev );
repeat = 1;
+   }
if( nl->second  &&  /* second channel present */
-   (inb( nl->second->base_addr+CSR0 ) & (RC_RDY | TR_RDY)) )
-   handle_channel( nl->second ),
+   (inb( nl->second->base_addr+CSR0 ) & (RC_RDY | TR_RDY)) ) {
+   handle_channel( nl->second );
repeat = 1;
+   }
} while( repeat );
 
if( nl->second )
@@ -610,11 +614,12 @@ recv_frame( struct net_device  *dev )
nl->state |= FL_PREV_OK;
if( framelen > 4 )
nl->in_stats.all_rx_number++;
-   } else
-   nl->state &= ~FL_PREV_OK,
-   change_level( dev ),
-   nl->in_stats.all_rx_number++,
+   } else {
+   nl->state &= ~FL_PREV_OK;
+   change_level( dev );
+   nl->in_stats.all_rx_number++;
nl->in_stats.bad_rx_number++;
+   }
 
return  !frame_ok  ||  framelen > 4;
 }
@@ -689,9 +694,10 @@ download_data( struct net_device  *dev,  u32  *crc_p )
*crc_p = calc_crc32( *crc_p, skb->data + nl->outpos, len );
 
/* if packet too short we should write some more bytes to pad */
-   for( len = nl->framelen - len;  len--; )
-   outb( 0, dev->base_addr + DAT ),
+   for( len = nl->framelen - len;  len--; ) {
+   outb( 0, dev->base_addr + DAT );
*crc_p = CRC32( 0, *crc_p );
+   }
 }
 
 
@@ -703,9 +709,10 @@ upload_data( struct net_device  *dev,  unsigned  framelen, 
 unsigned  frameno,
 
int  frame_ok;
 
-   if( is_first )
-   nl->wait_frameno = frameno,
+   if( is_first ) {
+   nl->wait_frameno = frameno;
nl->inppos = 0;
+   }
 
if( nl->wait_frameno == frameno ) {
 
@@ -717,33 +724,35 @@ upload_data( struct net_device  *dev,  unsigned  
framelen,  unsigned  frameno,
 * error was occurred... drop entire packet
 */
else if( (frame_ok = skip_tail( dev->base_addr, framelen, crc ))
-!= 0 )
-   nl->wait_frameno = 0,
-   nl->inppos = 0,
+!= 0 ) {
+   nl->wait_frameno = 0;
+   nl->inppos = 0;
 #ifdef CONFIG_SBNI_MULTILINE
-   nl->master->stats.rx_errors++,
+   nl->master->stats.rx_errors++;
nl->master->stats.rx_missed_errors++;
 #else
-   dev->stats.rx_errors++,
+   dev->stats.rx_errors++;
dev->stats.rx_missed_errors++;
 #endif
+   }
/* now skip all frames until is_first != 0 */
} else
frame_ok = skip_tail( dev->base_addr, framelen, crc );
 
-   if( is_first  &&  !frame_ok )
+   if( 

[PATCH 25/29] lib/zlib: Avoid comma separated statements

2020-08-24 Thread Joe Perches
Use semicolons and braces.

Signed-off-by: Joe Perches 
---
 lib/zlib_deflate/deftree.c | 49 +++---
 1 file changed, 35 insertions(+), 14 deletions(-)

diff --git a/lib/zlib_deflate/deftree.c b/lib/zlib_deflate/deftree.c
index a4a34da512fe..e358053bdb15 100644
--- a/lib/zlib_deflate/deftree.c
+++ b/lib/zlib_deflate/deftree.c
@@ -217,10 +217,22 @@ static void tr_static_init(void)
 /* Construct the codes of the static literal tree */
 for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;
 n = 0;
-while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++;
-while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++;
-while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++;
-while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++;
+while (n <= 143) {
+static_ltree[n++].Len = 8;
+   bl_count[8]++;
+}
+while (n <= 255) {
+static_ltree[n++].Len = 9;
+   bl_count[9]++;
+}
+while (n <= 279) {
+static_ltree[n++].Len = 7;
+   bl_count[7]++;
+}
+while (n <= 287) {
+static_ltree[n++].Len = 8;
+   bl_count[8]++;
+}
 /* Codes 286 and 287 do not exist, but we must include them in the
  * tree construction to get a canonical Huffman tree (longest code
  * all ones)
@@ -378,7 +390,10 @@ static void gen_bitlen(
 for (h = s->heap_max+1; h < HEAP_SIZE; h++) {
 n = s->heap[h];
 bits = tree[tree[n].Dad].Len + 1;
-if (bits > max_length) bits = max_length, overflow++;
+if (bits > max_length) {
+bits = max_length;
+   overflow++;
+}
 tree[n].Len = (ush)bits;
 /* We overwrite tree[n].Dad which is no longer needed */
 
@@ -497,7 +512,7 @@ static void build_tree(
  * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1].
  * heap[0] is not used.
  */
-s->heap_len = 0, s->heap_max = HEAP_SIZE;
+s->heap_len = 0; s->heap_max = HEAP_SIZE;
 
 for (n = 0; n < elems; n++) {
 if (tree[n].Freq != 0) {
@@ -583,7 +598,10 @@ static void scan_tree(
 int max_count = 7; /* max repeat count */
 int min_count = 4; /* min repeat count */
 
-if (nextlen == 0) max_count = 138, min_count = 3;
+if (nextlen == 0) {
+max_count = 138;
+   min_count = 3;
+}
 tree[max_code+1].Len = (ush)0x; /* guard */
 
 for (n = 0; n <= max_code; n++) {
@@ -602,11 +620,11 @@ static void scan_tree(
 }
 count = 0; prevlen = curlen;
 if (nextlen == 0) {
-max_count = 138, min_count = 3;
+max_count = 138; min_count = 3;
 } else if (curlen == nextlen) {
-max_count = 6, min_count = 3;
+max_count = 6; min_count = 3;
 } else {
-max_count = 7, min_count = 4;
+max_count = 7; min_count = 4;
 }
 }
 }
@@ -630,7 +648,10 @@ static void send_tree(
 int min_count = 4; /* min repeat count */
 
 /* tree[max_code+1].Len = -1; */  /* guard already set */
-if (nextlen == 0) max_count = 138, min_count = 3;
+if (nextlen == 0) {
+max_count = 138;
+   min_count = 3;
+}
 
 for (n = 0; n <= max_code; n++) {
 curlen = nextlen; nextlen = tree[n+1].Len;
@@ -654,11 +675,11 @@ static void send_tree(
 }
 count = 0; prevlen = curlen;
 if (nextlen == 0) {
-max_count = 138, min_count = 3;
+max_count = 138; min_count = 3;
 } else if (curlen == nextlen) {
-max_count = 6, min_count = 3;
+max_count = 6; min_count = 3;
 } else {
-max_count = 7, min_count = 4;
+max_count = 7; min_count = 4;
 }
 }
 }
-- 
2.26.0



[PATCH 29/29] tools: Avoid comma separated statements

2020-08-24 Thread Joe Perches
Use semicolons and braces.

Signed-off-by: Joe Perches 
---
 tools/lib/subcmd/help.c|  10 +-
 tools/power/cpupower/utils/cpufreq-set.c   |  14 +-
 tools/testing/selftests/vm/gup_benchmark.c |  18 +-
 tools/testing/selftests/vm/userfaultfd.c   | 296 +
 4 files changed, 210 insertions(+), 128 deletions(-)

diff --git a/tools/lib/subcmd/help.c b/tools/lib/subcmd/help.c
index 2859f107abc8..bf02d62a3b2b 100644
--- a/tools/lib/subcmd/help.c
+++ b/tools/lib/subcmd/help.c
@@ -65,12 +65,14 @@ void exclude_cmds(struct cmdnames *cmds, struct cmdnames 
*excludes)
ci = cj = ei = 0;
while (ci < cmds->cnt && ei < excludes->cnt) {
cmp = strcmp(cmds->names[ci]->name, excludes->names[ei]->name);
-   if (cmp < 0)
+   if (cmp < 0) {
cmds->names[cj++] = cmds->names[ci++];
-   else if (cmp == 0)
-   ci++, ei++;
-   else if (cmp > 0)
+   } else if (cmp == 0) {
+   ci++;
ei++;
+   } else if (cmp > 0) {
+   ei++;
+   }
}
 
while (ci < cmds->cnt)
diff --git a/tools/power/cpupower/utils/cpufreq-set.c 
b/tools/power/cpupower/utils/cpufreq-set.c
index 6ed82fba5aaa..7b2164e07057 100644
--- a/tools/power/cpupower/utils/cpufreq-set.c
+++ b/tools/power/cpupower/utils/cpufreq-set.c
@@ -99,13 +99,17 @@ static unsigned long string_to_frequency(const char *str)
continue;
 
if (str[cp] == '.') {
-   while (power > -1 && isdigit(str[cp+1]))
-   cp++, power--;
+   while (power > -1 && isdigit(str[cp+1])) {
+   cp++;
+   power--;
+   }
}
-   if (power >= -1)/* not enough => pad */
+   if (power >= -1) {  /* not enough => pad */
pad = power + 1;
-   else/* to much => strip */
-   pad = 0, cp += power + 1;
+   } else {/* too much => strip */
+   pad = 0;
+   cp += power + 1;
+   }
/* check bounds */
if (cp <= 0 || cp + pad > NORM_FREQ_LEN - 1)
return 0;
diff --git a/tools/testing/selftests/vm/gup_benchmark.c 
b/tools/testing/selftests/vm/gup_benchmark.c
index 31f8bb086907..1d4359341e44 100644
--- a/tools/testing/selftests/vm/gup_benchmark.c
+++ b/tools/testing/selftests/vm/gup_benchmark.c
@@ -105,12 +105,16 @@ int main(int argc, char **argv)
gup.flags |= FOLL_WRITE;
 
fd = open("/sys/kernel/debug/gup_benchmark", O_RDWR);
-   if (fd == -1)
-   perror("open"), exit(1);
+   if (fd == -1) {
+   perror("open");
+   exit(1);
+   }
 
p = mmap(NULL, size, PROT_READ | PROT_WRITE, flags, filed, 0);
-   if (p == MAP_FAILED)
-   perror("mmap"), exit(1);
+   if (p == MAP_FAILED) {
+   perror("mmap");
+   exit(1);
+   }
gup.addr = (unsigned long)p;
 
if (thp == 1)
@@ -123,8 +127,10 @@ int main(int argc, char **argv)
 
for (i = 0; i < repeats; i++) {
gup.size = size;
-   if (ioctl(fd, cmd, ))
-   perror("ioctl"), exit(1);
+   if (ioctl(fd, cmd, )) {
+   perror("ioctl");
+   exit(1);
+   }
 
printf("Time: get:%lld put:%lld us", gup.get_delta_usec,
gup.put_delta_usec);
diff --git a/tools/testing/selftests/vm/userfaultfd.c 
b/tools/testing/selftests/vm/userfaultfd.c
index 61e5cfeb1350..9b0912a01777 100644
--- a/tools/testing/selftests/vm/userfaultfd.c
+++ b/tools/testing/selftests/vm/userfaultfd.c
@@ -227,8 +227,10 @@ static void hugetlb_allocate_area(void **alloc_area)
  huge_fd, *alloc_area == area_src ? 0 :
  nr_pages * page_size);
if (area_alias == MAP_FAILED) {
-   if (munmap(*alloc_area, nr_pages * page_size) < 0)
-   perror("hugetlb munmap"), exit(1);
+   if (munmap(*alloc_area, nr_pages * page_size) < 0) {
+   perror("hugetlb munmap");
+   exit(1);
+   }
*alloc_area = NULL;
return;
}
@@ -337,9 +339,10 @@ static void wp_range(int ufd, __u64 start, __u64 len, bool 
wp)
/* Undo write-protect, do wakeup after that */
prms.mode = wp ? UFFDIO_WRITEPROTECT_MODE_WP : 0;
 
-   if (ioctl(ufd, UFFDIO_WRITEPROTECT, ))
-   fprintf(stderr, "clear WP failed for address 0x%Lx\n",
-   start), exit(1);
+   if (ioctl(ufd, UFFDIO_WRITEPROTECT, )) {
+   

[PATCH 27/29] ipv6: fib6: Avoid comma separated statements

2020-08-24 Thread Joe Perches
Use semicolons and braces.

Signed-off-by: Joe Perches 
---
 net/ipv6/ip6_fib.c | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
index 25a90f3f705c..44d68ed70f24 100644
--- a/net/ipv6/ip6_fib.c
+++ b/net/ipv6/ip6_fib.c
@@ -1812,10 +1812,14 @@ static struct fib6_node *fib6_repair_tree(struct net 
*net,
 
children = 0;
child = NULL;
-   if (fn_r)
-   child = fn_r, children |= 1;
-   if (fn_l)
-   child = fn_l, children |= 2;
+   if (fn_r) {
+   child = fn_r;
+   children |= 1;
+   }
+   if (fn_l) {
+   child = fn_l;
+   children |= 2;
+   }
 
if (children == 3 || FIB6_SUBTREE(fn)
 #ifdef CONFIG_IPV6_SUBTREES
-- 
2.26.0



[PATCH 17/29] fs_enet: Avoid comma separated statements

2020-08-24 Thread Joe Perches
Use semicolons and braces.

Signed-off-by: Joe Perches 
---
 drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c 
b/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
index bf846b42bc74..78e008b81374 100644
--- a/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
+++ b/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
@@ -562,10 +562,13 @@ fs_enet_start_xmit(struct sk_buff *skb, struct net_device 
*dev)
BD_ENET_TX_TC);
CBDS_SC(bdp, BD_ENET_TX_READY);
 
-   if ((CBDR_SC(bdp) & BD_ENET_TX_WRAP) == 0)
-   bdp++, curidx++;
-   else
-   bdp = fep->tx_bd_base, curidx = 0;
+   if ((CBDR_SC(bdp) & BD_ENET_TX_WRAP) == 0) {
+   bdp++;
+   curidx++;
+   } else {
+   bdp = fep->tx_bd_base;
+   curidx = 0;
+   }
 
len = skb_frag_size(frag);
CBDW_BUFADDR(bdp, skb_frag_dma_map(fep->dev, frag, 0, len,
-- 
2.26.0



[PATCH 03/29] ia64: Avoid comma separated statements

2020-08-24 Thread Joe Perches
Use semicolons and braces.

Signed-off-by: Joe Perches 
---
 arch/ia64/kernel/smpboot.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/arch/ia64/kernel/smpboot.c b/arch/ia64/kernel/smpboot.c
index c29c600d7967..3311b9d21319 100644
--- a/arch/ia64/kernel/smpboot.c
+++ b/arch/ia64/kernel/smpboot.c
@@ -224,8 +224,11 @@ get_delta (long *rt, long *master)
go[SLAVE] = 0;
t1 = ia64_get_itc();
 
-   if (t1 - t0 < best_t1 - best_t0)
-   best_t0 = t0, best_t1 = t1, best_tm = tm;
+   if (t1 - t0 < best_t1 - best_t0) {
+   best_t0 = t0;
+   best_t1 = t1;
+   best_tm = tm;
+   }
}
 
*rt = best_t1 - best_t0;
-- 
2.26.0



[PATCH 12/29] Input: MT - Avoid comma separated statements

2020-08-24 Thread Joe Perches
Use semicolons and braces.

Signed-off-by: Joe Perches 
---
 drivers/input/input-mt.c | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/input/input-mt.c b/drivers/input/input-mt.c
index f699538bdac4..44fe6f2f063c 100644
--- a/drivers/input/input-mt.c
+++ b/drivers/input/input-mt.c
@@ -323,11 +323,14 @@ static int adjust_dual(int *begin, int step, int *end, 
int eq, int mu)
p = begin + step;
s = p == end ? f + 1 : *p;
 
-   for (; p != end; p += step)
-   if (*p < f)
-   s = f, f = *p;
-   else if (*p < s)
+   for (; p != end; p += step) {
+   if (*p < f) {
+   s = f;
+   f = *p;
+   } else if (*p < s) {
s = *p;
+   }
+   }
 
c = (f + s + 1) / 2;
if (c == 0 || (c > mu && (!eq || mu > 0)))
-- 
2.26.0



[PATCH 07/29] lp: Avoid comma separated statements

2020-08-24 Thread Joe Perches
Use semicolons and braces.

Signed-off-by: Joe Perches 
---
 drivers/char/lp.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/char/lp.c b/drivers/char/lp.c
index 45932f05fd67..0ec73917d8dd 100644
--- a/drivers/char/lp.c
+++ b/drivers/char/lp.c
@@ -853,8 +853,10 @@ static void lp_console_write(struct console *co, const 
char *s,
count--;
do {
written = parport_write(port, crlf, i);
-   if (written > 0)
-   i -= written, crlf += written;
+   if (written > 0) {
+   i -= written;
+   crlf += written;
+   }
} while (i > 0 && (CONSOLE_LP_STRICT || written > 0));
}
} while (count > 0 && (CONSOLE_LP_STRICT || written > 0));
-- 
2.26.0



[PATCH 22/29] video: fbdev: Avoid comma separated statements

2020-08-24 Thread Joe Perches
Use semicolons and braces.

Signed-off-by: Joe Perches 
---
 drivers/video/fbdev/tgafb.c | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/video/fbdev/tgafb.c b/drivers/video/fbdev/tgafb.c
index e9869135d833..666fbe2f671c 100644
--- a/drivers/video/fbdev/tgafb.c
+++ b/drivers/video/fbdev/tgafb.c
@@ -989,8 +989,10 @@ tgafb_fillrect(struct fb_info *info, const struct 
fb_fillrect *rect)
/* We can fill 2k pixels per operation.  Notice blocks that fit
   the width of the screen so that we can take advantage of this
   and fill more than one line per write.  */
-   if (width == line_length)
-   width *= height, height = 1;
+   if (width == line_length) {
+   width *= height;
+   height = 1;
+   }
 
/* The write into the frame buffer must be aligned to 4 bytes,
   but we are allowed to encode the offset within the word in
@@ -1171,8 +1173,10 @@ copyarea_8bpp(struct fb_info *info, u32 dx, u32 dy, u32 
sx, u32 sy,
   More than anything else, these control how we do copies.  */
depos = dy * line_length + dx;
sepos = sy * line_length + sx;
-   if (backward)
-   depos += width, sepos += width;
+   if (backward) {
+   depos += width;
+   sepos += width;
+   }
 
/* Next copy full words at a time.  */
n32 = width / 32;
-- 
2.26.0



[PATCH 23/29] fuse: Avoid comma separated statements

2020-08-24 Thread Joe Perches
Use semicolons and braces.

Signed-off-by: Joe Perches 
---
 fs/fuse/dir.c | 24 
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index 26f028bc760b..ecb6eed832a0 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -1362,14 +1362,22 @@ static void iattr_to_fattr(struct fuse_conn *fc, struct 
iattr *iattr,
 {
unsigned ivalid = iattr->ia_valid;
 
-   if (ivalid & ATTR_MODE)
-   arg->valid |= FATTR_MODE,   arg->mode = iattr->ia_mode;
-   if (ivalid & ATTR_UID)
-   arg->valid |= FATTR_UID,arg->uid = from_kuid(fc->user_ns, 
iattr->ia_uid);
-   if (ivalid & ATTR_GID)
-   arg->valid |= FATTR_GID,arg->gid = from_kgid(fc->user_ns, 
iattr->ia_gid);
-   if (ivalid & ATTR_SIZE)
-   arg->valid |= FATTR_SIZE,   arg->size = iattr->ia_size;
+   if (ivalid & ATTR_MODE) {
+   arg->valid |= FATTR_MODE;
+   arg->mode = iattr->ia_mode;
+   }
+   if (ivalid & ATTR_UID) {
+   arg->valid |= FATTR_UID;
+   arg->uid = from_kuid(fc->user_ns, iattr->ia_uid);
+   }
+   if (ivalid & ATTR_GID) {
+   arg->valid |= FATTR_GID;
+   arg->gid = from_kgid(fc->user_ns, iattr->ia_gid);
+   }
+   if (ivalid & ATTR_SIZE) {
+   arg->valid |= FATTR_SIZE;
+   arg->size = iattr->ia_size;
+   }
if (ivalid & ATTR_ATIME) {
arg->valid |= FATTR_ATIME;
arg->atime = iattr->ia_atime.tv_sec;
-- 
2.26.0



[PATCH 20/29] scai/arm: Avoid comma separated statements

2020-08-24 Thread Joe Perches
Use semicolons and braces.

Signed-off-by: Joe Perches 
---
 drivers/scsi/arm/cumana_2.c | 19 +++
 drivers/scsi/arm/eesox.c|  9 +
 drivers/scsi/arm/powertec.c |  9 +
 3 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/drivers/scsi/arm/cumana_2.c b/drivers/scsi/arm/cumana_2.c
index 29294f0ef8a9..9dcd912267e6 100644
--- a/drivers/scsi/arm/cumana_2.c
+++ b/drivers/scsi/arm/cumana_2.c
@@ -166,14 +166,15 @@ cumanascsi_2_dma_setup(struct Scsi_Host *host, struct 
scsi_pointer *SCp,
 
bufs = copy_SCp_to_sg(>sg[0], SCp, NR_SG);
 
-   if (direction == DMA_OUT)
-   map_dir = DMA_TO_DEVICE,
-   dma_dir = DMA_MODE_WRITE,
+   if (direction == DMA_OUT) {
+   map_dir = DMA_TO_DEVICE;
+   dma_dir = DMA_MODE_WRITE;
alatch_dir = ALATCH_DMA_OUT;
-   else
-   map_dir = DMA_FROM_DEVICE,
-   dma_dir = DMA_MODE_READ,
+   } else {
+   map_dir = DMA_FROM_DEVICE;
+   dma_dir = DMA_MODE_READ;
alatch_dir = ALATCH_DMA_IN;
+   }
 
dma_map_sg(dev, info->sg, bufs, map_dir);
 
@@ -326,10 +327,12 @@ cumanascsi_2_set_proc_info(struct Scsi_Host *host, char 
*buffer, int length)
cumanascsi_2_terminator_ctl(host, 0);
else
ret = -EINVAL;
-   } else
+   } else {
ret = -EINVAL;
-   } else
+   }
+   } else {
ret = -EINVAL;
+   }
 
return ret;
 }
diff --git a/drivers/scsi/arm/eesox.c b/drivers/scsi/arm/eesox.c
index 591ae2a6dd74..5eb2415dda9d 100644
--- a/drivers/scsi/arm/eesox.c
+++ b/drivers/scsi/arm/eesox.c
@@ -165,12 +165,13 @@ eesoxscsi_dma_setup(struct Scsi_Host *host, struct 
scsi_pointer *SCp,
 
bufs = copy_SCp_to_sg(>sg[0], SCp, NR_SG);
 
-   if (direction == DMA_OUT)
-   map_dir = DMA_TO_DEVICE,
+   if (direction == DMA_OUT) {
+   map_dir = DMA_TO_DEVICE;
dma_dir = DMA_MODE_WRITE;
-   else
-   map_dir = DMA_FROM_DEVICE,
+   } else {
+   map_dir = DMA_FROM_DEVICE;
dma_dir = DMA_MODE_READ;
+   }
 
dma_map_sg(dev, info->sg, bufs, map_dir);
 
diff --git a/drivers/scsi/arm/powertec.c b/drivers/scsi/arm/powertec.c
index d99ef014528e..9cc73da4e876 100644
--- a/drivers/scsi/arm/powertec.c
+++ b/drivers/scsi/arm/powertec.c
@@ -138,12 +138,13 @@ powertecscsi_dma_setup(struct Scsi_Host *host, struct 
scsi_pointer *SCp,
 
bufs = copy_SCp_to_sg(>sg[0], SCp, NR_SG);
 
-   if (direction == DMA_OUT)
-   map_dir = DMA_TO_DEVICE,
+   if (direction == DMA_OUT) {
+   map_dir = DMA_TO_DEVICE;
dma_dir = DMA_MODE_WRITE;
-   else
-   map_dir = DMA_FROM_DEVICE,
+   } else {
+   map_dir = DMA_FROM_DEVICE;
dma_dir = DMA_MODE_READ;
+   }
 
dma_map_sg(dev, info->sg, bufs, map_dir);
 
-- 
2.26.0



[PATCH 11/29] hwmon: (scmi-hwmon): Avoid comma separated statements

2020-08-24 Thread Joe Perches
Use semicolons and braces.

Signed-off-by: Joe Perches 
---
 drivers/hwmon/scmi-hwmon.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/scmi-hwmon.c b/drivers/hwmon/scmi-hwmon.c
index d421e691318b..09ce30cba54b 100644
--- a/drivers/hwmon/scmi-hwmon.c
+++ b/drivers/hwmon/scmi-hwmon.c
@@ -202,8 +202,10 @@ static int scmi_hwmon_probe(struct scmi_device *sdev)
}
}
 
-   if (nr_count[hwmon_temp])
-   nr_count[hwmon_chip]++, nr_types++;
+   if (nr_count[hwmon_temp]) {
+   nr_count[hwmon_chip]++;
+   nr_types++;
+   }
 
scmi_hwmon_chan = devm_kcalloc(dev, nr_types, sizeof(*scmi_hwmon_chan),
   GFP_KERNEL);
-- 
2.26.0



[PATCH 24/29] reiserfs: Avoid comma separated statements

2020-08-24 Thread Joe Perches
Use semicolons and braces.

Signed-off-by: Joe Perches 
---
 fs/reiserfs/fix_node.c | 36 
 1 file changed, 24 insertions(+), 12 deletions(-)

diff --git a/fs/reiserfs/fix_node.c b/fs/reiserfs/fix_node.c
index fefe87e1c099..aea63e67a42b 100644
--- a/fs/reiserfs/fix_node.c
+++ b/fs/reiserfs/fix_node.c
@@ -235,8 +235,10 @@ static void check_left(struct tree_balance *tb, int h, int 
cur_free)
d_size = 0, ih_size = IH_SIZE;
 
/* first item may be merge with last item in left neighbor */
-   if (vi->vi_type & VI_TYPE_LEFT_MERGEABLE)
-   d_size = -((int)IH_SIZE), ih_size = 0;
+   if (vi->vi_type & VI_TYPE_LEFT_MERGEABLE) {
+   d_size = -((int)IH_SIZE);
+   ih_size = 0;
+   }
 
tb->lnum[0] = 0;
for (i = 0; i < vn->vn_nr_item;
@@ -321,8 +323,10 @@ static void check_right(struct tree_balance *tb, int h, 
int cur_free)
d_size = 0, ih_size = IH_SIZE;
 
/* last item may be merge with first item in right neighbor */
-   if (vi->vi_type & VI_TYPE_RIGHT_MERGEABLE)
-   d_size = -(int)IH_SIZE, ih_size = 0;
+   if (vi->vi_type & VI_TYPE_RIGHT_MERGEABLE) {
+   d_size = -(int)IH_SIZE;
+   ih_size = 0;
+   }
 
tb->rnum[0] = 0;
for (i = vn->vn_nr_item - 1; i >= 0;
@@ -1534,8 +1538,10 @@ static int ip_check_balance(struct tree_balance *tb, int 
h)
nver1 = get_num_ver(vn->vn_mode, tb, h,
0, -1, 0, -1,
snum012 + NOTHING_SHIFT_FLOW, FLOW);
-   if (nver > nver1)
-   nset = NOTHING_SHIFT_FLOW, nver = nver1;
+   if (nver > nver1) {
+   nset = NOTHING_SHIFT_FLOW;
+   nver = nver1;
+   }
}
 
/*
@@ -1559,8 +1565,10 @@ static int ip_check_balance(struct tree_balance *tb, int 
h)
 ((tb->lbytes != -1) ? 1 : 0),
 tb->lbytes, 0, -1,
 snum012 + LEFT_SHIFT_FLOW, FLOW);
-   if (lnver > lnver1)
-   lset = LEFT_SHIFT_FLOW, lnver = lnver1;
+   if (lnver > lnver1) {
+   lset = LEFT_SHIFT_FLOW;
+   lnver = lnver1;
+   }
}
 
/*
@@ -1590,8 +1598,10 @@ static int ip_check_balance(struct tree_balance *tb, int 
h)
 tb->rbytes,
 snum012 + RIGHT_SHIFT_FLOW, FLOW);
 
-   if (rnver > rnver1)
-   rset = RIGHT_SHIFT_FLOW, rnver = rnver1;
+   if (rnver > rnver1) {
+   rset = RIGHT_SHIFT_FLOW;
+   rnver = rnver1;
+   }
}
 
/*
@@ -1622,8 +1632,10 @@ static int ip_check_balance(struct tree_balance *tb, int 
h)
   ((tb->rbytes != -1) ? 1 : 0)),
  tb->rbytes,
  snum012 + LR_SHIFT_FLOW, FLOW);
-   if (lrnver > lrnver1)
-   lrset = LR_SHIFT_FLOW, lrnver = lrnver1;
+   if (lrnver > lrnver1) {
+   lrset = LR_SHIFT_FLOW;
+   lrnver = lrnver1;
+   }
}
 
/*
-- 
2.26.0



[PATCH 26/29] lib: zstd: Avoid comma separated statements

2020-08-24 Thread Joe Perches
Use semicolons and braces.

Signed-off-by: Joe Perches 
---
 lib/zstd/compress.c | 120 ++--
 lib/zstd/fse_compress.c |  24 +---
 lib/zstd/huf_compress.c |   6 +-
 3 files changed, 100 insertions(+), 50 deletions(-)

diff --git a/lib/zstd/compress.c b/lib/zstd/compress.c
index b080264ed3ad..d8587e458665 100644
--- a/lib/zstd/compress.c
+++ b/lib/zstd/compress.c
@@ -629,12 +629,17 @@ ZSTD_STATIC size_t 
ZSTD_compressSequences_internal(ZSTD_CCtx *zc, void *dst, siz
/* Sequences Header */
if ((oend - op) < 3 /*max nbSeq Size*/ + 1 /*seqHead */)
return ERROR(dstSize_tooSmall);
-   if (nbSeq < 0x7F)
+   if (nbSeq < 0x7F) {
*op++ = (BYTE)nbSeq;
-   else if (nbSeq < LONGNBSEQ)
-   op[0] = (BYTE)((nbSeq >> 8) + 0x80), op[1] = (BYTE)nbSeq, op += 
2;
-   else
-   op[0] = 0xFF, ZSTD_writeLE16(op + 1, (U16)(nbSeq - LONGNBSEQ)), 
op += 3;
+   } else if (nbSeq < LONGNBSEQ) {
+   op[0] = (BYTE)((nbSeq >> 8) + 0x80);
+   op[1] = (BYTE)nbSeq;
+   op += 2;
+   } else {
+   op[0] = 0xFF;
+   ZSTD_writeLE16(op + 1, (U16)(nbSeq - LONGNBSEQ));
+   op += 3;
+   }
if (nbSeq == 0)
return op - ostart;
 
@@ -1025,10 +1030,13 @@ void ZSTD_compressBlock_fast_generic(ZSTD_CCtx *cctx, 
const void *src, size_t sr
ip += (ip == lowest);
{
U32 const maxRep = (U32)(ip - lowest);
-   if (offset_2 > maxRep)
-   offsetSaved = offset_2, offset_2 = 0;
-   if (offset_1 > maxRep)
-   offsetSaved = offset_1, offset_1 = 0;
+   if (offset_2 > maxRep) {
+   offsetSaved = offset_2;
+   offset_2 = 0;
+   }
+   if (offset_1 > maxRep) {
+   offsetSaved = offset_1; offset_1 = 0;
+   }
}
 
/* Main Search Loop */
@@ -1273,10 +1281,14 @@ void ZSTD_compressBlock_doubleFast_generic(ZSTD_CCtx 
*cctx, const void *src, siz
ip += (ip == lowest);
{
U32 const maxRep = (U32)(ip - lowest);
-   if (offset_2 > maxRep)
-   offsetSaved = offset_2, offset_2 = 0;
-   if (offset_1 > maxRep)
-   offsetSaved = offset_1, offset_1 = 0;
+   if (offset_2 > maxRep) {
+   offsetSaved = offset_2;
+   offset_2 = 0;
+   }
+   if (offset_1 > maxRep) {
+   offsetSaved = offset_1;
+   offset_1 = 0;
+   }
}
 
/* Main Search Loop */
@@ -1686,8 +1698,10 @@ static size_t ZSTD_insertBtAndFindBestMatch(ZSTD_CCtx 
*zc, const BYTE *const ip,
if (matchLength > bestLength) {
if (matchLength > matchEndIdx - matchIndex)
matchEndIdx = matchIndex + (U32)matchLength;
-   if ((4 * (int)(matchLength - bestLength)) > 
(int)(ZSTD_highbit32(curr - matchIndex + 1) - ZSTD_highbit32((U32)offsetPtr[0] 
+ 1)))
-   bestLength = matchLength, *offsetPtr = 
ZSTD_REP_MOVE + curr - matchIndex;
+   if ((4 * (int)(matchLength - bestLength)) > 
(int)(ZSTD_highbit32(curr - matchIndex + 1) - ZSTD_highbit32((U32)offsetPtr[0] 
+ 1))) {
+   bestLength = matchLength;
+   *offsetPtr = ZSTD_REP_MOVE + curr - matchIndex;
+   }
if (ip + matchLength == iend) /* equal : no way to know 
if inf or sup */
break;/* drop, to guarantee 
consistency (miss a little bit of compression) */
}
@@ -1916,10 +1930,14 @@ void ZSTD_compressBlock_lazy_generic(ZSTD_CCtx *ctx, 
const void *src, size_t src
ctx->nextToUpdate3 = ctx->nextToUpdate;
{
U32 const maxRep = (U32)(ip - base);
-   if (offset_2 > maxRep)
-   savedOffset = offset_2, offset_2 = 0;
-   if (offset_1 > maxRep)
-   savedOffset = offset_1, offset_1 = 0;
+   if (offset_2 > maxRep) {
+   savedOffset = offset_2;
+   offset_2 = 0;
+   }
+   if (offset_1 > maxRep) {
+   savedOffset = offset_1;
+   offset_1 = 0;
+   }
}
 
/* Match Loop */
@@ -1940,8 +1958,11 @@ void ZSTD_compressBlock_lazy_generic(ZSTD_CCtx *ctx, 
const void *src, size_t src
{
size_t offsetFound = ;
size_t const ml2 = searchMax(ctx, ip, iend, 
, maxSearches, mls);
-   if (ml2 > matchLength)
- 

[PATCH 00/29] treewide: Convert comma separated statements

2020-08-24 Thread Joe Perches
There are many comma separated statements in the kernel.
See:https://lore.kernel.org/lkml/alpine.DEB.2.22.394.2008201856110.2524@hadrien/

Convert the comma separated statements that are in if/do/while blocks
to use braces and semicolons.

Many comma separated statements still exist but those are changes for
another day.

Joe Perches (29):
  coding-style.rst: Avoid comma statements
  alpha: Avoid comma separated statements
  ia64: Avoid comma separated statements
  sparc: Avoid comma separated statements
  ata: Avoid comma separated statements
  drbd: Avoid comma separated statements
  lp: Avoid comma separated statements
  dma-buf: Avoid comma separated statements
  drm/gma500: Avoid comma separated statements
  drm/i915: Avoid comma separated statements
  hwmon: (scmi-hwmon): Avoid comma separated statements
  Input: MT - Avoid comma separated statements
  bcache: Avoid comma separated statements
  media: Avoid comma separated statements
  mtd: Avoid comma separated statements
  8390: Avoid comma separated statements
  fs_enet: Avoid comma separated statements
  wan: sbni: Avoid comma separated statements
  s390/tty3270: Avoid comma separated statements
  scai/arm: Avoid comma separated statements
  media: atomisp: Avoid comma separated statements
  video: fbdev: Avoid comma separated statements
  fuse: Avoid comma separated statements
  reiserfs: Avoid comma separated statements
  lib/zlib: Avoid comma separated statements
  lib: zstd: Avoid comma separated statements
  ipv6: fib6: Avoid comma separated statements
  sunrpc: Avoid comma separated statements
  tools: Avoid comma separated statements

 Documentation/process/coding-style.rst|  17 +
 arch/alpha/kernel/pci_iommu.c |   8 +-
 arch/alpha/oprofile/op_model_ev4.c|  22 +-
 arch/alpha/oprofile/op_model_ev5.c|   8 +-
 arch/ia64/kernel/smpboot.c|   7 +-
 arch/sparc/kernel/smp_64.c|   7 +-
 drivers/ata/pata_icside.c |  21 +-
 drivers/block/drbd/drbd_receiver.c|   6 +-
 drivers/char/lp.c |   6 +-
 drivers/dma-buf/st-dma-fence.c|   7 +-
 drivers/gpu/drm/gma500/mdfld_intel_display.c  |  44 ++-
 drivers/gpu/drm/i915/gt/gen8_ppgtt.c  |   8 +-
 drivers/gpu/drm/i915/gt/intel_gt_requests.c   |   6 +-
 .../gpu/drm/i915/gt/selftest_workarounds.c|   6 +-
 drivers/gpu/drm/i915/intel_runtime_pm.c   |   6 +-
 drivers/hwmon/scmi-hwmon.c|   6 +-
 drivers/input/input-mt.c  |  11 +-
 drivers/md/bcache/bset.c  |  12 +-
 drivers/md/bcache/sysfs.c |   6 +-
 drivers/media/i2c/msp3400-kthreads.c  |  12 +-
 drivers/media/pci/bt8xx/bttv-cards.c  |   6 +-
 drivers/media/pci/saa7134/saa7134-video.c |   7 +-
 drivers/mtd/devices/lart.c|  10 +-
 drivers/net/ethernet/8390/axnet_cs.c  |  19 +-
 drivers/net/ethernet/8390/lib8390.c   |  14 +-
 drivers/net/ethernet/8390/pcnet_cs.c  |   6 +-
 .../ethernet/freescale/fs_enet/fs_enet-main.c |  11 +-
 drivers/net/wan/sbni.c| 101 +++---
 drivers/s390/char/tty3270.c   |   6 +-
 drivers/scsi/arm/cumana_2.c   |  19 +-
 drivers/scsi/arm/eesox.c  |   9 +-
 drivers/scsi/arm/powertec.c   |   9 +-
 .../media/atomisp/pci/atomisp_subdev.c|   6 +-
 drivers/video/fbdev/tgafb.c   |  12 +-
 fs/fuse/dir.c |  24 +-
 fs/reiserfs/fix_node.c|  36 ++-
 lib/zlib_deflate/deftree.c|  49 ++-
 lib/zstd/compress.c   | 120 ---
 lib/zstd/fse_compress.c   |  24 +-
 lib/zstd/huf_compress.c   |   6 +-
 net/ipv6/ip6_fib.c|  12 +-
 net/sunrpc/sysctl.c   |   6 +-
 tools/lib/subcmd/help.c   |  10 +-
 tools/power/cpupower/utils/cpufreq-set.c  |  14 +-
 tools/testing/selftests/vm/gup_benchmark.c|  18 +-
 tools/testing/selftests/vm/userfaultfd.c  | 296 +++---
 46 files changed, 694 insertions(+), 382 deletions(-)

-- 
2.26.0



[PATCH 02/29] alpha: Avoid comma separated statements

2020-08-24 Thread Joe Perches
Use semicolons and braces.

Signed-off-by: Joe Perches 
---
 arch/alpha/kernel/pci_iommu.c  |  8 +---
 arch/alpha/oprofile/op_model_ev4.c | 22 ++
 arch/alpha/oprofile/op_model_ev5.c |  8 +---
 3 files changed, 24 insertions(+), 14 deletions(-)

diff --git a/arch/alpha/kernel/pci_iommu.c b/arch/alpha/kernel/pci_iommu.c
index 81037907268d..b8af7ad6c607 100644
--- a/arch/alpha/kernel/pci_iommu.c
+++ b/arch/alpha/kernel/pci_iommu.c
@@ -161,10 +161,12 @@ iommu_arena_find_pages(struct device *dev, struct 
pci_iommu_arena *arena,
goto again;
}
 
-   if (ptes[p+i])
-   p = ALIGN(p + i + 1, mask + 1), i = 0;
-   else
+   if (ptes[p+i]) {
+   p = ALIGN(p + i + 1, mask + 1);
+   i = 0;
+   } else {
i = i + 1;
+   }
}
 
if (i < n) {
diff --git a/arch/alpha/oprofile/op_model_ev4.c 
b/arch/alpha/oprofile/op_model_ev4.c
index 086a0d5445c5..004f80a4291f 100644
--- a/arch/alpha/oprofile/op_model_ev4.c
+++ b/arch/alpha/oprofile/op_model_ev4.c
@@ -46,18 +46,24 @@ ev4_reg_setup(struct op_register_config *reg,
   map it onto one of the possible values, and write it back.  */
 
count = ctr[0].count;
-   if (count <= 4096)
-   count = 4096, hilo = 1;
-   else
-   count = 65536, hilo = 0;
+   if (count <= 4096) {
+   count = 4096;
+   hilo = 1;
+   } else {
+   count = 65536;
+   hilo = 0;
+   }
ctr[0].count = count;
ctl |= (ctr[0].enabled && hilo) << 3;
 
count = ctr[1].count;
-   if (count <= 256)
-   count = 256, hilo = 1;
-   else
-   count = 4096, hilo = 0;
+   if (count <= 256) {
+   count = 256;
+   hilo = 1;
+   } else {
+   count = 4096;
+   hilo = 0;
+   }
ctr[1].count = count;
ctl |= (ctr[1].enabled && hilo);
 
diff --git a/arch/alpha/oprofile/op_model_ev5.c 
b/arch/alpha/oprofile/op_model_ev5.c
index c300f5ef3482..6f52244e1181 100644
--- a/arch/alpha/oprofile/op_model_ev5.c
+++ b/arch/alpha/oprofile/op_model_ev5.c
@@ -92,9 +92,11 @@ common_reg_setup(struct op_register_config *reg,
if (!ctr[i].enabled)
continue;
 
-   if (count <= 256)
-   count = 256, hilo = 3, max = 256;
-   else {
+   if (count <= 256) {
+   max = 256;
+   hilo = 3;
+   count = 256;
+   } else {
max = (i == 2 ? 16384 : 65536);
hilo = 2;
if (count > max)
-- 
2.26.0



[PATCH 01/29] coding-style.rst: Avoid comma statements

2020-08-24 Thread Joe Perches
Commas are not how statements are terminated.
Always use semicolons and braces if necessary.

Signed-off-by: Joe Perches 
---
 Documentation/process/coding-style.rst | 17 +
 1 file changed, 17 insertions(+)

diff --git a/Documentation/process/coding-style.rst 
b/Documentation/process/coding-style.rst
index 98227226c4e5..a1e061149e0d 100644
--- a/Documentation/process/coding-style.rst
+++ b/Documentation/process/coding-style.rst
@@ -69,9 +69,26 @@ something to hide:
if (condition) do_this;
  do_something_everytime;
 
+Don't use commas to avoid using braces:
+
+.. code-block:: c
+
+   if (condition)
+   do_this(), do_that();
+
+Always uses braces for multiple statements:
+
+.. code-block:: c
+
+   if (condition) {
+   do_this();
+   do_that();
+   }
+
 Don't put multiple assignments on a single line either.  Kernel coding style
 is super simple.  Avoid tricky expressions.
 
+
 Outside of comments, documentation and except in Kconfig, spaces are never
 used for indentation, and the above example is deliberately broken.
 
-- 
2.26.0



Re: [PATCH v2 3/9] ASoC: audio-graph: Identify 'no_pcm' DAI links for DPCM

2020-08-24 Thread Kuninori Morimoto


Hi Sameer

> +static bool soc_component_is_pcm(struct 
> snd_soc_dai_link_component *dlc)
> +{
> + struct snd_soc_dai *dai = snd_soc_find_dai(dlc);
> +
> + if (dai && (dai->component->driver->pcm_construct ||
> + dai->driver->pcm_new))
> + return true;
> +
> + return false;
> +}
(snip)
> I tried testing this with LOCKDEP config enabled at my end.
> It seems I don't see warning originated from above function.
> Are you suggesting that, in general, snd_soc_find_dai()
> should be called with client_mutex held?

Hmm ? strange...

snd_soc_find_dai() is using lockdep_assert_held()

struct snd_soc_dai *snd_soc_find_dai(...)
{
...
=>  lockdep_assert_held(_mutex);
...
}

and lockdep_assert_held() will indicate WARN_ON()

-- lockdep.h --
...
#ifdef CONFIG_LOCKDEP
...
#define lockdep_assert_held(l)  do {\
=>  WARN_ON(debug_locks && !lockdep_is_held(l));\
} while (0)

> May be snd_soc_dai_link_set_capabilities() requires similar fix?

Yes, I'm posting fixup patch.

https://patchwork.kernel.org/patch/11719919/

Thank you for your help !!

Best regards
---
Kuninori Morimoto


回复: [PATCH] debugobjects: install cpu hotplug callback

2020-08-24 Thread Zhang, Qiang


发件人: linux-kernel-ow...@vger.kernel.org  代表 
qiang.zh...@windriver.com 
发送时间: 2020年8月20日 11:24
收件人: t...@linutronix.de; el...@google.com; long...@redhat.com
抄送: linux-kernel@vger.kernel.org
主题: [PATCH] debugobjects: install cpu hotplug callback

From: Zqiang 

When a cpu going offline, we should free objects in "percpu_obj_pool"
free_objs list which corresponding to this cpu.

Signed-off-by: Zqiang 
---
 include/linux/cpuhotplug.h |  1 +
 lib/debugobjects.c | 23 +++
 2 files changed, 24 insertions(+)

diff --git a/include/linux/cpuhotplug.h b/include/linux/cpuhotplug.h
index a2710e654b64..2e77db655cfa 100644
--- a/include/linux/cpuhotplug.h
+++ b/include/linux/cpuhotplug.h
@@ -36,6 +36,7 @@ enum cpuhp_state {
CPUHP_X86_MCE_DEAD,
CPUHP_VIRT_NET_DEAD,
CPUHP_SLUB_DEAD,
+   CPUHP_DEBUG_OBJ_DEAD,
CPUHP_MM_WRITEBACK_DEAD,
CPUHP_MM_VMSTAT_DEAD,
CPUHP_SOFTIRQ_DEAD,
diff --git a/lib/debugobjects.c b/lib/debugobjects.c
index fe4557955d97..50e21ed0519e 100644
--- a/lib/debugobjects.c
+++ b/lib/debugobjects.c
@@ -19,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 

 #define ODEBUG_HASH_BITS   14
 #define ODEBUG_HASH_SIZE   (1 << ODEBUG_HASH_BITS)
@@ -433,6 +434,23 @@ static void free_object(struct debug_obj *obj)
}
 }

+#if defined(CONFIG_HOTPLUG_CPU)
+static int object_cpu_offline(unsigned int cpu)
+{
+   struct debug_percpu_free *percpu_pool;
+   struct hlist_node *tmp;
+   struct debug_obj *obj;
+
+   percpu_pool = per_cpu_ptr(_obj_pool, cpu);
+   hlist_for_each_entry_safe(obj, tmp, _pool->free_objs, node) {
+   hlist_del(>node);
+   kmem_cache_free(obj_cache, obj);
+   }
+
+   return 0;
+}
+#endif
+
 /*
  * We run out of memory. That means we probably have tons of objects
  * allocated.
@@ -1367,6 +1385,11 @@ void __init debug_objects_mem_init(void)
} else
debug_objects_selftest();

+#if defined(CONFIG_HOTPLUG_CPU)
+   cpuhp_setup_state_nocalls(CPUHP_DEBUG_OBJ_DEAD, "object:offline", NULL,
+   object_cpu_offline);
+#endif
+
/*
 * Increase the thresholds for allocating and freeing objects
 * according to the number of possible CPUs available in the system.
--
2.17.1



Re: [PATCH v2 13/19] dt-bindings: nvmem: imx-ocotp: Update i.MX 8M compatibles

2020-08-24 Thread Sascha Hauer
On Mon, Aug 24, 2020 at 06:26:46PM +0200, Krzysztof Kozlowski wrote:
> +oneOf:
> +  - items:
> +  - enum:
> +  - fsl,imx6q-ocotp
> +  - fsl,imx6sl-ocotp
> +  - fsl,imx6sx-ocotp
> +  - fsl,imx6ul-ocotp
> +  - fsl,imx6ull-ocotp
> +  - fsl,imx7d-ocotp
> +  - fsl,imx6sll-ocotp
> +  - fsl,imx7ulp-ocotp
> +  - fsl,imx8mq-ocotp
> +  - fsl,imx8mm-ocotp
> +  - fsl,imx8mn-ocotp
> +  - fsl,imx8mp-ocotp
> +  - const: syscon
> +  - items:
> +  # The devices are not really compatible with fsl,imx8mm-ocotp, 
> however
> +  # the code for getting SoC revision depends on fsl,imx8mm-ocotp 
> compatible.

Shouldn't this be fixed? It seems strange to justify a binding with
existing code.

Sascha

> +  - enum:
> +  - fsl,imx8mn-ocotp
> +  - fsl,imx8mp-ocotp
> +  - const: fsl,imx8mm-ocotp
> +  - const: syscon
>  
>reg:
>  maxItems: 1
> -- 
> 2.17.1
> 
> 

-- 
Pengutronix e.K.   | |
Steuerwalder Str. 21   | http://www.pengutronix.de/  |
31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |


Re: [RFC PATCH 3/3] opp: Power on (virtual) power domains managed by the OPP core

2020-08-24 Thread Viresh Kumar
On 24-08-20, 17:08, Stephan Gerhold wrote:
> On Mon, Aug 24, 2020 at 04:36:57PM +0200, Ulf Hansson wrote:
> > That said, perhaps should rely on the consumer to deploy runtime PM
> > support, but let the OPP core to set up the device links for the genpd
> > virtual devices!?
> > 
> 
> Yes, that would be the alternative option.

That is the right option IMO.

> I would be fine with it as long as it also works for the CPUfreq case.
> 
> I don't think anything manages runtime PM for the CPU device, just
> like no-one calls dev_pm_opp_set_rate(cpu_dev, 0). So with my patch the
> power domain is essentially kept always-on (except for system suspend).
> At least in my case this is intended.
> 
> If device links also keep the power domains on if the consumer device
> does not make use of runtime PM it should work fine for my case.

With device link, you only need to do rpm enable/disable on the consumer device
and it will get propagated by itself.

> Personally, I think my original patch (without device links) fits better
> into the OPP API, for the following two reasons.
> 
> With device links:
> 
>   1. Unlike regulators/interconnects, attached power domains would be
>  controlled by runtime PM instead of dev_pm_opp_set_rate(opp_dev, 0).
> 
>   2. ... some driver using OPP tables might not make use of runtime PM.
>  In that case, the power domains would stay on the whole time,
>  even if dev_pm_opp_set_rate(opp_dev, 0) was called.
> 
> With my patch, the power domain state is directly related to the
> dev_pm_opp_set_rate(opp_dev, 0) call, which is more intuitive than
> relying on the runtime PM state in my opinion.

So opp-set-rate isn't in the best of shape TBH, some things are left for the
drivers while other are done by it. Regulator-enable/disable was moved to it
some time back as people needed something like that. While on the other hand,
clk_enable/disable doesn't happen there, nor does rpm enable/disable.

Maybe one day we may want to do that, but lets make sure someone wants to do
that first.

Anyway, even in that case both of the changes would be required. We must make
device links nevertheless first. And later on if required, we may want to do rpm
enable/disable on the consumer device itself.

-- 
viresh


TDX #VE in SYSCALL gap (was: [RFD] x86: Curing the exception and syscall trainwreck in hardware)

2020-08-24 Thread Sean Christopherson
+Andy

On Mon, Aug 24, 2020 at 02:52:01PM +0100, Andrew Cooper wrote:
> And to help with coordination, here is something prepared (slightly)
> earlier.
> 
> https://docs.google.com/document/d/1hWejnyDkjRRAW-JEsRjA5c9CKLOPc6VKJQsuvODlQEI/edit?usp=sharing
> 
> This identifies the problems from software's perspective, along with
> proposing behaviour which ought to resolve the issues.
> 
> It is still a work-in-progress.  The #VE section still needs updating in
> light of the publication of the recent TDX spec.

For #VE on memory accesses in the SYSCALL gap (or NMI entry), is this
something we (Linux) as the guest kernel actually want to handle gracefully
(where gracefully means not panicking)?  For TDX, a #VE in the SYSCALL gap
would require one of two things:

  a) The guest kernel to not accept/validate the GPA->HPA mapping for the
 relevant pages, e.g. code or scratch data.

  b) The host VMM to remap the GPA (making the GPA->HPA pending again).

(a) is only possible if there's a fatal buggy guest kernel (or perhaps vBIOS).
(b) requires either a buggy or malicious host VMM.

I ask because, if the answer is "no, panic at will", then we shouldn't need
to burn an IST for TDX #VE.  Exceptions won't morph to #VE and hitting an
instruction based #VE in the SYSCALL gap would be a CPU bug or a kernel bug.
Ditto for a #VE in NMI entry before it gets to a thread stack.

Am I missing anything?


[PATCH v5 7/8] powerpc/watchpoint/ptrace: Introduce PPC_DEBUG_FEATURE_DATA_BP_ARCH_31

2020-08-24 Thread Ravi Bangoria
PPC_DEBUG_FEATURE_DATA_BP_ARCH_31 can be used to determine whether
we are running on an ISA 3.1 compliant machine. Which is needed to
determine DAR behaviour, 512 byte boundary limit etc. This was
requested by Pedro Miraglia Franco de Carvalho for extending
watchpoint features in gdb. Note that availability of 2nd DAWR is
independent of this flag and should be checked using
ppc_debug_info->num_data_bps.

Signed-off-by: Ravi Bangoria 
---
 Documentation/powerpc/ptrace.rst  | 1 +
 arch/powerpc/include/uapi/asm/ptrace.h| 1 +
 arch/powerpc/kernel/ptrace/ptrace-noadv.c | 2 ++
 3 files changed, 4 insertions(+)

diff --git a/Documentation/powerpc/ptrace.rst b/Documentation/powerpc/ptrace.rst
index 864d4b61..77725d69eb4a 100644
--- a/Documentation/powerpc/ptrace.rst
+++ b/Documentation/powerpc/ptrace.rst
@@ -46,6 +46,7 @@ features will have bits indicating whether there is support 
for::
   #define PPC_DEBUG_FEATURE_DATA_BP_RANGE  0x4
   #define PPC_DEBUG_FEATURE_DATA_BP_MASK   0x8
   #define PPC_DEBUG_FEATURE_DATA_BP_DAWR   0x10
+  #define PPC_DEBUG_FEATURE_DATA_BP_ARCH_310x20
 
 2. PTRACE_SETHWDEBUG
 
diff --git a/arch/powerpc/include/uapi/asm/ptrace.h 
b/arch/powerpc/include/uapi/asm/ptrace.h
index f5f1ccc740fc..7004cfea3f5f 100644
--- a/arch/powerpc/include/uapi/asm/ptrace.h
+++ b/arch/powerpc/include/uapi/asm/ptrace.h
@@ -222,6 +222,7 @@ struct ppc_debug_info {
 #define PPC_DEBUG_FEATURE_DATA_BP_RANGE0x0004
 #define PPC_DEBUG_FEATURE_DATA_BP_MASK 0x0008
 #define PPC_DEBUG_FEATURE_DATA_BP_DAWR 0x0010
+#define PPC_DEBUG_FEATURE_DATA_BP_ARCH_31  0x0020
 
 #ifndef __ASSEMBLY__
 
diff --git a/arch/powerpc/kernel/ptrace/ptrace-noadv.c 
b/arch/powerpc/kernel/ptrace/ptrace-noadv.c
index 081c39842d84..1d0235db3c1b 100644
--- a/arch/powerpc/kernel/ptrace/ptrace-noadv.c
+++ b/arch/powerpc/kernel/ptrace/ptrace-noadv.c
@@ -57,6 +57,8 @@ void ppc_gethwdinfo(struct ppc_debug_info *dbginfo)
} else {
dbginfo->features = 0;
}
+   if (cpu_has_feature(CPU_FTR_ARCH_31))
+   dbginfo->features |= PPC_DEBUG_FEATURE_DATA_BP_ARCH_31;
 }
 
 int ptrace_get_debugreg(struct task_struct *child, unsigned long addr,
-- 
2.26.2



[PATCH v5 3/8] powerpc/watchpoint/ptrace: Fix SETHWDEBUG when CONFIG_HAVE_HW_BREAKPOINT=N

2020-08-24 Thread Ravi Bangoria
When kernel is compiled with CONFIG_HAVE_HW_BREAKPOINT=N, user can
still create watchpoint using PPC_PTRACE_SETHWDEBUG, with limited
functionalities. But, such watchpoints are never firing because of
the missing privilege settings. Fix that.

It's safe to set HW_BRK_TYPE_PRIV_ALL because we don't really leak
any kernel address in signal info. Setting HW_BRK_TYPE_PRIV_ALL will
also help to find scenarios when kernel corrupts user memory.

Reported-by: Pedro Miraglia Franco de Carvalho 
Suggested-by: Pedro Miraglia Franco de Carvalho 
Signed-off-by: Ravi Bangoria 
---
 arch/powerpc/kernel/ptrace/ptrace-noadv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/kernel/ptrace/ptrace-noadv.c 
b/arch/powerpc/kernel/ptrace/ptrace-noadv.c
index 697c7e4b5877..57a0ab822334 100644
--- a/arch/powerpc/kernel/ptrace/ptrace-noadv.c
+++ b/arch/powerpc/kernel/ptrace/ptrace-noadv.c
@@ -217,7 +217,7 @@ long ppc_set_hwdebug(struct task_struct *child, struct 
ppc_hw_breakpoint *bp_inf
return -EIO;
 
brk.address = ALIGN_DOWN(bp_info->addr, HW_BREAKPOINT_SIZE);
-   brk.type = HW_BRK_TYPE_TRANSLATE;
+   brk.type = HW_BRK_TYPE_TRANSLATE | HW_BRK_TYPE_PRIV_ALL;
brk.len = DABR_MAX_LEN;
if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ)
brk.type |= HW_BRK_TYPE_READ;
-- 
2.26.2



[PATCH v5 4/8] powerpc/watchpoint: Move DAWR detection logic outside of hw_breakpoint.c

2020-08-24 Thread Ravi Bangoria
Power10 hw has multiple DAWRs but hw doesn't tell which DAWR caused
the exception. So we have a sw logic to detect that in hw_breakpoint.c.
But hw_breakpoint.c gets compiled only with CONFIG_HAVE_HW_BREAKPOINT=Y.
Move DAWR detection logic outside of hw_breakpoint.c so that it can be
reused when CONFIG_HAVE_HW_BREAKPOINT is not set.

Signed-off-by: Ravi Bangoria 
---
 arch/powerpc/include/asm/hw_breakpoint.h  |   8 +
 arch/powerpc/kernel/Makefile  |   3 +-
 arch/powerpc/kernel/hw_breakpoint.c   | 159 +
 .../kernel/hw_breakpoint_constraints.c| 162 ++
 4 files changed, 174 insertions(+), 158 deletions(-)
 create mode 100644 arch/powerpc/kernel/hw_breakpoint_constraints.c

diff --git a/arch/powerpc/include/asm/hw_breakpoint.h 
b/arch/powerpc/include/asm/hw_breakpoint.h
index da38e05e04d9..2eca3dd54b55 100644
--- a/arch/powerpc/include/asm/hw_breakpoint.h
+++ b/arch/powerpc/include/asm/hw_breakpoint.h
@@ -10,6 +10,7 @@
 #define _PPC_BOOK3S_64_HW_BREAKPOINT_H
 
 #include 
+#include 
 
 #ifdef __KERNEL__
 struct arch_hw_breakpoint {
@@ -52,6 +53,13 @@ static inline int nr_wp_slots(void)
return cpu_has_feature(CPU_FTR_DAWR1) ? 2 : 1;
 }
 
+bool wp_check_constraints(struct pt_regs *regs, struct ppc_inst instr,
+ unsigned long ea, int type, int size,
+ struct arch_hw_breakpoint *info);
+
+void wp_get_instr_detail(struct pt_regs *regs, struct ppc_inst *instr,
+int *type, int *size, unsigned long *ea);
+
 #ifdef CONFIG_HAVE_HW_BREAKPOINT
 #include 
 #include 
diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
index cbf41fb4ee89..a5550c2b24c4 100644
--- a/arch/powerpc/kernel/Makefile
+++ b/arch/powerpc/kernel/Makefile
@@ -45,7 +45,8 @@ obj-y := cputable.o syscalls.o \
   signal.o sysfs.o cacheinfo.o time.o \
   prom.o traps.o setup-common.o \
   udbg.o misc.o io.o misc_$(BITS).o \
-  of_platform.o prom_parse.o firmware.o
+  of_platform.o prom_parse.o firmware.o \
+  hw_breakpoint_constraints.o
 obj-y  += ptrace/
 obj-$(CONFIG_PPC64)+= setup_64.o \
   paca.o nvram_64.o note.o syscall_64.o
diff --git a/arch/powerpc/kernel/hw_breakpoint.c 
b/arch/powerpc/kernel/hw_breakpoint.c
index f6b24838ca3c..f4e8f21046f5 100644
--- a/arch/powerpc/kernel/hw_breakpoint.c
+++ b/arch/powerpc/kernel/hw_breakpoint.c
@@ -494,161 +494,6 @@ void thread_change_pc(struct task_struct *tsk, struct 
pt_regs *regs)
}
 }
 
-static bool dar_in_user_range(unsigned long dar, struct arch_hw_breakpoint 
*info)
-{
-   return ((info->address <= dar) && (dar - info->address < info->len));
-}
-
-static bool ea_user_range_overlaps(unsigned long ea, int size,
-  struct arch_hw_breakpoint *info)
-{
-   return ((ea < info->address + info->len) &&
-   (ea + size > info->address));
-}
-
-static bool dar_in_hw_range(unsigned long dar, struct arch_hw_breakpoint *info)
-{
-   unsigned long hw_start_addr, hw_end_addr;
-
-   hw_start_addr = ALIGN_DOWN(info->address, HW_BREAKPOINT_SIZE);
-   hw_end_addr = ALIGN(info->address + info->len, HW_BREAKPOINT_SIZE);
-
-   return ((hw_start_addr <= dar) && (hw_end_addr > dar));
-}
-
-static bool ea_hw_range_overlaps(unsigned long ea, int size,
-struct arch_hw_breakpoint *info)
-{
-   unsigned long hw_start_addr, hw_end_addr;
-   unsigned long align_size = HW_BREAKPOINT_SIZE;
-
-   /*
-* On p10 predecessors, quadword is handle differently then
-* other instructions.
-*/
-   if (!cpu_has_feature(CPU_FTR_ARCH_31) && size == 16)
-   align_size = HW_BREAKPOINT_SIZE_QUADWORD;
-
-   hw_start_addr = ALIGN_DOWN(info->address, align_size);
-   hw_end_addr = ALIGN(info->address + info->len, align_size);
-
-   return ((ea < hw_end_addr) && (ea + size > hw_start_addr));
-}
-
-/*
- * If hw has multiple DAWR registers, we also need to check all
- * dawrx constraint bits to confirm this is _really_ a valid event.
- * If type is UNKNOWN, but privilege level matches, consider it as
- * a positive match.
- */
-static bool check_dawrx_constraints(struct pt_regs *regs, int type,
-   struct arch_hw_breakpoint *info)
-{
-   if (OP_IS_LOAD(type) && !(info->type & HW_BRK_TYPE_READ))
-   return false;
-
-   /*
-* The Cache Management instructions other than dcbz never
-* cause a match. i.e. if type is CACHEOP, the instruction
-* is dcbz, and dcbz is treated as Store.
-*/
-   if ((OP_IS_STORE(type) || type == CACHEOP) && !(info->type & 

[PATCH v5 5/8] powerpc/watchpoint: Fix exception handling for CONFIG_HAVE_HW_BREAKPOINT=N

2020-08-24 Thread Ravi Bangoria
On powerpc, ptrace watchpoint works in one-shot mode. i.e. kernel
disables event every time it fires and user has to re-enable it.
Also, in case of ptrace watchpoint, kernel notifies ptrace user
before executing instruction.

With CONFIG_HAVE_HW_BREAKPOINT=N, kernel is missing to disable
ptrace event and thus it's causing infinite loop of exceptions.
This is especially harmful when user watches on a data which is
also read/written by kernel, eg syscall parameters. In such case,
infinite exceptions happens in kernel mode which causes soft-lockup.

Fixes: 9422de3e953d ("powerpc: Hardware breakpoints rewrite to handle non DABR 
breakpoint registers")
Reported-by: Pedro Miraglia Franco de Carvalho 
Signed-off-by: Ravi Bangoria 
---
 arch/powerpc/include/asm/hw_breakpoint.h  |  3 ++
 arch/powerpc/kernel/process.c | 48 +++
 arch/powerpc/kernel/ptrace/ptrace-noadv.c |  5 +++
 3 files changed, 56 insertions(+)

diff --git a/arch/powerpc/include/asm/hw_breakpoint.h 
b/arch/powerpc/include/asm/hw_breakpoint.h
index 2eca3dd54b55..c72263214d3f 100644
--- a/arch/powerpc/include/asm/hw_breakpoint.h
+++ b/arch/powerpc/include/asm/hw_breakpoint.h
@@ -18,6 +18,7 @@ struct arch_hw_breakpoint {
u16 type;
u16 len; /* length of the target data symbol */
u16 hw_len; /* length programmed in hw */
+   u8  flags;
 };
 
 /* Note: Don't change the first 6 bits below as they are in the same order
@@ -37,6 +38,8 @@ struct arch_hw_breakpoint {
 #define HW_BRK_TYPE_PRIV_ALL   (HW_BRK_TYPE_USER | HW_BRK_TYPE_KERNEL | \
 HW_BRK_TYPE_HYP)
 
+#define HW_BRK_FLAG_DISABLED   0x1
+
 /* Minimum granularity */
 #ifdef CONFIG_PPC_8xx
 #define HW_BREAKPOINT_SIZE  0x4
diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 016bd831908e..160fbbf41d40 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -636,6 +636,44 @@ void do_send_trap(struct pt_regs *regs, unsigned long 
address,
(void __user *)address);
 }
 #else  /* !CONFIG_PPC_ADV_DEBUG_REGS */
+
+static void do_break_handler(struct pt_regs *regs)
+{
+   struct arch_hw_breakpoint null_brk = {0};
+   struct arch_hw_breakpoint *info;
+   struct ppc_inst instr = ppc_inst(0);
+   int type = 0;
+   int size = 0;
+   unsigned long ea;
+   int i;
+
+   /*
+* If underneath hw supports only one watchpoint, we know it
+* caused exception. 8xx also falls into this category.
+*/
+   if (nr_wp_slots() == 1) {
+   __set_breakpoint(0, _brk);
+   current->thread.hw_brk[0] = null_brk;
+   current->thread.hw_brk[0].flags |= HW_BRK_FLAG_DISABLED;
+   return;
+   }
+
+   /* Otherwise findout which DAWR caused exception and disable it. */
+   wp_get_instr_detail(regs, , , , );
+
+   for (i = 0; i < nr_wp_slots(); i++) {
+   info = >thread.hw_brk[i];
+   if (!info->address)
+   continue;
+
+   if (wp_check_constraints(regs, instr, ea, type, size, info)) {
+   __set_breakpoint(i, _brk);
+   current->thread.hw_brk[i] = null_brk;
+   current->thread.hw_brk[i].flags |= HW_BRK_FLAG_DISABLED;
+   }
+   }
+}
+
 void do_break (struct pt_regs *regs, unsigned long address,
unsigned long error_code)
 {
@@ -647,6 +685,16 @@ void do_break (struct pt_regs *regs, unsigned long address,
if (debugger_break_match(regs))
return;
 
+   /*
+* We reach here only when watchpoint exception is generated by ptrace
+* event (or hw is buggy!). Now if CONFIG_HAVE_HW_BREAKPOINT is set,
+* watchpoint is already handled by hw_breakpoint_handler() so we don't
+* have to do anything. But when CONFIG_HAVE_HW_BREAKPOINT is not set,
+* we need to manually handle the watchpoint here.
+*/
+   if (!IS_ENABLED(CONFIG_HAVE_HW_BREAKPOINT))
+   do_break_handler(regs);
+
/* Deliver the signal to userspace */
force_sig_fault(SIGTRAP, TRAP_HWBKPT, (void __user *)address);
 }
diff --git a/arch/powerpc/kernel/ptrace/ptrace-noadv.c 
b/arch/powerpc/kernel/ptrace/ptrace-noadv.c
index 57a0ab822334..866597b407bc 100644
--- a/arch/powerpc/kernel/ptrace/ptrace-noadv.c
+++ b/arch/powerpc/kernel/ptrace/ptrace-noadv.c
@@ -286,11 +286,16 @@ long ppc_del_hwdebug(struct task_struct *child, long data)
}
return ret;
 #else /* CONFIG_HAVE_HW_BREAKPOINT */
+   if (child->thread.hw_brk[data - 1].flags & HW_BRK_FLAG_DISABLED)
+   goto del;
+
if (child->thread.hw_brk[data - 1].address == 0)
return -ENOENT;
 
+del:
child->thread.hw_brk[data - 1].address = 0;
child->thread.hw_brk[data - 1].type = 0;
+   

[PATCH v5 6/8] powerpc/watchpoint: Add hw_len wherever missing

2020-08-24 Thread Ravi Bangoria
There are couple of places where we set len but not hw_len. For
ptrace/perf watchpoints, when CONFIG_HAVE_HW_BREAKPOINT=Y, hw_len
will be calculated and set internally while parsing watchpoint.
But when CONFIG_HAVE_HW_BREAKPOINT=N, we need to manually set
'hw_len'. Similarly for xmon as well, hw_len needs to be set
directly.

Fixes: b57aeab811db ("powerpc/watchpoint: Fix length calculation for unaligned 
target")
Signed-off-by: Ravi Bangoria 
---
 arch/powerpc/kernel/ptrace/ptrace-noadv.c | 1 +
 arch/powerpc/xmon/xmon.c  | 1 +
 2 files changed, 2 insertions(+)

diff --git a/arch/powerpc/kernel/ptrace/ptrace-noadv.c 
b/arch/powerpc/kernel/ptrace/ptrace-noadv.c
index 866597b407bc..081c39842d84 100644
--- a/arch/powerpc/kernel/ptrace/ptrace-noadv.c
+++ b/arch/powerpc/kernel/ptrace/ptrace-noadv.c
@@ -219,6 +219,7 @@ long ppc_set_hwdebug(struct task_struct *child, struct 
ppc_hw_breakpoint *bp_inf
brk.address = ALIGN_DOWN(bp_info->addr, HW_BREAKPOINT_SIZE);
brk.type = HW_BRK_TYPE_TRANSLATE | HW_BRK_TYPE_PRIV_ALL;
brk.len = DABR_MAX_LEN;
+   brk.hw_len = DABR_MAX_LEN;
if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ)
brk.type |= HW_BRK_TYPE_READ;
if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE)
diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c
index df7bca00f5ec..55c43a6c9111 100644
--- a/arch/powerpc/xmon/xmon.c
+++ b/arch/powerpc/xmon/xmon.c
@@ -969,6 +969,7 @@ static void insert_cpu_bpts(void)
brk.address = dabr[i].address;
brk.type = (dabr[i].enabled & HW_BRK_TYPE_DABR) | 
HW_BRK_TYPE_PRIV_ALL;
brk.len = 8;
+   brk.hw_len = 8;
__set_breakpoint(i, );
}
}
-- 
2.26.2



[PATCH v5 8/8] powerpc/watchpoint/selftests: Tests for kernel accessing user memory

2020-08-24 Thread Ravi Bangoria
Introduce tests to cover simple scenarios where user is watching
memory which can be accessed by kernel as well. We also support
_MODE_EXACT with _SETHWDEBUG interface. Move those testcases out-
side of _BP_RANGE condition. This will help to test _MODE_EXACT
scenarios when CONFIG_HAVE_HW_BREAKPOINT is not set, eg:

  $ ./ptrace-hwbreak
  ...
  PTRACE_SET_DEBUGREG, Kernel Access Userspace, len: 8: Ok
  PPC_PTRACE_SETHWDEBUG, MODE_EXACT, WO, len: 1: Ok
  PPC_PTRACE_SETHWDEBUG, MODE_EXACT, RO, len: 1: Ok
  PPC_PTRACE_SETHWDEBUG, MODE_EXACT, RW, len: 1: Ok
  PPC_PTRACE_SETHWDEBUG, MODE_EXACT, Kernel Access Userspace, len: 1: Ok
  success: ptrace-hwbreak

Suggested-by: Pedro Miraglia Franco de Carvalho 
Signed-off-by: Ravi Bangoria 
---
 .../selftests/powerpc/ptrace/ptrace-hwbreak.c | 48 ++-
 1 file changed, 46 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/powerpc/ptrace/ptrace-hwbreak.c 
b/tools/testing/selftests/powerpc/ptrace/ptrace-hwbreak.c
index fc477dfe86a2..2e0d86e0687e 100644
--- a/tools/testing/selftests/powerpc/ptrace/ptrace-hwbreak.c
+++ b/tools/testing/selftests/powerpc/ptrace/ptrace-hwbreak.c
@@ -20,6 +20,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include "ptrace.h"
 
 #define SPRN_PVR   0x11F
@@ -44,6 +46,7 @@ struct gstruct {
 };
 static volatile struct gstruct gstruct __attribute__((aligned(512)));
 
+static volatile char cwd[PATH_MAX] __attribute__((aligned(8)));
 
 static void get_dbginfo(pid_t child_pid, struct ppc_debug_info *dbginfo)
 {
@@ -138,6 +141,9 @@ static void test_workload(void)
write_var(len);
}
 
+   /* PTRACE_SET_DEBUGREG, Kernel Access Userspace test */
+   syscall(__NR_getcwd, , PATH_MAX);
+
/* PPC_PTRACE_SETHWDEBUG, MODE_EXACT, WO test */
write_var(1);
 
@@ -150,6 +156,9 @@ static void test_workload(void)
else
read_var(1);
 
+   /* PPC_PTRACE_SETHWDEBUG, MODE_EXACT, Kernel Access Userspace test */
+   syscall(__NR_getcwd, , PATH_MAX);
+
/* PPC_PTRACE_SETHWDEBUG, MODE_RANGE, DW ALIGNED, WO test */
gstruct.a[rand() % A_LEN] = 'a';
 
@@ -293,6 +302,24 @@ static int test_set_debugreg(pid_t child_pid)
return 0;
 }
 
+static int test_set_debugreg_kernel_userspace(pid_t child_pid)
+{
+   unsigned long wp_addr = (unsigned long)cwd;
+   char *name = "PTRACE_SET_DEBUGREG";
+
+   /* PTRACE_SET_DEBUGREG, Kernel Access Userspace test */
+   wp_addr &= ~0x7UL;
+   wp_addr |= (1Ul << DABR_READ_SHIFT);
+   wp_addr |= (1UL << DABR_WRITE_SHIFT);
+   wp_addr |= (1UL << DABR_TRANSLATION_SHIFT);
+   ptrace_set_debugreg(child_pid, wp_addr);
+   ptrace(PTRACE_CONT, child_pid, NULL, 0);
+   check_success(child_pid, name, "Kernel Access Userspace", wp_addr, 8);
+
+   ptrace_set_debugreg(child_pid, 0);
+   return 0;
+}
+
 static void get_ppc_hw_breakpoint(struct ppc_hw_breakpoint *info, int type,
  unsigned long addr, int len)
 {
@@ -338,6 +365,22 @@ static void test_sethwdebug_exact(pid_t child_pid)
ptrace_delhwdebug(child_pid, wh);
 }
 
+static void test_sethwdebug_exact_kernel_userspace(pid_t child_pid)
+{
+   struct ppc_hw_breakpoint info;
+   unsigned long wp_addr = (unsigned long)
+   char *name = "PPC_PTRACE_SETHWDEBUG, MODE_EXACT";
+   int len = 1; /* hardcoded in kernel */
+   int wh;
+
+   /* PPC_PTRACE_SETHWDEBUG, MODE_EXACT, Kernel Access Userspace test */
+   get_ppc_hw_breakpoint(, PPC_BREAKPOINT_TRIGGER_WRITE, wp_addr, 0);
+   wh = ptrace_sethwdebug(child_pid, );
+   ptrace(PTRACE_CONT, child_pid, NULL, 0);
+   check_success(child_pid, name, "Kernel Access Userspace", wp_addr, len);
+   ptrace_delhwdebug(child_pid, wh);
+}
+
 static void test_sethwdebug_range_aligned(pid_t child_pid)
 {
struct ppc_hw_breakpoint info;
@@ -452,9 +495,10 @@ static void
 run_tests(pid_t child_pid, struct ppc_debug_info *dbginfo, bool dawr)
 {
test_set_debugreg(child_pid);
+   test_set_debugreg_kernel_userspace(child_pid);
+   test_sethwdebug_exact(child_pid);
+   test_sethwdebug_exact_kernel_userspace(child_pid);
if (dbginfo->features & PPC_DEBUG_FEATURE_DATA_BP_RANGE) {
-   test_sethwdebug_exact(child_pid);
-
test_sethwdebug_range_aligned(child_pid);
if (dawr || is_8xx) {
test_sethwdebug_range_unaligned(child_pid);
-- 
2.26.2



[PATCH v5 2/8] powerpc/watchpoint: Fix handling of vector instructions

2020-08-24 Thread Ravi Bangoria
Vector instructions are special because they are always aligned.
Thus unaligned EA needs to be aligned down before comparing it
with watch ranges. Otherwise we might consider valid event as
invalid.

Fixes: 74c6881019b7 ("powerpc/watchpoint: Prepare handler to handle more than 
one watchpoint")
Signed-off-by: Ravi Bangoria 
---
 arch/powerpc/kernel/hw_breakpoint.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/powerpc/kernel/hw_breakpoint.c 
b/arch/powerpc/kernel/hw_breakpoint.c
index 9f7df1c37233..f6b24838ca3c 100644
--- a/arch/powerpc/kernel/hw_breakpoint.c
+++ b/arch/powerpc/kernel/hw_breakpoint.c
@@ -644,6 +644,8 @@ static void get_instr_detail(struct pt_regs *regs, struct 
ppc_inst *instr,
if (*type == CACHEOP) {
*size = cache_op_size();
*ea &= ~(*size - 1);
+   } else if (*type == LOAD_VMX || *type == STORE_VMX) {
+   *ea &= ~(*size - 1);
}
 }
 
-- 
2.26.2



[PATCH v5 1/8] powerpc/watchpoint: Fix quarword instruction handling on p10 predecessors

2020-08-24 Thread Ravi Bangoria
On p10 predecessors, watchpoint with quarword access is compared at
quardword length. If the watch range is doubleword or less than that
in a first half of quarword aligned 16 bytes, and if there is any
unaligned quadword access which will access only the 2nd half, the
handler should consider it as extraneous and emulate/single-step it
before continuing.

Reported-by: Pedro Miraglia Franco de Carvalho 
Fixes: 74c6881019b7 ("powerpc/watchpoint: Prepare handler to handle more than 
one watchpoint")
Signed-off-by: Ravi Bangoria 
---
 arch/powerpc/include/asm/hw_breakpoint.h |  3 ++-
 arch/powerpc/kernel/hw_breakpoint.c  | 12 ++--
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/include/asm/hw_breakpoint.h 
b/arch/powerpc/include/asm/hw_breakpoint.h
index db206a7f38e2..da38e05e04d9 100644
--- a/arch/powerpc/include/asm/hw_breakpoint.h
+++ b/arch/powerpc/include/asm/hw_breakpoint.h
@@ -40,7 +40,8 @@ struct arch_hw_breakpoint {
 #ifdef CONFIG_PPC_8xx
 #define HW_BREAKPOINT_SIZE  0x4
 #else
-#define HW_BREAKPOINT_SIZE  0x8
+#define HW_BREAKPOINT_SIZE 0x8
+#define HW_BREAKPOINT_SIZE_QUADWORD0x10
 #endif
 
 #define DABR_MAX_LEN   8
diff --git a/arch/powerpc/kernel/hw_breakpoint.c 
b/arch/powerpc/kernel/hw_breakpoint.c
index 1f4a1efa0074..9f7df1c37233 100644
--- a/arch/powerpc/kernel/hw_breakpoint.c
+++ b/arch/powerpc/kernel/hw_breakpoint.c
@@ -520,9 +520,17 @@ static bool ea_hw_range_overlaps(unsigned long ea, int 
size,
 struct arch_hw_breakpoint *info)
 {
unsigned long hw_start_addr, hw_end_addr;
+   unsigned long align_size = HW_BREAKPOINT_SIZE;
 
-   hw_start_addr = ALIGN_DOWN(info->address, HW_BREAKPOINT_SIZE);
-   hw_end_addr = ALIGN(info->address + info->len, HW_BREAKPOINT_SIZE);
+   /*
+* On p10 predecessors, quadword is handle differently then
+* other instructions.
+*/
+   if (!cpu_has_feature(CPU_FTR_ARCH_31) && size == 16)
+   align_size = HW_BREAKPOINT_SIZE_QUADWORD;
+
+   hw_start_addr = ALIGN_DOWN(info->address, align_size);
+   hw_end_addr = ALIGN(info->address + info->len, align_size);
 
return ((ea < hw_end_addr) && (ea + size > hw_start_addr));
 }
-- 
2.26.2



[PATCH v5 0/8] powerpc/watchpoint: Bug fixes plus new feature flag

2020-08-24 Thread Ravi Bangoria
Patch #1 fixes issue for quardword instruction on p10 predecessors.
Patch #2 fixes issue for vector instructions.
Patch #3 fixes a bug about watchpoint not firing when created with
 ptrace PPC_PTRACE_SETHWDEBUG and CONFIG_HAVE_HW_BREAKPOINT=N.
 The fix uses HW_BRK_TYPE_PRIV_ALL for ptrace user which, I
 guess, should be fine because we don't leak any kernel
 addresses and PRIV_ALL will also help to cover scenarios when
 kernel accesses user memory.
Patch #4,#5 fixes infinite exception bug, again the bug happens only
 with CONFIG_HAVE_HW_BREAKPOINT=N.
Patch #6 fixes two places where we are missing to set hw_len.
Patch #7 introduce new feature bit PPC_DEBUG_FEATURE_DATA_BP_ARCH_31
 which will be set when running on ISA 3.1 compliant machine.
Patch #8 finally adds selftest to test scenarios fixed by patch#2,#3
 and also moves MODE_EXACT tests outside of BP_RANGE condition.

Christophe, let me know if this series breaks something for 8xx.

v4: 
https://lore.kernel.org/r/20200817102330.777537-1-ravi.bango...@linux.ibm.com/

v4->v5:
 - Patch #1 and #2 are new. These bug happen irrespective of
   CONFIG_HAVE_HW_BREAKPOINT.
 - Patch #3 to #8 are carry forwarded from v4
 - Rebased to powerpc/next

Ravi Bangoria (8):
  powerpc/watchpoint: Fix quarword instruction handling on p10
predecessors
  powerpc/watchpoint: Fix handling of vector instructions
  powerpc/watchpoint/ptrace: Fix SETHWDEBUG when
CONFIG_HAVE_HW_BREAKPOINT=N
  powerpc/watchpoint: Move DAWR detection logic outside of
hw_breakpoint.c
  powerpc/watchpoint: Fix exception handling for
CONFIG_HAVE_HW_BREAKPOINT=N
  powerpc/watchpoint: Add hw_len wherever missing
  powerpc/watchpoint/ptrace: Introduce PPC_DEBUG_FEATURE_DATA_BP_ARCH_31
  powerpc/watchpoint/selftests: Tests for kernel accessing user memory

 Documentation/powerpc/ptrace.rst  |   1 +
 arch/powerpc/include/asm/hw_breakpoint.h  |  14 +-
 arch/powerpc/include/uapi/asm/ptrace.h|   1 +
 arch/powerpc/kernel/Makefile  |   3 +-
 arch/powerpc/kernel/hw_breakpoint.c   | 149 +---
 .../kernel/hw_breakpoint_constraints.c| 162 ++
 arch/powerpc/kernel/process.c |  48 ++
 arch/powerpc/kernel/ptrace/ptrace-noadv.c |  10 +-
 arch/powerpc/xmon/xmon.c  |   1 +
 .../selftests/powerpc/ptrace/ptrace-hwbreak.c |  48 +-
 10 files changed, 285 insertions(+), 152 deletions(-)
 create mode 100644 arch/powerpc/kernel/hw_breakpoint_constraints.c

-- 
2.26.2



[tip:x86/fsgsbase] BUILD SUCCESS 5f1dd4dda5c8796c405e856aaa11e187f6885924

2020-08-24 Thread kernel test robot
tree/branch: https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git  
x86/fsgsbase
branch HEAD: 5f1dd4dda5c8796c405e856aaa11e187f6885924  x86/fsgsbase: Replace 
static_cpu_has() with boot_cpu_has()

elapsed time: 721m

configs tested: 74
configs skipped: 52

The following configs have been built successfully.
More configs may be tested in the coming days.

arm defconfig
arm64allyesconfig
arm64   defconfig
arm  allyesconfig
arm  allmodconfig
armzeus_defconfig
arm  zx_defconfig
arc  alldefconfig
arm  badge4_defconfig
sh  sdk7780_defconfig
sh  r7785rp_defconfig
arm rpc_defconfig
h8300h8300h-sim_defconfig
ia64 allmodconfig
ia64defconfig
ia64 allyesconfig
m68k allmodconfig
m68kdefconfig
m68k allyesconfig
nios2   defconfig
arc  allyesconfig
nds32 allnoconfig
c6x  allyesconfig
nds32   defconfig
nios2allyesconfig
cskydefconfig
alpha   defconfig
alphaallyesconfig
xtensa   allyesconfig
h8300allyesconfig
arc defconfig
sh   allmodconfig
parisc  defconfig
s390 allyesconfig
parisc   allyesconfig
s390defconfig
i386 allyesconfig
sparcallyesconfig
sparc   defconfig
i386defconfig
mips allyesconfig
mips allmodconfig
powerpc defconfig
powerpc  allyesconfig
powerpc  allmodconfig
powerpc   allnoconfig
i386 randconfig-a002-20200824
i386 randconfig-a004-20200824
i386 randconfig-a005-20200824
i386 randconfig-a003-20200824
i386 randconfig-a006-20200824
i386 randconfig-a001-20200824
x86_64   randconfig-a015-20200824
x86_64   randconfig-a016-20200824
x86_64   randconfig-a012-20200824
x86_64   randconfig-a014-20200824
x86_64   randconfig-a011-20200824
x86_64   randconfig-a013-20200824
i386 randconfig-a013-20200824
i386 randconfig-a012-20200824
i386 randconfig-a011-20200824
i386 randconfig-a016-20200824
i386 randconfig-a015-20200824
i386 randconfig-a014-20200824
riscvallyesconfig
riscv allnoconfig
riscv   defconfig
riscvallmodconfig
x86_64   rhel
x86_64   allyesconfig
x86_64rhel-7.6-kselftests
x86_64  defconfig
x86_64   rhel-8.3
x86_64  kexec

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-...@lists.01.org


Re: [PATCH 9/9] iomap: Change calling convention for zeroing

2020-08-24 Thread Dave Chinner
On Mon, Aug 24, 2020 at 09:35:59PM -0600, Andreas Dilger wrote:
> On Aug 24, 2020, at 9:26 PM, Matthew Wilcox  wrote:
> > 
> > On Tue, Aug 25, 2020 at 10:27:35AM +1000, Dave Chinner wrote:
> >>>   do {
> >>> - unsigned offset, bytes;
> >>> -
> >>> - offset = offset_in_page(pos);
> >>> - bytes = min_t(loff_t, PAGE_SIZE - offset, count);
> >>> + loff_t bytes;
> >>> 
> >>>   if (IS_DAX(inode))
> >>> - status = dax_iomap_zero(pos, offset, bytes, iomap);
> >>> + bytes = dax_iomap_zero(pos, length, iomap);
> >> 
> >> Hmmm. everything is loff_t here, but the callers are defining length
> >> as u64, not loff_t. Is there a potential sign conversion problem
> >> here? (sure 64 bit is way beyond anything we'll pass here, but...)
> > 
> > I've gone back and forth on the correct type for 'length' a few times.
> > size_t is too small (not for zeroing, but for seek()).  An unsigned type
> > seems right -- a length can't be negative, and we don't want to give
> > the impression that it can.  But the return value from these functions
> > definitely needs to be signed so we can represent an error.  So a u64
> > length with an loff_t return type feels like the best solution.  And
> > the upper layers have to promise not to pass in a length that's more
> > than 2^63-1.
> 
> The problem with allowing a u64 as the length is that it leads to the
> possibility of an argument value that cannot be returned.  Checking
> length < 0 is not worse than checking length > 0x7ff,
> and has the benefit of consistency with the other argument types and
> signs...

I think the problem here is that we have no guaranteed 64 bit size
type. when that was the case with off_t, we created loff_t to always
represent a 64 bit offset value. However, we never created one for
the count/size that is passed alongside loff_t in many places - it
was said that "syscalls are limited to 32 bit sizes" and
"size_t is 64 bit on 64 bit platforms" and so on and so we still
don't have a clean way to pass 64 bit sizes through the IO path.

We've been living with this shitty situation for a long time now, so
perhaps it's time for us to define lsize_t for 64 bit lengths and
start using that everywhere that needs a 64 bit clean path
through the code, regardless of whether the arch is 32 or 64 bit...

Thoughts?

-Dave.

-- 
Dave Chinner
da...@fromorbit.com


Re: [PATCH - stable v5.4 and v5.7] opp: Enable resources again if they were disabled earlier

2020-08-24 Thread Viresh Kumar
On 24-08-20, 18:10, Greg KH wrote:
> On Mon, Aug 24, 2020 at 02:52:23PM +0530, Viresh Kumar wrote:
> > From: Rajendra Nayak 
> > 
> > commit a4501bac0e553bed117b7e1b166d49731caf7260 upstream.
> > 
> > dev_pm_opp_set_rate() can now be called with freq = 0 in order
> > to either drop performance or bandwidth votes or to disable
> > regulators on platforms which support them.
> > 
> > In such cases, a subsequent call to dev_pm_opp_set_rate() with
> > the same frequency ends up returning early because 'old_freq == freq'
> > 
> > Instead make it fall through and put back the dropped performance
> > and bandwidth votes and/or enable back the regulators.
> > 
> > Cc: v5.3+  # v5.3+
> > Fixes: cd7ea582866f ("opp: Make dev_pm_opp_set_rate() handle freq = 0 to 
> > drop performance votes")
> > Reported-by: Sajida Bhanu 
> > Reviewed-by: Sibi Sankar 
> > Reported-by: Matthias Kaehlcke 
> > Tested-by: Matthias Kaehlcke 
> > Reviewed-by: Stephen Boyd 
> > Signed-off-by: Rajendra Nayak 
> > [ Viresh: Don't skip clk_set_rate() and massaged changelog ]
> > Signed-off-by: Viresh Kumar 
> > [ Viresh: Updated the patch to apply to v5.4 ]
> > Signed-off-by: Viresh Kumar 
> > ---
> >  drivers/opp/core.c | 10 ++
> >  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> This too is already in the 5.7 and 5.4 queues, why add it again?

Same here, your bot reported that patch failed to apply for 5.4 and 5.7, again
rightly so as I was required to modify the patch a little bit and so I have
added another signed-off and details.

-- 
viresh


Re: [PATCH - for v5.7 stable] opp: Put opp table in dev_pm_opp_set_rate() for empty tables

2020-08-24 Thread Viresh Kumar
On 24-08-20, 18:10, Greg KH wrote:
> On Mon, Aug 24, 2020 at 03:00:03PM +0530, Viresh Kumar wrote:
> > From: Stephen Boyd 
> > 
> > commit 8979ef70850eb469e1094279259d1ef393ffe85f upstream.
> > 
> > We get the opp_table pointer at the top of the function and so we should
> > put the pointer at the end of the function like all other exit paths
> > from this function do.
> > 
> > Cc: v5.7+  # v5.7+
> > Fixes: aca48b61f963 ("opp: Manage empty OPP tables with clk handle")
> > Reviewed-by: Rajendra Nayak 
> > Signed-off-by: Stephen Boyd 
> > [ Viresh: Split the patch into two ]
> > Signed-off-by: Viresh Kumar 
> > [ Viresh: Update the code for v5.7-stable ]
> > Signed-off-by: Viresh Kumar 
> > ---
> >  drivers/opp/core.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> This is already in the 5.7-stable queue, why add it again?
> 
> confused,

Because I received an email from your bot that it failed to apply to 5.7 stable,
rightly so as the patch was required to be modified.

-- 
viresh


[PATCH 05/14 v5] usb: typec: tcpci: Add set_vbus tcpci callback

2020-08-24 Thread Badhri Jagan Sridharan
set_vbus callback allows TCPC which are TCPCI based, however,
does not support turning on sink and source mode through
Command.SinkVbus and Command.SourceVbusDefaultVoltage.

Signed-off-by: Badhri Jagan Sridharan 
---
 drivers/usb/typec/tcpm/tcpci.c | 7 +++
 drivers/usb/typec/tcpm/tcpci.h | 1 +
 2 files changed, 8 insertions(+)

diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c
index 7b7991c8ac87..89d28e3fbee8 100644
--- a/drivers/usb/typec/tcpm/tcpci.c
+++ b/drivers/usb/typec/tcpm/tcpci.c
@@ -328,6 +328,13 @@ static int tcpci_set_vbus(struct tcpc_dev *tcpc, bool 
source, bool sink)
struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
int ret;
 
+   if (tcpci->data->set_vbus) {
+   ret = tcpci->data->set_vbus(tcpci, tcpci->data, source, sink);
+   /* Bypass when ret > 0 */
+   if (ret != 0)
+   return ret < 0 ? ret : 0;
+   }
+
/* Disable both source and sink first before enabling anything */
 
if (!source) {
diff --git a/drivers/usb/typec/tcpm/tcpci.h b/drivers/usb/typec/tcpm/tcpci.h
index 04c49a0b0368..4d441bdf24d5 100644
--- a/drivers/usb/typec/tcpm/tcpci.h
+++ b/drivers/usb/typec/tcpm/tcpci.h
@@ -144,6 +144,7 @@ struct tcpci_data {
 bool enable);
int (*start_drp_toggling)(struct tcpci *tcpci, struct tcpci_data *data,
  enum typec_cc_status cc);
+   int (*set_vbus)(struct tcpci *tcpci, struct tcpci_data *data, bool 
source, bool sink);
 };
 
 struct tcpci *tcpci_register_port(struct device *dev, struct tcpci_data *data);
-- 
2.28.0.297.g1956fa8f8d-goog



[PATCH 07/14 v1] usb: typec: tcpci_maxim: Chip level TCPC driver

2020-08-24 Thread Badhri Jagan Sridharan
Chip level TCPC driver for Maxim's TCPCI implementation.
This TCPC implementation does not support the following
commands: COMMAND.SinkVbus, COMMAND.SourceVbusDefaultVoltage,
COMMAND.SourceVbusHighVoltage. Instead the sinking and sourcing
from vbus is supported by writes to custom registers.

Signed-off-by: Badhri Jagan Sridharan 
---
 drivers/usb/typec/tcpm/Kconfig   |   6 +
 drivers/usb/typec/tcpm/Makefile  |  13 +-
 drivers/usb/typec/tcpm/tcpci.h   |   1 +
 drivers/usb/typec/tcpm/tcpci_maxim.c | 474 +++
 4 files changed, 488 insertions(+), 6 deletions(-)
 create mode 100644 drivers/usb/typec/tcpm/tcpci_maxim.c

diff --git a/drivers/usb/typec/tcpm/Kconfig b/drivers/usb/typec/tcpm/Kconfig
index fa3f39336246..7c9722b02afe 100644
--- a/drivers/usb/typec/tcpm/Kconfig
+++ b/drivers/usb/typec/tcpm/Kconfig
@@ -27,6 +27,12 @@ config TYPEC_RT1711H
  Type-C Port Controller Manager to provide USB PD and USB
  Type-C functionalities.
 
+config TYPEC_TCPCI_MAXIM
+   tristate "Maxim TCPCI based Type-C chip driver"
+   select USB_PSY
+   help
+ MAXIM TCPCI based Type-C chip driver
+
 endif # TYPEC_TCPCI
 
 config TYPEC_FUSB302
diff --git a/drivers/usb/typec/tcpm/Makefile b/drivers/usb/typec/tcpm/Makefile
index a5ff6c8eb892..58d001cf0dd2 100644
--- a/drivers/usb/typec/tcpm/Makefile
+++ b/drivers/usb/typec/tcpm/Makefile
@@ -1,7 +1,8 @@
 # SPDX-License-Identifier: GPL-2.0
-obj-$(CONFIG_TYPEC_TCPM)   += tcpm.o
-obj-$(CONFIG_TYPEC_FUSB302)+= fusb302.o
-obj-$(CONFIG_TYPEC_WCOVE)  += typec_wcove.o
-typec_wcove-y  := wcove.o
-obj-$(CONFIG_TYPEC_TCPCI)  += tcpci.o
-obj-$(CONFIG_TYPEC_RT1711H)+= tcpci_rt1711h.o
+obj-$(CONFIG_TYPEC_TCPM)   += tcpm.o
+obj-$(CONFIG_TYPEC_FUSB302)+= fusb302.o
+obj-$(CONFIG_TYPEC_WCOVE)  += typec_wcove.o
+typec_wcove-y  := wcove.o
+obj-$(CONFIG_TYPEC_TCPCI)  += tcpci.o
+obj-$(CONFIG_TYPEC_RT1711H)+= tcpci_rt1711h.o
+obj-$(CONFIG_TYPEC_TCPCI_MAXIM)+= tcpci_maxim.o
diff --git a/drivers/usb/typec/tcpm/tcpci.h b/drivers/usb/typec/tcpm/tcpci.h
index 4d441bdf24d5..82f021a82456 100644
--- a/drivers/usb/typec/tcpm/tcpci.h
+++ b/drivers/usb/typec/tcpm/tcpci.h
@@ -109,6 +109,7 @@
 
 #define TCPC_RX_BYTE_CNT   0x30
 #define TCPC_RX_BUF_FRAME_TYPE 0x31
+#define TCPC_RX_BUF_FRAME_TYPE_SOP 0
 #define TCPC_RX_HDR0x32
 #define TCPC_RX_DATA   0x34 /* through 0x4f */
 
diff --git a/drivers/usb/typec/tcpm/tcpci_maxim.c 
b/drivers/usb/typec/tcpm/tcpci_maxim.c
new file mode 100644
index ..b61f290a8f96
--- /dev/null
+++ b/drivers/usb/typec/tcpm/tcpci_maxim.c
@@ -0,0 +1,474 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020, Google LLC
+ *
+ * MAXIM TCPCI based TCPC driver
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "tcpci.h"
+
+#define PD_ACTIVITY_TIMEOUT_MS 1
+
+#define TCPC_VENDOR_ALERT  0x80
+
+#define TCPC_RECEIVE_BUFFER_COUNT_OFFSET   0
+#define TCPC_RECEIVE_BUFFER_FRAME_TYPE_OFFSET  1
+#define TCPC_RECEIVE_BUFFER_RX_BYTE_BUF_OFFSET 2
+
+/*
+ * LongMessage not supported, hence 32 bytes for buf to be read from 
RECEIVE_BUFFER.
+ * DEVICE_CAPABILITIES_2.LongMessage = 0, the value in READABLE_BYTE_COUNT reg 
shall be
+ * less than or equal to 31. Since, RECEIVE_BUFFER len = 31 + 
1(READABLE_BYTE_COUNT).
+ */
+#define TCPC_RECEIVE_BUFFER_LEN32
+
+#define MAX_BUCK_BOOST_SID 0x69
+#define MAX_BUCK_BOOST_OP  0xb9
+#define MAX_BUCK_BOOST_OFF 0
+#define MAX_BUCK_BOOST_SOURCE  0xa
+#define MAX_BUCK_BOOST_SINK0x5
+
+struct max_tcpci_chip {
+   struct tcpci_data data;
+   struct tcpci *tcpci;
+   struct device *dev;
+   struct i2c_client *client;
+   struct tcpm_port *port;
+};
+
+static const struct regmap_range max_tcpci_tcpci_range[] = {
+   regmap_reg_range(0x00, 0x95)
+};
+
+const struct regmap_access_table max_tcpci_tcpci_write_table = {
+   .yes_ranges = max_tcpci_tcpci_range,
+   .n_yes_ranges = ARRAY_SIZE(max_tcpci_tcpci_range),
+};
+
+static const struct regmap_config max_tcpci_regmap_config = {
+   .reg_bits = 8,
+   .val_bits = 8,
+   .max_register = 0x95,
+   .wr_table = _tcpci_tcpci_write_table,
+};
+
+static struct max_tcpci_chip *tdata_to_max_tcpci(struct tcpci_data *tdata)
+{
+   return container_of(tdata, struct max_tcpci_chip, data);
+}
+
+static int max_tcpci_read16(struct max_tcpci_chip *chip, unsigned int reg, u16 
*val)
+{
+   return regmap_raw_read(chip->data.regmap, reg, val, sizeof(u16));
+}
+
+static int 

[PATCH 13/14 v1] usb: typec: tcpci: Implement Auto discharge disconnect callbacks

2020-08-24 Thread Badhri Jagan Sridharan
Implement callbacks for enabling/disabling
POWER_CONTROL.AutoDischargeDisconnect.

TCPCI spec allows TCPC hardware to autonomously discharge the vbus
capacitance upon disconnect. The expectation is that the TCPM enables
AutoDischargeDisconnect while entering SNK/SRC_ATTACHED states. Hardware
then automously discharges vbus when the vbus falls below a certain
threshold i.e. VBUS_SINK_DISCONNECT_THRESHOLD.

Apart from enabling the vbus discharge circuit, AutoDischargeDisconnect
is also used a flag to move TCPCI based TCPC implementations into
Attached.Snk/Attached.Src state as mentioned in
Figure 4-15. TCPC State Diagram before a Connection of the
USB Type-C Port Controller Interface Specification.
In such TCPC implementations, setting AutoDischargeDisconnect would
prevent TCPC into entering "Connection_Invalid" state as well.

Signed-off-by: Badhri Jagan Sridharan 
---
 drivers/usb/typec/tcpm/tcpci.c | 33 +
 drivers/usb/typec/tcpm/tcpci.h | 22 --
 2 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c
index 13d2e1c2ff20..e876f13ddf31 100644
--- a/drivers/usb/typec/tcpm/tcpci.c
+++ b/drivers/usb/typec/tcpm/tcpci.c
@@ -268,6 +268,33 @@ static int tcpci_set_vconn(struct tcpc_dev *tcpc, bool 
enable)
enable ? TCPC_POWER_CTRL_VCONN_ENABLE : 0);
 }
 
+static int tcpci_enable_auto_vbus_discharge(struct tcpc_dev *dev, bool enable)
+{
+   struct tcpci *tcpci = tcpc_to_tcpci(dev);
+   int ret;
+
+   ret = regmap_update_bits(tcpci->regmap, TCPC_POWER_CTRL, 
TCPC_POWER_CTRL_AUTO_DISCHARGE,
+enable ? TCPC_POWER_CTRL_AUTO_DISCHARGE : 0);
+   return ret;
+}
+
+static int tcpci_set_auto_vbus_discharge_threshold(struct tcpc_dev *dev, enum 
typec_role port_role,
+  enum typec_pwr_opmode mode, 
bool pps_active,
+  u32 requested_vbus_voltage)
+{
+   struct tcpci *tcpci = tcpc_to_tcpci(dev);
+   int (*set_auto_vbus_threshold)(struct tcpci *tcpci, struct tcpci_data 
*data,
+  enum typec_role port_role, enum 
typec_pwr_opmode mode,
+  bool pps_active, u32 
requested_vbus_voltage);
+
+   set_auto_vbus_threshold = 
tcpci->data->set_auto_vbus_discharge_threshold;
+   if (set_auto_vbus_threshold)
+   return set_auto_vbus_threshold(tcpci, tcpci->data, port_role, 
mode, pps_active,
+  requested_vbus_voltage);
+
+   return 0;
+}
+
 static int tcpci_enable_frs(struct tcpc_dev *dev, bool enable)
 {
struct tcpci *tcpci = tcpc_to_tcpci(dev);
@@ -628,6 +655,12 @@ struct tcpci *tcpci_register_port(struct device *dev, 
struct tcpci_data *data)
tcpci->tcpc.set_bist_data = tcpci_set_bist_data;
tcpci->tcpc.enable_frs = tcpci_enable_frs;
 
+   if (tcpci->data->auto_discharge_disconnect) {
+   tcpci->tcpc.enable_auto_vbus_discharge = 
tcpci_enable_auto_vbus_discharge;
+   tcpci->tcpc.set_auto_vbus_discharge_threshold =
+   tcpci_set_auto_vbus_discharge_threshold;
+   }
+
err = tcpci_parse_config(tcpci);
if (err < 0)
return ERR_PTR(err);
diff --git a/drivers/usb/typec/tcpm/tcpci.h b/drivers/usb/typec/tcpm/tcpci.h
index 5ef07a56d67a..6a0aea34e544 100644
--- a/drivers/usb/typec/tcpm/tcpci.h
+++ b/drivers/usb/typec/tcpm/tcpci.h
@@ -8,6 +8,8 @@
 #ifndef __LINUX_USB_TCPCI_H
 #define __LINUX_USB_TCPCI_H
 
+#include 
+
 #define TCPC_VENDOR_ID 0x0
 #define TCPC_PRODUCT_ID0x2
 #define TCPC_BCD_DEV   0x4
@@ -67,6 +69,7 @@
 
 #define TCPC_POWER_CTRL0x1c
 #define TCPC_POWER_CTRL_VCONN_ENABLE   BIT(0)
+#define TCPC_POWER_CTRL_AUTO_DISCHARGE BIT(4)
 #define TCPC_FAST_ROLE_SWAP_EN BIT(7)
 
 #define TCPC_CC_STATUS 0x1d
@@ -133,6 +136,8 @@
 
 #define TCPC_VBUS_VOLTAGE  0x70
 #define TCPC_VBUS_SINK_DISCONNECT_THRESH   0x72
+#define TCPC_VBUS_SINK_DISCONNECT_THRESH_LSB   25
+#define TCPC_VBUS_SINK_DISCONNECT_THRESH_MAX   1023
 #define TCPC_VBUS_STOP_DISCHARGE_THRESH0x74
 #define TCPC_VBUS_VOLTAGE_ALARM_HI_CFG 0x76
 #define TCPC_VBUS_VOLTAGE_ALARM_LO_CFG 0x78
@@ -140,20 +145,33 @@
 /* I2C_WRITE_BYTE_COUNT + 1 when TX_BUF_BYTE_x is only accessible 
I2C_WRITE_BYTE_COUNT */
 #define TCPC_TRANSMIT_BUFFER_MAX_LEN   31
 
+struct tcpci;
+
 /*
- * @TX_BUF_BYTE_x_hidden
+ * @TX_BUF_BYTE_x_hidden:
  * optional; Set when TX_BUF_BYTE_x can only be accessed through 
I2C_WRITE_BYTE_COUNT.
+ * @auto_discharge_disconnect:
+ * Optional; Enables TCPC to autonously discharge vbus on 
disconnect.
+ * @set_auto_vbus_discharge_threshold:
+ * 

[PATCH 09/14 v1] usb: typec: tcpm: Add support for Sink Fast Role SWAP(FRS)

2020-08-24 Thread Badhri Jagan Sridharan
PD 3.0 spec defines a new mechanism for power role swap called
Fast role swap. This change enables TCPM to support FRS when
acting as sink.

Once the explicit contract is negotiated, sink port is
expected to query the source port for sink caps to
determine whether the source is FRS capable.
Bits 23 & 24 of fixed pdo of the sink caps from the source, when
set, indicates the current needed by the source when fast role
swap is in progress(Implicit contract phasae). 0 indicates that
the source does not support Fast Role Swap.

Upon receiving the FRS signal from the source,
TCPC(TCPM_FRS_EVENT) informs TCPM to start the Fast role swap sequence.

1. TCPM sends FRS PD message: FR_SWAP_SEND
2. If response is not received within the expiry of
   SenderResponseTimer, Error recovery is triggered.:
   FR_SWAP_SEND_TIMEOUT
3. Upon receipt of the accept message, TCPM waits for
   PSSourceOffTimer for PS_READY message from the partner:
   FR_SWAP_SNK_SRC_NEW_SINK_READY.

TCPC is expected to autonomously turn on vbus once the FRS
signal is received and vbus voltage falls below vsafe5v within
tSrcFrSwap. This is different from traditional power role swap
where the vbus sourcing is turned on by TCPM.

4. By this time, TCPC most likely would have started to
   source vbus, TCPM waits for tSrcFrSwap to see  if the
   lower level TCPC driver signals TCPM_SOURCING_VBUS event:
   FR_SWAP_SNK_SRC_SOURCE_VBUS_APPLIED.
5. When TCPC signals sourcing vbus, TCPM sends PS_READY msg and
   changes the CC pin from Rd to Rp. This is the end of fast
   role swap sequence and TCPM initiates the sequnce to negotiate
   explicit contract by transitioning into SRC_STARTUP after
   SwapSrcStart.

The code is written based on the sequence described in "Figure 8-107:
Dual-role Port in Sink to Source Fast Role Swap State Diagram" of
USB Power Delivery Specification Revision 3.0, Version 1.2.

Signed-off-by: Badhri Jagan Sridharan 
---
 drivers/usb/typec/tcpm/tcpm.c | 191 +-
 include/linux/usb/pd.h|  20 ++--
 include/linux/usb/tcpm.h  |   8 +-
 include/linux/usb/typec.h |  13 +++
 4 files changed, 220 insertions(+), 12 deletions(-)

diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
index 3ef37202ee37..6ea4613af905 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -103,6 +103,13 @@
S(VCONN_SWAP_TURN_ON_VCONN),\
S(VCONN_SWAP_TURN_OFF_VCONN),   \
\
+   S(FR_SWAP_SEND),\
+   S(FR_SWAP_SEND_TIMEOUT),\
+   S(FR_SWAP_SNK_SRC_TRANSITION_TO_OFF),   \
+   S(FR_SWAP_SNK_SRC_NEW_SINK_READY),  \
+   S(FR_SWAP_SNK_SRC_SOURCE_VBUS_APPLIED), \
+   S(FR_SWAP_CANCEL),  \
+   \
S(SNK_TRY), \
S(SNK_TRY_WAIT),\
S(SNK_TRY_WAIT_DEBOUNCE),   \
@@ -124,6 +131,9 @@
S(GET_PPS_STATUS_SEND), \
S(GET_PPS_STATUS_SEND_TIMEOUT), \
\
+   S(GET_SINK_CAP),\
+   S(GET_SINK_CAP_TIMEOUT),\
+   \
S(ERROR_RECOVERY),  \
S(PORT_RESET),  \
S(PORT_RESET_WAIT_OFF)
@@ -172,6 +182,8 @@ enum adev_actions {
 #define TCPM_CC_EVENT  BIT(0)
 #define TCPM_VBUS_EVENTBIT(1)
 #define TCPM_RESET_EVENT   BIT(2)
+#define TCPM_FRS_EVENT BIT(3)
+#define TCPM_SOURCING_VBUS BIT(4)
 
 #define LOG_BUFFER_ENTRIES 1024
 #define LOG_BUFFER_ENTRY_SIZE  128
@@ -181,6 +193,8 @@ enum adev_actions {
 #define SVID_DISCOVERY_MAX 16
 #define ALTMODE_DISCOVERY_MAX  (SVID_DISCOVERY_MAX * MODE_DISCOVERY_MAX)
 
+#define GET_SINK_CAP_RETRY_MS  100
+
 struct pd_mode_data {
int svid_index; /* current SVID index   */
int nsvids;
@@ -256,6 +270,7 @@ struct tcpm_port {
struct work_struct event_work;
struct delayed_work state_machine;
struct delayed_work vdm_state_machine;
+   struct delayed_work enable_frs;
bool state_machine_running;
 
struct completion tx_complete;
@@ -330,6 +345,12 @@ struct tcpm_port {
/* port belongs to a self powered device */
bool self_powered;
 
+   /* FRS */
+   enum frs_typec_current frs_current;
+
+   /* Sink caps have been queried */
+   bool sink_cap_done;
+
 #ifdef CONFIG_DEBUG_FS
struct dentry *dentry;
struct mutex logbuffer_lock;/* log buffer access lock */
@@ -1646,6 +1667,9 @@ static void tcpm_pd_data_request(struct tcpm_port *port,
unsigned int cnt = pd_header_cnt_le(msg->header);
unsigned int rev = pd_header_rev_le(msg->header);

[PATCH 08/14 v1] dt-bindings: connector: Add property to set initial current cap for FRS

2020-08-24 Thread Badhri Jagan Sridharan
This change adds frs-typec-current which allows setting the initial current
capability of the new source when vSafe5V is applied during PD3.0
sink Fast Role Swap.

Signed-off-by: Badhri Jagan Sridharan 
---
 .../bindings/connector/usb-connector.txt  | 128 ++
 include/dt-bindings/usb/pd.h  |  10 ++
 2 files changed, 138 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/connector/usb-connector.txt

diff --git a/Documentation/devicetree/bindings/connector/usb-connector.txt 
b/Documentation/devicetree/bindings/connector/usb-connector.txt
new file mode 100644
index ..e2f6e0f07d00
--- /dev/null
+++ b/Documentation/devicetree/bindings/connector/usb-connector.txt
@@ -0,0 +1,128 @@
+USB Connector
+=
+
+USB connector node represents physical USB connector. It should be
+a child of USB interface controller.
+
+Required properties:
+- compatible: describes type of the connector, must be one of:
+"usb-a-connector",
+"usb-b-connector",
+"usb-c-connector".
+
+Optional properties:
+- label: symbolic name for the connector,
+- type: size of the connector, should be specified in case of USB-A, USB-B
+  non-fullsize connectors: "mini", "micro".
+
+Optional properties for usb-c-connector:
+- power-role: should be one of "source", "sink" or "dual"(DRP) if typec
+  connector has power support.
+- try-power-role: preferred power role if "dual"(DRP) can support Try.SNK
+  or Try.SRC, should be "sink" for Try.SNK or "source" for Try.SRC.
+- data-role: should be one of "host", "device", "dual"(DRD) if typec
+  connector supports USB data.
+- frs-typec-current - Initial current capability of the new source when vSafe5V
+  is applied during PD3.0 Fast Role Swap. "Table 6-14 Fixed Supply PDO - Sink"
+  of "USB Power Delivery Specification Revision 3.0, Version 1.2" provides the
+  different power levels and "6.4.1.3.1.6 Fast Role Swap USB Type-C Current"
+  provides a detailed description of the field.
+  0: Fast role swap not supported
+  1: Default USB Power
+  2: 1.5A @ 5V
+  3: 3A @ 5V.
+
+Required properties for usb-c-connector with power delivery support:
+- source-pdos: An array of u32 with each entry providing supported power
+  source data object(PDO), the detailed bit definitions of PDO can be found
+  in "Universal Serial Bus Power Delivery Specification" chapter 6.4.1.2
+  Source_Capabilities Message, the order of each entry(PDO) should follow
+  the PD spec chapter 6.4.1. Required for power source and power dual role.
+  User can specify the source PDO array via PDO_FIXED/BATT/VAR/PPS_APDO()
+  defined in dt-bindings/usb/pd.h.
+- sink-pdos: An array of u32 with each entry providing supported power
+  sink data object(PDO), the detailed bit definitions of PDO can be found
+  in "Universal Serial Bus Power Delivery Specification" chapter 6.4.1.3
+  Sink Capabilities Message, the order of each entry(PDO) should follow
+  the PD spec chapter 6.4.1. Required for power sink and power dual role.
+  User can specify the sink PDO array via PDO_FIXED/BATT/VAR/PPS_APDO() defined
+  in dt-bindings/usb/pd.h.
+- op-sink-microwatt: Sink required operating power in microwatt, if source
+  can't offer the power, Capability Mismatch is set. Required for power
+  sink and power dual role.
+
+Required nodes:
+- any data bus to the connector should be modeled using the OF graph bindings
+  specified in bindings/graph.txt, unless the bus is between parent node and
+  the connector. Since single connector can have multpile data buses every bus
+  has assigned OF graph port number as follows:
+0: High Speed (HS), present in all connectors,
+1: Super Speed (SS), present in SS capable connectors,
+2: Sideband use (SBU), present in USB-C.
+
+Examples
+
+
+1. Micro-USB connector with HS lines routed via controller (MUIC):
+
+muic-max77843@66 {
+   ...
+   usb_con: connector {
+   compatible = "usb-b-connector";
+   label = "micro-USB";
+   type = "micro";
+   };
+};
+
+2. USB-C connector attached to CC controller (s2mm005), HS lines routed
+to companion PMIC (max77865), SS lines to USB3 PHY and SBU to DisplayPort.
+DisplayPort video lines are routed to the connector via SS mux in USB3 PHY.
+
+ccic: s2mm005@33 {
+   ...
+   usb_con: connector {
+   compatible = "usb-c-connector";
+   label = "USB-C";
+
+   ports {
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   port@0 {
+   reg = <0>;
+   usb_con_hs: endpoint {
+   remote-endpoint = <_usbc_hs>;
+   };
+   };
+   port@1 {
+   reg = <1>;
+   usb_con_ss: endpoint {
+   remote-endpoint = 

[PATCH 10/14 v1] usb: typec: tcpci: Implement callbacks for FRS

2020-08-24 Thread Badhri Jagan Sridharan
Implement tcpc.enable_frs to enable TCPC to receive
Fast role swap signal.

Additionally set the sink disconnect threshold to 4v
to prevent disconnect during Fast Role swap.

Signed-off-by: Badhri Jagan Sridharan 
---
 drivers/usb/typec/tcpm/tcpci.c | 17 +
 drivers/usb/typec/tcpm/tcpci.h |  8 
 2 files changed, 25 insertions(+)

diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c
index 89d28e3fbee8..13d2e1c2ff20 100644
--- a/drivers/usb/typec/tcpm/tcpci.c
+++ b/drivers/usb/typec/tcpm/tcpci.c
@@ -268,6 +268,22 @@ static int tcpci_set_vconn(struct tcpc_dev *tcpc, bool 
enable)
enable ? TCPC_POWER_CTRL_VCONN_ENABLE : 0);
 }
 
+static int tcpci_enable_frs(struct tcpc_dev *dev, bool enable)
+{
+   struct tcpci *tcpci = tcpc_to_tcpci(dev);
+   int ret;
+
+   /* To prevent disconnect during FRS, set disconnect threshold to 3.5V */
+   ret = tcpci_write16(tcpci, TCPC_VBUS_SINK_DISCONNECT_THRESH, enable ? 0 
: 0x8c);
+   if (ret < 0)
+   return ret;
+
+   ret = regmap_update_bits(tcpci->regmap, TCPC_POWER_CTRL, 
TCPC_FAST_ROLE_SWAP_EN, enable ?
+TCPC_FAST_ROLE_SWAP_EN : 0);
+
+   return ret;
+}
+
 static int tcpci_set_bist_data(struct tcpc_dev *tcpc, bool enable)
 {
struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
@@ -610,6 +626,7 @@ struct tcpci *tcpci_register_port(struct device *dev, 
struct tcpci_data *data)
tcpci->tcpc.set_roles = tcpci_set_roles;
tcpci->tcpc.pd_transmit = tcpci_pd_transmit;
tcpci->tcpc.set_bist_data = tcpci_set_bist_data;
+   tcpci->tcpc.enable_frs = tcpci_enable_frs;
 
err = tcpci_parse_config(tcpci);
if (err < 0)
diff --git a/drivers/usb/typec/tcpm/tcpci.h b/drivers/usb/typec/tcpm/tcpci.h
index 82f021a82456..5ef07a56d67a 100644
--- a/drivers/usb/typec/tcpm/tcpci.h
+++ b/drivers/usb/typec/tcpm/tcpci.h
@@ -16,6 +16,7 @@
 #define TCPC_PD_INT_REV0xa
 
 #define TCPC_ALERT 0x10
+#define TCPC_ALERT_EXTND   BIT(14)
 #define TCPC_ALERT_EXTENDED_STATUS BIT(13)
 #define TCPC_ALERT_VBUS_DISCNCTBIT(11)
 #define TCPC_ALERT_RX_BUF_OVF  BIT(10)
@@ -37,6 +38,9 @@
 #define TCPC_EXTENDED_STATUS_MASK  0x16
 #define TCPC_EXTENDED_STATUS_MASK_VSAFE0V  BIT(0)
 
+#define TCPC_ALERT_EXTENDED_MASK   0x17
+#define TCPC_SINK_FAST_ROLE_SWAP   BIT(0)
+
 #define TCPC_CONFIG_STD_OUTPUT 0x18
 
 #define TCPC_TCPC_CTRL 0x19
@@ -63,6 +67,7 @@
 
 #define TCPC_POWER_CTRL0x1c
 #define TCPC_POWER_CTRL_VCONN_ENABLE   BIT(0)
+#define TCPC_FAST_ROLE_SWAP_EN BIT(7)
 
 #define TCPC_CC_STATUS 0x1d
 #define TCPC_CC_STATUS_TOGGLINGBIT(5)
@@ -74,11 +79,14 @@
 
 #define TCPC_POWER_STATUS  0x1e
 #define TCPC_POWER_STATUS_UNINIT   BIT(6)
+#define TCPC_POWER_STATUS_SOURCING_VBUSBIT(4)
 #define TCPC_POWER_STATUS_VBUS_DET BIT(3)
 #define TCPC_POWER_STATUS_VBUS_PRESBIT(2)
 
 #define TCPC_FAULT_STATUS  0x1f
 
+#define TCPC_ALERT_EXTENDED0x21
+
 #define TCPC_COMMAND   0x23
 #define TCPC_CMD_WAKE_I2C  0x11
 #define TCPC_CMD_DISABLE_VBUS_DETECT   0x22
-- 
2.28.0.297.g1956fa8f8d-goog



[PATCH 11/14 v1] usb: typec: tcpci_maxim: Add support for Sink FRS

2020-08-24 Thread Badhri Jagan Sridharan
Upon receiving ALERT_EXTENDED.TCPC_SINK_FAST_ROLE_SWAP signal
tcpm to start Sink fast role swap signal.

Inform when TCPM is sourcing vbus.

Signed-off-by: Badhri Jagan Sridharan 
---
 drivers/usb/typec/tcpm/tcpci_maxim.c | 50 +---
 1 file changed, 46 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/typec/tcpm/tcpci_maxim.c 
b/drivers/usb/typec/tcpm/tcpci_maxim.c
index b61f290a8f96..6ba808ad901a 100644
--- a/drivers/usb/typec/tcpm/tcpci_maxim.c
+++ b/drivers/usb/typec/tcpm/tcpci_maxim.c
@@ -106,13 +106,22 @@ static void max_tcpci_init_regs(struct max_tcpci_chip 
*chip)
return;
}
 
+   ret = max_tcpci_write8(chip, TCPC_ALERT_EXTENDED, 0xff);
+   if (ret < 0) {
+   dev_err(chip->dev, "Unable to clear TCPC_ALERT_EXTENDED 
ret:%d\n", ret);
+   return;
+   }
+
alert_mask = TCPC_ALERT_TX_SUCCESS | TCPC_ALERT_TX_DISCARDED | 
TCPC_ALERT_TX_FAILED |
TCPC_ALERT_RX_HARD_RST | TCPC_ALERT_RX_STATUS | 
TCPC_ALERT_CC_STATUS |
-   TCPC_ALERT_VBUS_DISCNCT | TCPC_ALERT_RX_BUF_OVF | 
TCPC_ALERT_POWER_STATUS;
+   TCPC_ALERT_VBUS_DISCNCT | TCPC_ALERT_RX_BUF_OVF | 
TCPC_ALERT_POWER_STATUS |
+   /* Enable Extended alert for detecting Fast Role Swap Signal */
+   TCPC_ALERT_EXTND;
 
ret = max_tcpci_write16(chip, TCPC_ALERT_MASK, alert_mask);
if (ret < 0) {
-   dev_err(chip->dev, "Error writing to TCPC_ALERT_MASK ret:%d\n", 
ret);
+   dev_err(chip->dev,
+   "Error enabling TCPC_ALERT: TCPC_ALERT_MASK write 
failed ret:%d\n", ret);
return;
}
 
@@ -122,6 +131,10 @@ static void max_tcpci_init_regs(struct max_tcpci_chip 
*chip)
dev_err(chip->dev, "Error writing to TCPC_POWER_CTRL ret:%d\n", 
ret);
return;
}
+
+   ret = max_tcpci_write8(chip, TCPC_ALERT_EXTENDED_MASK, 
TCPC_SINK_FAST_ROLE_SWAP);
+   if (ret < 0)
+   return;
 }
 
 static void process_rx(struct max_tcpci_chip *chip, u16 status)
@@ -225,10 +238,23 @@ static void process_power_status(struct max_tcpci_chip 
*chip)
if (ret < 0)
return;
 
-   if (pwr_status == 0xff)
+   if (pwr_status == 0xff) {
max_tcpci_init_regs(chip);
-   else
+   } else if (pwr_status & TCPC_POWER_STATUS_SOURCING_VBUS) {
+   tcpm_sourcing_vbus(chip->port);
+   /*
+* Alawys re-enable boost here.
+* In normal case, when say an headset is attached, TCPM would
+* have instructed to TCPC to enable boost, so the call is a
+* no-op.
+* But for Fast Role Swap case, Boost turns on autonomously 
without
+* AP intervention, but, needs AP to enable source mode 
explicitly
+* for AP to regain control.
+*/
+   max_tcpci_set_vbus(chip->tcpci, >data, true, false);
+   } else {
tcpm_vbus_change(chip->port);
+   }
 }
 
 static void process_tx(struct max_tcpci_chip *chip, u16 status)
@@ -249,6 +275,7 @@ static irqreturn_t _max_tcpci_irq(struct max_tcpci_chip 
*chip, u16 status)
 {
u16 mask;
int ret;
+   u8 reg_status;
 
/*
 * Clear alert status for everything except RX_STATUS, which shouldn't
@@ -274,6 +301,21 @@ static irqreturn_t _max_tcpci_irq(struct max_tcpci_chip 
*chip, u16 status)
}
}
 
+   if (status & TCPC_ALERT_EXTND) {
+   ret = max_tcpci_read8(chip, TCPC_ALERT_EXTENDED, _status);
+   if (ret < 0)
+   return ret;
+
+   ret = max_tcpci_write8(chip, TCPC_ALERT_EXTENDED, reg_status);
+   if (ret < 0)
+   return ret;
+
+   if (reg_status & TCPC_SINK_FAST_ROLE_SWAP) {
+   dev_info(chip->dev, "FRS Signal");
+   tcpm_sink_frs(chip->port);
+   }
+   }
+
if (status & TCPC_ALERT_RX_STATUS)
process_rx(chip, status);
 
-- 
2.28.0.297.g1956fa8f8d-goog



[PATCH 14/14 v1] usb: typec: tcpci_maxim: Implemnent set_auto_vbus_discharge_threshold

2020-08-24 Thread Badhri Jagan Sridharan
Programs VBUS_SINK_DISCONNECT_THRESHOLD based on the power_role,
voltage requested as sink, mode of operation.

The programmed threshold is based on vSinkDisconnect and
vSinkDisconnectPD values.

Signed-off-by: Badhri Jagan Sridharan 
---
 drivers/usb/typec/tcpm/tcpci_maxim.c | 48 
 1 file changed, 48 insertions(+)

diff --git a/drivers/usb/typec/tcpm/tcpci_maxim.c 
b/drivers/usb/typec/tcpm/tcpci_maxim.c
index 6ba808ad901a..e35bd995c037 100644
--- a/drivers/usb/typec/tcpm/tcpci_maxim.c
+++ b/drivers/usb/typec/tcpm/tcpci_maxim.c
@@ -137,6 +137,52 @@ static void max_tcpci_init_regs(struct max_tcpci_chip 
*chip)
return;
 }
 
+static int max_tcpci_set_auto_vbus_discharge_threshold(struct tcpci *tcpci, 
struct tcpci_data *data,
+  enum typec_role 
port_role,
+  enum typec_pwr_opmode 
mode, bool pps_active,
+  u32 
requested_vbus_voltage_mv)
+{
+   struct max_tcpci_chip *chip = tdata_to_max_tcpci(data);
+   u32 threshold = 0;
+   u8 pwr_ctrl;
+
+   /*
+* Indicates that vbus is going to go away due PR_SWAP, hard reset etc.
+* Do not discharge vbus here.
+*/
+   if (requested_vbus_voltage_mv == 0)
+   goto write_thresh;
+
+   if (port_role == TYPEC_SINK) {
+   max_tcpci_read8(chip, TCPC_POWER_CTRL, _ctrl);
+   if (pwr_ctrl & TCPC_FAST_ROLE_SWAP_EN) {
+   /* To prevent disconnect when the source is fast role 
swap is capable. */
+   threshold = 3500;
+   } else if (mode == TYPEC_PWR_MODE_PD) {
+   if (pps_active)
+   threshold = (95 * requested_vbus_voltage_mv / 
100) - 850;
+   else
+   threshold = (95 * requested_vbus_voltage_mv / 
100) - 1250;
+   } else {
+   /* 3.5V for non-pd sink */
+   threshold = 3500;
+   }
+   } else {
+   /* 4V for source */
+   threshold = 4000;
+   }
+
+   threshold = threshold / TCPC_VBUS_SINK_DISCONNECT_THRESH_LSB;
+
+   if (threshold > TCPC_VBUS_SINK_DISCONNECT_THRESH_MAX) {
+   dev_err(chip->dev, "VBUS_SINK_DISCONNECT_THRESH out of range");
+   return -EINVAL;
+   }
+
+write_thresh:
+   return max_tcpci_write16(chip, TCPC_VBUS_SINK_DISCONNECT_THRESH, 
threshold);
+}
+
 static void process_rx(struct max_tcpci_chip *chip, u16 status)
 {
struct pd_message msg;
@@ -454,6 +500,8 @@ static int max_tcpci_probe(struct i2c_client *client, const 
struct i2c_device_id
chip->data.start_drp_toggling = max_tcpci_start_toggling;
chip->data.TX_BUF_BYTE_x_hidden = true;
chip->data.init = tcpci_init;
+   chip->data.set_auto_vbus_discharge_threshold = 
max_tcpci_set_auto_vbus_discharge_threshold;
+   chip->data.auto_discharge_disconnect = true;
 
max_tcpci_init_regs(chip);
chip->tcpci = tcpci_register_port(chip->dev, >data);
-- 
2.28.0.297.g1956fa8f8d-goog



[PATCH 12/14] usb: typec: tcpm: Implement enabling Auto Discharge disconnect support

2020-08-24 Thread Badhri Jagan Sridharan
TCPCI spec allows TCPC hardware to autonomously discharge the vbus
capacitance upon disconnect. The expectation is that the TCPM enables
AutoDischargeDisconnect while entering SNK/SRC_ATTACHED states. Hardware
then automously discharges vbus when the vbus falls below a certain
threshold i.e. VBUS_SINK_DISCONNECT_THRESHOLD.

Apart from enabling the vbus discharge circuit, AutoDischargeDisconnect
is also used a flag to move TCPCI based TCPC implementations into
Attached.Snk/Attached.Src state as mentioned in
Figure 4-15. TCPC State Diagram before a Connection of the
USB Type-C Port Controller Interface Specification.
In such TCPC implementations, setting AutoDischargeDisconnect would
prevent TCPC into entering "Connection_Invalid" state as well.

Signed-off-by: Badhri Jagan Sridharan 
Change-Id: I09c407eb228d69eb1259008eeb14c429b0fda765
---
 drivers/usb/typec/tcpm/tcpm.c | 80 +--
 include/linux/usb/tcpm.h  | 16 +++
 2 files changed, 92 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
index 6ea4613af905..fe58cf908144 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -1660,6 +1660,25 @@ static void tcpm_handle_alert(struct tcpm_port *port, 
const __le32 *payload,
}
 }
 
+static int tcpm_set_auto_vbus_discharge_threshold(struct tcpm_port *port, enum 
typec_role port_role,
+ enum typec_pwr_opmode mode, 
bool pps_active,
+ u32 requested_vbus_voltage)
+{
+   int ret;
+
+   if (!port->tcpc->set_auto_vbus_discharge_threshold)
+   return 0;
+
+   ret = port->tcpc->set_auto_vbus_discharge_threshold(port->tcpc, 
port_role, mode, pps_active,
+   
requested_vbus_voltage);
+   tcpm_log_force(port,
+  "set_auto_vbus_discharge_threshold pwr_role:%s mode:%d 
pps_active:%c vbus:%u ret:%d",
+  port_role == TYPEC_SINK ? "sink" : "source", mode, 
pps_active ? 'y' : 'n',
+  requested_vbus_voltage, ret);
+
+   return ret;
+}
+
 static void tcpm_pd_data_request(struct tcpm_port *port,
 const struct pd_message *msg)
 {
@@ -1829,6 +1848,10 @@ static void tcpm_pd_ctrl_request(struct tcpm_port *port,
   port->current_limit,
   port->supply_voltage);
port->explicit_contract = true;
+   tcpm_set_auto_vbus_discharge_threshold(port, 
TYPEC_SINK,
+  
TYPEC_PWR_MODE_PD,
+  
port->pps_data.active,
+  
port->supply_voltage);
tcpm_set_state(port, SNK_READY, 0);
} else {
/*
@@ -2743,8 +2766,14 @@ static int tcpm_src_attach(struct tcpm_port *port)
if (ret < 0)
return ret;
 
-   ret = tcpm_set_roles(port, true, TYPEC_SOURCE,
-tcpm_data_role_for_source(port));
+   if (port->tcpc->enable_auto_vbus_discharge) {
+   tcpm_set_auto_vbus_discharge_threshold(port, TYPEC_SOURCE, 
TYPEC_PWR_MODE_USB,
+  false, VSAFE5V);
+   ret = port->tcpc->enable_auto_vbus_discharge(port->tcpc, true);
+   tcpm_log_force(port, "enable vbus discharge ret:%d", ret);
+   }
+
+   ret = tcpm_set_roles(port, true, TYPEC_SOURCE, 
tcpm_data_role_for_sink(port));
if (ret < 0)
return ret;
 
@@ -2811,6 +2840,12 @@ static void tcpm_unregister_altmodes(struct tcpm_port 
*port)
 
 static void tcpm_reset_port(struct tcpm_port *port)
 {
+   int ret;
+
+   if (port->tcpc->enable_auto_vbus_discharge) {
+   ret = port->tcpc->enable_auto_vbus_discharge(port->tcpc, false);
+   tcpm_log_force(port, "Disable vbus discharge ret:%d", ret);
+   }
tcpm_unregister_altmodes(port);
tcpm_typec_disconnect(port);
port->attached = false;
@@ -2875,8 +2910,14 @@ static int tcpm_snk_attach(struct tcpm_port *port)
if (ret < 0)
return ret;
 
-   ret = tcpm_set_roles(port, true, TYPEC_SINK,
-tcpm_data_role_for_sink(port));
+   if (port->tcpc->enable_auto_vbus_discharge) {
+   tcpm_set_auto_vbus_discharge_threshold(port, TYPEC_SINK, 
TYPEC_PWR_MODE_USB, false,
+  VSAFE5V);
+   ret = port->tcpc->enable_auto_vbus_discharge(port->tcpc, true);
+   tcpm_log_force(port, "enable vbus 

[PATCH 04/14 v1] usb: typec: tcpci: Add a getter method to retrieve tcpm_port reference

2020-08-24 Thread Badhri Jagan Sridharan
Allow chip level drivers to retrieve reference to tcpm_port.

Signed-off-by: Badhri Jagan Sridharan 
---
 drivers/usb/typec/tcpm/tcpci.c | 6 ++
 drivers/usb/typec/tcpm/tcpci.h | 2 ++
 2 files changed, 8 insertions(+)

diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c
index 9e814d454d14..7b7991c8ac87 100644
--- a/drivers/usb/typec/tcpm/tcpci.c
+++ b/drivers/usb/typec/tcpm/tcpci.c
@@ -38,6 +38,12 @@ struct tcpci_chip {
struct tcpci_data data;
 };
 
+struct tcpm_port *tcpci_get_tcpm_port(struct tcpci *tcpci)
+{
+   return tcpci->port;
+}
+EXPORT_SYMBOL_GPL(tcpci_get_tcpm_port);
+
 static inline struct tcpci *tcpc_to_tcpci(struct tcpc_dev *tcpc)
 {
return container_of(tcpc, struct tcpci, tcpc);
diff --git a/drivers/usb/typec/tcpm/tcpci.h b/drivers/usb/typec/tcpm/tcpci.h
index cf9d8b63adcb..04c49a0b0368 100644
--- a/drivers/usb/typec/tcpm/tcpci.h
+++ b/drivers/usb/typec/tcpm/tcpci.h
@@ -150,4 +150,6 @@ struct tcpci *tcpci_register_port(struct device *dev, 
struct tcpci_data *data);
 void tcpci_unregister_port(struct tcpci *tcpci);
 irqreturn_t tcpci_irq(struct tcpci *tcpci);
 
+struct tcpm_port;
+struct tcpm_port *tcpci_get_tcpm_port(struct tcpci *tcpci);
 #endif /* __LINUX_USB_TCPCI_H */
-- 
2.28.0.297.g1956fa8f8d-goog



[PATCH 02/14 v2] usb: typec: tcpci: Add support when hidden tx registers are inaccessible

2020-08-24 Thread Badhri Jagan Sridharan
TCPCI spec forbids direct access of TX_BUF_BYTE_x register.
The existing version of tcpci driver assumes that those registers
are directly addressible. Add support for tcpci chips which do
not support direct access to TX_BUF_BYTE_x registers. TX_BUF_BYTE_x
can only be accessed by I2C_WRITE_BYTE_COUNT.

Signed-off-by: Badhri Jagan Sridharan 
---
 drivers/usb/typec/tcpm/tcpci.c | 49 +-
 drivers/usb/typec/tcpm/tcpci.h |  8 ++
 2 files changed, 44 insertions(+), 13 deletions(-)

diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c
index f57d91fd0e09..90d348caa6a8 100644
--- a/drivers/usb/typec/tcpm/tcpci.c
+++ b/drivers/usb/typec/tcpm/tcpci.c
@@ -320,8 +320,7 @@ static int tcpci_set_vbus(struct tcpc_dev *tcpc, bool 
source, bool sink)
return 0;
 }
 
-static int tcpci_pd_transmit(struct tcpc_dev *tcpc,
-enum tcpm_transmit_type type,
+static int tcpci_pd_transmit(struct tcpc_dev *tcpc, enum tcpm_transmit_type 
type,
 const struct pd_message *msg)
 {
struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
@@ -330,23 +329,47 @@ static int tcpci_pd_transmit(struct tcpc_dev *tcpc,
int ret;
 
cnt = msg ? pd_header_cnt(header) * 4 : 0;
-   ret = regmap_write(tcpci->regmap, TCPC_TX_BYTE_CNT, cnt + 2);
-   if (ret < 0)
-   return ret;
+   /**
+* TCPCI spec forbids direct access of TCPC_TX_DATA.
+* But, since some of the chipsets offer this capability,
+* it's fair to support both.
+*/
+   if (!tcpci->data->TX_BUF_BYTE_x_hidden) {
+   ret = regmap_write(tcpci->regmap, TCPC_TX_BYTE_CNT, cnt + 2);
+   if (ret < 0)
+   return ret;
 
-   ret = tcpci_write16(tcpci, TCPC_TX_HDR, header);
-   if (ret < 0)
-   return ret;
+   ret = tcpci_write16(tcpci, TCPC_TX_HDR, header);
+   if (ret < 0)
+   return ret;
+
+   if (cnt > 0) {
+   ret = regmap_raw_write(tcpci->regmap, TCPC_TX_DATA, 
>payload, cnt);
+   if (ret < 0)
+   return ret;
+   }
+   } else {
+   u8 buf[TCPC_TRANSMIT_BUFFER_MAX_LEN] = {0,};
+   u8 pos = 0;
+
+   /* Payload + header + TCPC_TX_BYTE_CNT */
+   buf[pos++] = cnt + 2;
+
+   if (msg)
+   memcpy([pos], >header, sizeof(msg->header));
+
+   pos += sizeof(header);
+
+   if (cnt > 0)
+   memcpy([pos], msg->payload, cnt);
 
-   if (cnt > 0) {
-   ret = regmap_raw_write(tcpci->regmap, TCPC_TX_DATA,
-  >payload, cnt);
+   pos += cnt;
+   ret = regmap_raw_write(tcpci->regmap, TCPC_TX_BYTE_CNT, buf, 
pos);
if (ret < 0)
return ret;
}
 
-   reg = (PD_RETRY_COUNT << TCPC_TRANSMIT_RETRY_SHIFT) |
-   (type << TCPC_TRANSMIT_TYPE_SHIFT);
+   reg = (PD_RETRY_COUNT << TCPC_TRANSMIT_RETRY_SHIFT) | (type << 
TCPC_TRANSMIT_TYPE_SHIFT);
ret = regmap_write(tcpci->regmap, TCPC_TRANSMIT, reg);
if (ret < 0)
return ret;
diff --git a/drivers/usb/typec/tcpm/tcpci.h b/drivers/usb/typec/tcpm/tcpci.h
index fd26ca35814c..cf9d8b63adcb 100644
--- a/drivers/usb/typec/tcpm/tcpci.h
+++ b/drivers/usb/typec/tcpm/tcpci.h
@@ -128,9 +128,17 @@
 #define TCPC_VBUS_VOLTAGE_ALARM_HI_CFG 0x76
 #define TCPC_VBUS_VOLTAGE_ALARM_LO_CFG 0x78
 
+/* I2C_WRITE_BYTE_COUNT + 1 when TX_BUF_BYTE_x is only accessible 
I2C_WRITE_BYTE_COUNT */
+#define TCPC_TRANSMIT_BUFFER_MAX_LEN   31
+
+/*
+ * @TX_BUF_BYTE_x_hidden
+ * optional; Set when TX_BUF_BYTE_x can only be accessed through 
I2C_WRITE_BYTE_COUNT.
+ */
 struct tcpci;
 struct tcpci_data {
struct regmap *regmap;
+   unsigned char TX_BUF_BYTE_x_hidden:1;
int (*init)(struct tcpci *tcpci, struct tcpci_data *data);
int (*set_vconn)(struct tcpci *tcpci, struct tcpci_data *data,
 bool enable);
-- 
2.28.0.297.g1956fa8f8d-goog



[PATCH 03/14 v1] usb: typec: tcpci: update ROLE_CONTROL for DRP

2020-08-24 Thread Badhri Jagan Sridharan
ROLE_CONTROL register would not have the actual CC terminations
unless the port does not set ROLE_CONTROL.DRP. For DRP ports,
CC_STATUS.cc1/cc2 indicates the final terminations applied
when TCPC enters potential_connect_as_source/_sink.
For DRP ports, infer port role from CC_STATUS and set corresponding
CC terminations before setting the orientation.

Signed-off-by: Badhri Jagan Sridharan 
---
 drivers/usb/typec/tcpm/tcpci.c | 37 +-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c
index 90d348caa6a8..9e814d454d14 100644
--- a/drivers/usb/typec/tcpm/tcpci.c
+++ b/drivers/usb/typec/tcpm/tcpci.c
@@ -191,12 +191,47 @@ static int tcpci_set_polarity(struct tcpc_dev *tcpc,
struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
unsigned int reg;
int ret;
+   enum typec_cc_status cc1, cc2;
 
-   /* Keep the disconnect cc line open */
+   /* Obtain Rp setting from role control */
ret = regmap_read(tcpci->regmap, TCPC_ROLE_CTRL, );
if (ret < 0)
return ret;
 
+   ret = tcpci_get_cc(tcpc, , );
+   if (ret < 0)
+   return ret;
+
+   /*
+* When port has drp toggling enabled, ROLE_CONTROL would only have the 
initial
+* terminations for the toggling and does not indicate the final cc
+* terminations when ConnectionResult is 0 i.e. drp toggling stops and
+* the connection is resolbed. Infer port role from TCPC_CC_STATUS 
based on the
+* terminations seen. The port role is then used to set the cc 
terminations.
+*/
+   if (reg & TCPC_ROLE_CTRL_DRP) {
+   /* Disable DRP for the OPEN setting to take effect */
+   reg = reg & ~TCPC_ROLE_CTRL_DRP;
+
+   if (polarity == TYPEC_POLARITY_CC2) {
+   reg &= ~(TCPC_ROLE_CTRL_CC2_MASK << 
TCPC_ROLE_CTRL_CC2_SHIFT);
+   /* Local port is source */
+   if (cc2 == TYPEC_CC_RD)
+   /* Role control would have the Rp setting when 
DRP was enabled */
+   reg |= TCPC_ROLE_CTRL_CC_RP << 
TCPC_ROLE_CTRL_CC2_SHIFT;
+   else
+   reg |= TCPC_ROLE_CTRL_CC_RD << 
TCPC_ROLE_CTRL_CC2_SHIFT;
+   } else {
+   reg &= ~(TCPC_ROLE_CTRL_CC1_MASK << 
TCPC_ROLE_CTRL_CC1_SHIFT);
+   /* Local port is source */
+   if (cc1 == TYPEC_CC_RD)
+   /* Role control would have the Rp setting when 
DRP was enabled */
+   reg |= TCPC_ROLE_CTRL_CC_RP << 
TCPC_ROLE_CTRL_CC1_SHIFT;
+   else
+   reg |= TCPC_ROLE_CTRL_CC_RD << 
TCPC_ROLE_CTRL_CC1_SHIFT;
+   }
+   }
+
if (polarity == TYPEC_POLARITY_CC2)
reg |= TCPC_ROLE_CTRL_CC_OPEN << TCPC_ROLE_CTRL_CC1_SHIFT;
else
-- 
2.28.0.297.g1956fa8f8d-goog



[PATCH 01/14 v1] usb: typec: tcpci: Add register definitions to tcpci

2020-08-24 Thread Badhri Jagan Sridharan
Add register definitions to trap extended alerts.

Signed-off-by: Badhri Jagan Sridharan 
---
 drivers/usb/typec/tcpm/tcpci.h | 5 +
 1 file changed, 5 insertions(+)

diff --git a/drivers/usb/typec/tcpm/tcpci.h b/drivers/usb/typec/tcpm/tcpci.h
index 11c36d086c86..fd26ca35814c 100644
--- a/drivers/usb/typec/tcpm/tcpci.h
+++ b/drivers/usb/typec/tcpm/tcpci.h
@@ -16,6 +16,7 @@
 #define TCPC_PD_INT_REV0xa
 
 #define TCPC_ALERT 0x10
+#define TCPC_ALERT_EXTENDED_STATUS BIT(13)
 #define TCPC_ALERT_VBUS_DISCNCTBIT(11)
 #define TCPC_ALERT_RX_BUF_OVF  BIT(10)
 #define TCPC_ALERT_FAULT   BIT(9)
@@ -32,6 +33,10 @@
 #define TCPC_ALERT_MASK0x12
 #define TCPC_POWER_STATUS_MASK 0x14
 #define TCPC_FAULT_STATUS_MASK 0x15
+
+#define TCPC_EXTENDED_STATUS_MASK  0x16
+#define TCPC_EXTENDED_STATUS_MASK_VSAFE0V  BIT(0)
+
 #define TCPC_CONFIG_STD_OUTPUT 0x18
 
 #define TCPC_TCPC_CTRL 0x19
-- 
2.28.0.297.g1956fa8f8d-goog



[PATCH 00/14] TCPM support for FRS and AutoDischarge Disconnect

2020-08-24 Thread Badhri Jagan Sridharan
Hi all,

With this patchset, I am hoping to add Sink Fast Role swap support to TCPM.
Sink Fast Role swap is described by the USB Power Delivery Specification
Revision 3.0. The patchset also adds support to Auto Discharge Disconnect
described in the USB Type-C Port Controller Interface Specification.
I am also sending the chip level driver for the TCPCI based type-c controller
that supports Fast role swap.

I tested the fast role swap implementation with the following
accessories:
1. https://ezq.com/usb-c-multimedia-hub-adapter-8-ports.html
2. https://www.iogear.com/product/GUH3C22P/

Note: I will rebase the patchset on top of https://lkml.org/lkml/2020/8/19/52
once it's picked up in usb-next.

Badhri Jagan Sridharan (14):
  usb: typec: tcpci: Add register definitions to tcpci
  usb: typec: tcpci: Add support when hidden tx registers are
inaccessible
  usb: typec: tcpci: update ROLE_CONTROL for DRP
  usb: typec: tcpci: Add a getter method to retrieve tcpm_port reference
  usb: typec: tcpci: Add set_vbus tcpci callback
  dt-bindings: usb: Maxim type-c controller device tree binding document
  usb: typec: tcpci_maxim: Chip level TCPC driver
  dt-bindings: connector: Add property to set initial current cap for
FRS
  usb: typec: tcpm: Add support for Sink Fast Role SWAP(FRS)
  usb: typec: tcpci: Implement callbacks for FRS
  usb: typec: tcpci_maxim: Add support for Sink FRS
  usb: typec: tcpm: Implement enabling Auto Discharge disconnect support
  usb: typec: tcpci: Implement Auto discharge disconnect callbacks
  usb: typec: tcpci_maxim: Implemnent set_auto_vbus_discharge_threshold

 .../bindings/connector/usb-connector.txt  | 128 
 .../devicetree/bindings/usb/maxim,tcpci.txt   |  44 ++
 drivers/usb/typec/tcpm/Kconfig|   6 +
 drivers/usb/typec/tcpm/Makefile   |  13 +-
 drivers/usb/typec/tcpm/tcpci.c| 149 -
 drivers/usb/typec/tcpm/tcpci.h|  43 ++
 drivers/usb/typec/tcpm/tcpci_maxim.c  | 564 ++
 drivers/usb/typec/tcpm/tcpm.c | 271 -
 include/dt-bindings/usb/pd.h  |  10 +
 include/linux/usb/pd.h|  20 +-
 include/linux/usb/tcpm.h  |  24 +-
 include/linux/usb/typec.h |  13 +
 12 files changed, 1249 insertions(+), 36 deletions(-)
 create mode 100644 
Documentation/devicetree/bindings/connector/usb-connector.txt
 create mode 100644 Documentation/devicetree/bindings/usb/maxim,tcpci.txt
 create mode 100644 drivers/usb/typec/tcpm/tcpci_maxim.c

-- 
2.28.0.297.g1956fa8f8d-goog



[PATCH 06/14 v1] dt-bindings: usb: Maxim type-c controller device tree binding document

2020-08-24 Thread Badhri Jagan Sridharan
Add device tree binding document for Maxim TCPCI based Type-C chip driver

Signed-off-by: Badhri Jagan Sridharan 
---
 .../devicetree/bindings/usb/maxim,tcpci.txt   | 44 +++
 1 file changed, 44 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/maxim,tcpci.txt

diff --git a/Documentation/devicetree/bindings/usb/maxim,tcpci.txt 
b/Documentation/devicetree/bindings/usb/maxim,tcpci.txt
new file mode 100644
index ..8a5b08e57b2d
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/maxim,tcpci.txt
@@ -0,0 +1,44 @@
+Maxim TCPCI Type-C PD controller:
+-
+
+Required properties:
+- compatible:   should be set maxim,tcpci:
+
+- reg:  0x25:the i2c slave address of typec port controller device.
+- interrupt-parent: the phandle to the interrupt controller which provides
+the interrupt.
+- usbpd,usbpd_int:  interrupt specification for tcpci alert.
+
+Required sub-node:
+- connector: The "usb-c-connector" attached to the tcpci chip, the bindings
+  of connector node are specified in
+  Documentation/devicetree/bindings/connector/usb-connector.txt
+
+maxtcpc: maxtcpc@25 {
+   status = "okay";
+   compatible = "maxim,tcpc";
+   reg = <0x25>;
+   interrupt-parent = <>;
+   usbpd,usbpd_int = < 2 GPIO_ACTIVE_LOW>;
+
+   connector {
+   compatible = "usb-c-connector";
+   label = "USB-C";
+   data-role = "dual";
+   power-role = "dual";
+   try-power-role = "sink";
+   self-powered;
+   op-sink-microwatt = <260>;
+   source-pdos = ;
+   sink-pdos = ;
+   };
+};
-- 
2.28.0.297.g1956fa8f8d-goog



Re: [patch RFC 24/38] x86/xen: Consolidate XEN-MSI init

2020-08-24 Thread Jürgen Groß

On 24.08.20 23:21, Thomas Gleixner wrote:

On Mon, Aug 24 2020 at 06:59, Jürgen Groß wrote:

On 21.08.20 02:24, Thomas Gleixner wrote:

+static __init void xen_setup_pci_msi(void)
+{
+   if (xen_initial_domain()) {
+   x86_msi.setup_msi_irqs = xen_initdom_setup_msi_irqs;
+   x86_msi.teardown_msi_irqs = xen_teardown_msi_irqs;
+   x86_msi.restore_msi_irqs = xen_initdom_restore_msi_irqs;
+   pci_msi_ignore_mask = 1;


This is wrong, as a PVH initial domain shouldn't do the pv settings.

The "if (xen_initial_domain())" should be inside the pv case, like:

if (xen_pv_domain()) {
if (xen_initial_domain()) {
...
} else {
...
}
} else if (xen_hvm_domain()) {
...


I still think it does the right thing depending on the place it is
called from, but even if so, it's completely unreadable gunk. I'll fix
that proper.


The main issue is that xen_initial_domain() and xen_pv_domain() are
orthogonal to each other. So xen_initial_domain() can either be true
for xen_pv_domain() (the "classic" pv dom0) or for xen_hvm_domain()
(the new PVH dom0).


Juergen


Re: [PATCH] iio: dac: ad5593r: Dynamically set AD5593R channel modes

2020-08-24 Thread AceLan Kao
Hi William,

Please read my comment below.

William Sung  於 2020年8月24日 週一 下午1:43寫道:
>
> To use ad5593r more flexibly, we use the module parameter to setting the
> channel modes dynamically whenever the module probe up. Users can pass
> the channel modes to the module parameter for allocating the
> functionality of channels as desired.
>
> For example:
> * Use in the kernel command line:
> Users can add the module parameter in the kernel command line such as
>
> "ad5593r.ch_mode_cmdline=88001122"
>
> "88001122" means the channel mode setting for each channel. The most
> left side indicates the mode of channel 7, and the most right side
> indicates the mode of channel 0.
>
> * Use when manually probe the module:
> Similar to the kernel command line usage, users can enter
>
> "modprobe ad5593r ch_mode_probe=88001122"
The usage of the parameters do not match the one written in the code,
which is "ch_mode"

>
> to start the ad5593r module with the desired channel mode setting.
>
> Signed-off-by: William Sung 
> ---
>  drivers/iio/dac/ad5592r-base.c | 33 ++--
>  drivers/iio/dac/ad5592r-base.h |  4 +++
>  drivers/iio/dac/ad5593r.c  | 55 ++
>  3 files changed, 89 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/iio/dac/ad5592r-base.c b/drivers/iio/dac/ad5592r-base.c
> index cc4875660a69..cd69a34fa21e 100644
> --- a/drivers/iio/dac/ad5592r-base.c
> +++ b/drivers/iio/dac/ad5592r-base.c
> @@ -21,6 +21,10 @@
>
>  #include "ad5592r-base.h"
>
> +/* Parameters for dynamic channel mode setting */
> +static u8 update_channel_mode;
> +static u8 new_channel_modes[AD559XR_CHANNEL_NR];
> +
>  static int ad5592r_gpio_get(struct gpio_chip *chip, unsigned offset)
>  {
> struct ad5592r_state *st = gpiochip_get_data(chip);
> @@ -132,7 +136,7 @@ static int ad5592r_gpio_init(struct ad5592r_state *st)
>
> st->gpiochip.label = dev_name(st->dev);
> st->gpiochip.base = -1;
> -   st->gpiochip.ngpio = 8;
> +   st->gpiochip.ngpio = AD559XR_CHANNEL_NR;
> st->gpiochip.parent = st->dev;
> st->gpiochip.can_sleep = true;
> st->gpiochip.direction_input = ad5592r_gpio_direction_input;
> @@ -287,6 +291,14 @@ static int ad5592r_set_channel_modes(struct 
> ad5592r_state *st)
> return ret;
>  }
>
> +static void ad5592r_set_def_channel_modes(struct ad5592r_state *st)
> +{
> +   int i;
> +
> +   for (i = 0; i < ARRAY_SIZE(st->channel_modes); i++)
> +   st->channel_modes[i] = new_channel_modes[i];
> +}
> +
>  static int ad5592r_reset_channel_modes(struct ad5592r_state *st)
>  {
> int i;
> @@ -532,6 +544,10 @@ static int ad5592r_alloc_channels(struct iio_dev 
> *iio_dev)
> st->channel_offstate[reg] = tmp;
> }
>
> +   /* Update default channel modes set by external module */
> +   if (update_channel_mode == 1)
> +   ad5592r_set_def_channel_modes(st);
> +
> channels = devm_kcalloc(st->dev,
> 1 + 2 * num_channels, sizeof(*channels),
> GFP_KERNEL);
> @@ -567,7 +583,7 @@ static int ad5592r_alloc_channels(struct iio_dev *iio_dev)
> }
>
> channels[curr_channel].type = IIO_TEMP;
> -   channels[curr_channel].channel = 8;
> +   channels[curr_channel].channel = AD559XR_CHANNEL_NR;
> channels[curr_channel].info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
>BIT(IIO_CHAN_INFO_SCALE) |
>BIT(IIO_CHAN_INFO_OFFSET);
> @@ -589,6 +605,17 @@ static void ad5592r_init_scales(struct ad5592r_state 
> *st, int vref_mV)
> div_s64_rem(tmp * 2, 10LL, >scale_avail[1][1]);
>  }
>
> +void ad5592r_update_default_channel_modes(u8 *new_modes)
> +{
> +   int idx = 0;
> +
> +   update_channel_mode = 1;
> +   for (idx = 0; idx < AD559XR_CHANNEL_NR; idx++)
> +   new_channel_modes[idx] = new_modes[idx];
> +
> +}
> +EXPORT_SYMBOL_GPL(ad5592r_update_default_channel_modes);
> +
>  int ad5592r_probe(struct device *dev, const char *name,
> const struct ad5592r_rw_ops *ops)
>  {
> @@ -603,7 +630,7 @@ int ad5592r_probe(struct device *dev, const char *name,
> st = iio_priv(iio_dev);
> st->dev = dev;
> st->ops = ops;
> -   st->num_channels = 8;
> +   st->num_channels = AD559XR_CHANNEL_NR;
> dev_set_drvdata(dev, iio_dev);
>
> st->reg = devm_regulator_get_optional(dev, "vref");
> diff --git a/drivers/iio/dac/ad5592r-base.h b/drivers/iio/dac/ad5592r-base.h
> index 23dac2f1ff8a..40ad6369e660 100644
> --- a/drivers/iio/dac/ad5592r-base.h
> +++ b/drivers/iio/dac/ad5592r-base.h
> @@ -39,6 +39,9 @@ enum ad5592r_registers {
>  #define AD5592R_REG_CTRL_ADC_RANGE BIT(5)
>  #define AD5592R_REG_CTRL_DAC_RANGE BIT(4)
>
> +/* Define quantity of channels of AD5592R/AD5593R */
> +#define AD559XR_CHANNEL_NR 8
> +
>  struct 

Re: [PATCH bpf] bpf, sysctl: let bpf_stats_handler take a kernel pointer buffer

2020-08-24 Thread Alexei Starovoitov
On Mon, Aug 24, 2020 at 7:20 AM Tobias Klauser  wrote:
>
> Commit 32927393dc1c ("sysctl: pass kernel pointers to ->proc_handler")
> changed ctl_table.proc_handler to take a kernel pointer. Adjust the
> signature of bpf_stats_handler to match ctl_table.proc_handler which
> fixes the following sparse warning:
>
> kernel/sysctl.c:226:49: warning: incorrect type in argument 3 (different 
> address spaces)
> kernel/sysctl.c:226:49:expected void *
> kernel/sysctl.c:226:49:got void [noderef] __user *buffer
> kernel/sysctl.c:2640:35: warning: incorrect type in initializer (incompatible 
> argument 3 (different address spaces))
> kernel/sysctl.c:2640:35:expected int ( [usertype] *proc_handler )( ... )
> kernel/sysctl.c:2640:35:got int ( * )( ... )
>
> Fixes: 32927393dc1c ("sysctl: pass kernel pointers to ->proc_handler")
> Cc: Christoph Hellwig 
> Signed-off-by: Tobias Klauser 

Applied. Thanks


Re: [PATCH 5/5] ARM: dts: aspeed: Add Facebook Wedge400 BMC

2020-08-24 Thread Joel Stanley
On Mon, 24 Aug 2020 at 21:20,  wrote:
>
> From: Tao Ren 
>
> Add initial version of device tree for Facebook Wedge400 (AST2500) BMC.
>
> Signed-off-by: Tao Ren 

Reviewed-by: Joel Stanley 

> ---
>  arch/arm/boot/dts/Makefile|   1 +
>  .../boot/dts/aspeed-bmc-facebook-wedge400.dts | 420 ++
>  2 files changed, 421 insertions(+)
>  create mode 100644 arch/arm/boot/dts/aspeed-bmc-facebook-wedge400.dts
>
> diff --git a/arch/arm/boot/dts/Makefile b/arch/arm/boot/dts/Makefile
> index 77f1c95c4e1c..24f7acc0e2ee 100644
> --- a/arch/arm/boot/dts/Makefile
> +++ b/arch/arm/boot/dts/Makefile
> @@ -1354,6 +1354,7 @@ dtb-$(CONFIG_ARCH_ASPEED) += \
> aspeed-bmc-facebook-tiogapass.dtb \
> aspeed-bmc-facebook-wedge40.dtb \
> aspeed-bmc-facebook-wedge100.dtb \
> +   aspeed-bmc-facebook-wedge400.dtb \
> aspeed-bmc-facebook-yamp.dtb \
> aspeed-bmc-facebook-yosemitev2.dtb \
> aspeed-bmc-ibm-rainier.dtb \
> diff --git a/arch/arm/boot/dts/aspeed-bmc-facebook-wedge400.dts 
> b/arch/arm/boot/dts/aspeed-bmc-facebook-wedge400.dts
> new file mode 100644
> index ..ad1fcad3676c
> --- /dev/null
> +++ b/arch/arm/boot/dts/aspeed-bmc-facebook-wedge400.dts
> @@ -0,0 +1,420 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +// Copyright (c) 2019 Facebook Inc.
> +/dts-v1/;
> +
> +#include 
> +#include "ast2500-facebook-netbmc-common.dtsi"
> +
> +/ {
> +   model = "Facebook Wedge 400 BMC";
> +   compatible = "facebook,wedge400-bmc", "aspeed,ast2500";
> +
> +   aliases {
> +   /*
> +* PCA9548 (2-0070) provides 8 channels connecting to
> +* SCM (System Controller Module).
> +*/
> +   i2c16 = 
> +   i2c17 = 
> +   i2c18 = 
> +   i2c19 = 
> +   i2c20 = 
> +   i2c21 = 
> +   i2c22 = 
> +   i2c23 = 
> +
> +   /*
> +* PCA9548 (8-0070) provides 8 channels connecting to
> +* SMB (Switch Main Board).
> +*/
> +   i2c24 = 
> +   i2c25 = 
> +   i2c26 = 
> +   i2c27 = 
> +   i2c28 = 
> +   i2c29 = 
> +   i2c30 = 
> +   i2c31 = 
> +
> +   /*
> +* PCA9548 (11-0076) provides 8 channels connecting to
> +* FCM (Fan Controller Module).
> +*/
> +   i2c32 = 
> +   i2c33 = 
> +   i2c34 = 
> +   i2c35 = 
> +   i2c36 = 
> +   i2c37 = 
> +   i2c38 = 
> +   i2c39 = 
> +
> +   spi2 = _gpio;
> +   };
> +
> +   chosen {
> +   stdout-path = 
> +   bootargs = "console=ttyS0,9600n8 root=/dev/ram rw";
> +   };
> +
> +   ast-adc-hwmon {
> +   compatible = "iio-hwmon";
> +   io-channels = < 0>, < 1>, < 2>, < 3>, < 
> 4>;
> +   };
> +
> +   /*
> +* GPIO-based SPI Master is required to access SPI TPM, because
> +* full-duplex SPI transactions are not supported by ASPEED SPI
> +* Controllers.
> +*/
> +   spi_gpio: spi-gpio {
> +   status = "okay";
> +   compatible = "spi-gpio";
> +   #address-cells = <1>;
> +   #size-cells = <0>;
> +
> +   cs-gpios = < ASPEED_GPIO(R, 2) GPIO_ACTIVE_LOW>;
> +   gpio-sck = < ASPEED_GPIO(R, 3) GPIO_ACTIVE_HIGH>;
> +   gpio-mosi = < ASPEED_GPIO(R, 4) GPIO_ACTIVE_HIGH>;
> +   gpio-miso = < ASPEED_GPIO(R, 5) GPIO_ACTIVE_HIGH>;
> +   num-chipselects = <1>;
> +
> +   tpmdev@0 {
> +   compatible = "tcg,tpm_tis-spi";
> +   spi-max-frequency = <3300>;
> +   reg = <0>;
> +   };
> +   };
> +};
> +
> +/*
> + * Both firmware flashes are 128MB on Wedge400 BMC.
> + */
> +_flash0 {
> +   partitions {
> +   compatible = "fixed-partitions";
> +   #address-cells = <1>;
> +   #size-cells = <1>;
> +
> +   /*
> +* u-boot partition: 384KB.
> +*/
> +   u-boot@0 {
> +   reg = <0x0 0x6>;
> +   label = "u-boot";
> +   };
> +
> +   /*
> +* u-boot environment variables: 128KB.
> +*/
> +   u-boot-env@6 {
> +   reg = <0x6 0x2>;
> +   label = "env";
> +   };
> +
> +   /*
> +* FIT image: 123.5 MB.
> +*/
> +   fit@8 {
> +   reg = <0x8 0x7b8>;
> +   label = "fit";
> +   };
> +
> +   /*
> +* 

[PATCH v4 17/19] media: rkvdec: Use H264_SCALING_MATRIX only when required

2020-08-24 Thread Ezequiel Garcia
Baseline, Main and Extended profiles are specified to
not support a scaling matrix. Also, High profiles
can optionally specify a scaling matrix, using
SPS and PPS NAL units.

To meet this expectation, applications are required to
set the V4L2_CID_MPEG_VIDEO_H264_SCALING_MATRIX control
and set the V4L2_H264_PPS_FLAG_SCALING_MATRIX_PRESENT
flag only when a scaling matrix is specified for a picture.

Implement this on rkvdec, which has hardware support for this
case.

Signed-off-by: Ezequiel Garcia 
Tested-by: Jonas Karlman 
---
 drivers/staging/media/rkvdec/rkvdec-h264.c | 10 +++---
 drivers/staging/media/rkvdec/rkvdec.c  |  1 -
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/media/rkvdec/rkvdec-h264.c 
b/drivers/staging/media/rkvdec/rkvdec-h264.c
index c45cd1617b3b..7cc3b478a5f4 100644
--- a/drivers/staging/media/rkvdec/rkvdec-h264.c
+++ b/drivers/staging/media/rkvdec/rkvdec-h264.c
@@ -708,9 +708,9 @@ static void assemble_hw_pps(struct rkvdec_ctx *ctx,
WRITE_PPS(pps->second_chroma_qp_index_offset,
  SECOND_CHROMA_QP_INDEX_OFFSET);
 
-   /* always use the matrix sent from userspace */
-   WRITE_PPS(1, SCALING_LIST_ENABLE_FLAG);
-
+   WRITE_PPS(!!(pps->flags & V4L2_H264_PPS_FLAG_SCALING_MATRIX_PRESENT),
+ SCALING_LIST_ENABLE_FLAG);
+   /* To be on the safe side, program the scaling matrix address */
scaling_distance = offsetof(struct rkvdec_h264_priv_tbl, scaling_list);
scaling_list_address = h264_ctx->priv_tbl.dma + scaling_distance;
WRITE_PPS(scaling_list_address, SCALING_LIST_ADDRESS);
@@ -792,9 +792,13 @@ static void assemble_hw_scaling_list(struct rkvdec_ctx 
*ctx,
 struct rkvdec_h264_run *run)
 {
const struct v4l2_ctrl_h264_scaling_matrix *scaling = 
run->scaling_matrix;
+   const struct v4l2_ctrl_h264_pps *pps = run->pps;
struct rkvdec_h264_ctx *h264_ctx = ctx->priv;
struct rkvdec_h264_priv_tbl *tbl = h264_ctx->priv_tbl.cpu;
 
+   if (!(pps->flags & V4L2_H264_PPS_FLAG_SCALING_MATRIX_PRESENT))
+   return;
+
BUILD_BUG_ON(sizeof(tbl->scaling_list.scaling_list_4x4) !=
 sizeof(scaling->scaling_list_4x4));
BUILD_BUG_ON(sizeof(tbl->scaling_list.scaling_list_8x8) !=
diff --git a/drivers/staging/media/rkvdec/rkvdec.c 
b/drivers/staging/media/rkvdec/rkvdec.c
index 9f59dfb62d3f..d25c4a37e2af 100644
--- a/drivers/staging/media/rkvdec/rkvdec.c
+++ b/drivers/staging/media/rkvdec/rkvdec.c
@@ -68,7 +68,6 @@ static const struct rkvdec_ctrl_desc rkvdec_h264_ctrl_descs[] 
= {
.cfg.id = V4L2_CID_MPEG_VIDEO_H264_PPS,
},
{
-   .mandatory = true,
.cfg.id = V4L2_CID_MPEG_VIDEO_H264_SCALING_MATRIX,
},
{
-- 
2.27.0



Re: fsl_espi errors on v5.7.15

2020-08-24 Thread Chris Packham

On 25/08/20 10:04 am, Chris Packham wrote:
>
> On 20/08/20 9:08 am, Chris Packham wrote:
>>
>> On 19/08/20 6:15 pm, Heiner Kallweit wrote:
>>> On 19.08.2020 00:44, Chris Packham wrote:
 Hi Again,

 On 17/08/20 9:09 am, Chris Packham wrote:

> On 14/08/20 6:19 pm, Heiner Kallweit wrote:
>> On 14.08.2020 04:48, Chris Packham wrote:
>>> Hi,
>>>
>>> I'm seeing a problem with accessing spi-nor after upgrading a T2081
>>> based system to linux v5.7.15
>>>
>>> For this board u-boot and the u-boot environment live on spi-nor.
>>>
>>> When I use fw_setenv from userspace I get the following kernel logs
>>>
>>> # fw_setenv foo=1
>>> fsl_espi ffe11.spi: Transfer done but SPIE_DON isn't set!
>>> fsl_espi ffe11.spi: Transfer done but SPIE_DON isn't set!
>>> fsl_espi ffe11.spi: Transfer done but SPIE_DON isn't set!
>>> fsl_espi ffe11.spi: Transfer done but SPIE_DON isn't set!
>>> fsl_espi ffe11.spi: Transfer done but SPIE_DON isn't set!
>>> fsl_espi ffe11.spi: Transfer done but SPIE_DON isn't set!
>>> fsl_espi ffe11.spi: Transfer done but SPIE_DON isn't set!
>>> fsl_espi ffe11.spi: Transfer done but SPIE_DON isn't set!
>>> fsl_espi ffe11.spi: Transfer done but SPIE_DON isn't set!
>>> fsl_espi ffe11.spi: Transfer done but SPIE_DON isn't set!
>>> fsl_espi ffe11.spi: Transfer done but SPIE_DON isn't set!
>>> fsl_espi ffe11.spi: Transfer done but SPIE_DON isn't set!
>>> fsl_espi ffe11.spi: Transfer done but SPIE_DON isn't set!
>>> fsl_espi ffe11.spi: Transfer done but SPIE_DON isn't set!
>>> fsl_espi ffe11.spi: Transfer done but rx/tx fifo's aren't 
>>> empty!
>>> fsl_espi ffe11.spi: SPIE_RXCNT = 1, SPIE_TXCNT = 32
>>> fsl_espi ffe11.spi: Transfer done but rx/tx fifo's aren't 
>>> empty!
>>> fsl_espi ffe11.spi: SPIE_RXCNT = 1, SPIE_TXCNT = 32
>>> fsl_espi ffe11.spi: Transfer done but rx/tx fifo's aren't 
>>> empty!
>>> fsl_espi ffe11.spi: SPIE_RXCNT = 1, SPIE_TXCNT = 32
>>> ...
>>>
>> This error reporting doesn't exist yet in 4.4. So you may have an 
>> issue
>> under 4.4 too, it's just not reported.
>> Did you verify that under 4.4 fw_setenv actually has an effect?
> Just double checked and yes under 4.4 the setting does get saved.
>>> If I run fw_printenv (before getting it into a bad state) it is 
>>> able to
>>> display the content of the boards u-boot environment.
>>>
>> This might indicate an issue with spi being locked. I've seen 
>> related
>> questions, just use the search engine of your choice and check for
>> fw_setenv and locked.
> I'm running a version of fw_setenv which includes
> https://gitlab.denx.de/u-boot/u-boot/-/commit/db820159 so it 
> shouldn't
> be locking things unnecessarily.
>>> If been unsuccessful in producing a setup for bisecting the 
>>> issue. I do
>>> know the issue doesn't occur on the old 4.4.x based kernel but 
>>> that's
>>> probably not much help.
>>>
>>> Any pointers on what the issue (and/or solution) might be.
 I finally managed to get our board running with a vanilla kernel. With
 corenet64_smp_defconfig I occasionally see

     fsl_espi ffe11.spi: Transfer done but SPIE_DON isn't set!

 other than the message things seem to be working.

 With a custom defconfig I see

     fsl_espi ffe11.spi: Transfer done but SPIE_DON isn't set!
     fsl_espi ffe11.spi: Transfer done but rx/tx fifo's aren't 
 empty!
     fsl_espi ffe11.spi: SPIE_RXCNT = 1, SPIE_TXCNT = 32
     ...

 and access to the spi-nor does not work until the board is reset.

 I'll try and pick apart the differences between the two defconfigs.
>>
>> I now think my earlier testing is invalid. I have seen the problem 
>> with either defconfig if I try hard enough. I had convinced myself 
>> that the problem was CONFIG_PREEMPT but that was before I found 
>> boot-to-boot differences with the same kernel.
>>
>> It's possible that I'm chasing multiple issues with the same symptom.
>>
>> The error I'm most concerned with is in the sequence
>> 1. boot with old image
>> 2. write environment
>> 3. boot with new image
>> 4. write environment
>> 5. write fails and environment is corrupted
>>
>> After I recover the system things sometimes seem fine. Until I repeat 
>> the sequence above.
>>
>>> Also relevant may be:
>>> - Which dts are you using?
>> Custom but based heavily on the t2080rdb.
>>> - What's the spi-nor type, and at which frequency are you operating it?
>> The board has several alternate parts for the spi-nor so the dts just 
>> specifies compatible = "jedec,spi-nor" the actual chip detected on 
>> the board I have is "n25q032a (4096 Kbytes)". The dts sets 
>> spi-max-frequency = <1000> I haven't 

[PATCH v4 14/19] media: cedrus: h264: Properly configure reference field

2020-08-24 Thread Ezequiel Garcia
From: Jernej Skrabec 

When interlaced H264 content is being decoded, references must indicate
which field is being referenced. Currently this was done by checking
capture buffer flags. However, that is not correct because capture
buffer may hold both fields.

Fix this by checking newly introduced flags in reference lists.

Signed-off-by: Jernej Skrabec 
Reviewed-by: Nicolas Dufresne 
---
 drivers/staging/media/sunxi/cedrus/cedrus_h264.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_h264.c 
b/drivers/staging/media/sunxi/cedrus/cedrus_h264.c
index c8f626fdd3dd..1e89a8438f36 100644
--- a/drivers/staging/media/sunxi/cedrus/cedrus_h264.c
+++ b/drivers/staging/media/sunxi/cedrus/cedrus_h264.c
@@ -182,7 +182,6 @@ static void _cedrus_write_ref_list(struct cedrus_ctx *ctx,
for (i = 0; i < num_ref; i++) {
const struct v4l2_h264_dpb_entry *dpb;
const struct cedrus_buffer *cedrus_buf;
-   const struct vb2_v4l2_buffer *ref_buf;
unsigned int position;
int buf_idx;
u8 dpb_idx;
@@ -197,12 +196,11 @@ static void _cedrus_write_ref_list(struct cedrus_ctx *ctx,
if (buf_idx < 0)
continue;
 
-   ref_buf = to_vb2_v4l2_buffer(cap_q->bufs[buf_idx]);
-   cedrus_buf = vb2_v4l2_to_cedrus_buffer(ref_buf);
+   cedrus_buf = vb2_to_cedrus_buffer(cap_q->bufs[buf_idx]);
position = cedrus_buf->codec.h264.position;
 
sram_array[i] |= position << 1;
-   if (ref_buf->field == V4L2_FIELD_BOTTOM)
+   if (ref_list[i].fields & V4L2_H264_BOTTOM_FIELD_REF)
sram_array[i] |= BIT(0);
}
 
-- 
2.27.0



[PATCH v4 13/19] media: rkvdec: Don't require unneeded H264_SLICE_PARAMS

2020-08-24 Thread Ezequiel Garcia
Now that slice invariant parameters have been moved,
the driver no longer needs this control, so drop it.

Signed-off-by: Ezequiel Garcia 
Reviewed-by: Jonas Karlman 
Tested-by: Jonas Karlman 
---
v2:
* Fix wrongly removed SPS.
---
 drivers/staging/media/rkvdec/rkvdec-h264.c | 4 
 drivers/staging/media/rkvdec/rkvdec.c  | 5 -
 2 files changed, 9 deletions(-)

diff --git a/drivers/staging/media/rkvdec/rkvdec-h264.c 
b/drivers/staging/media/rkvdec/rkvdec-h264.c
index 90f211839be2..c45cd1617b3b 100644
--- a/drivers/staging/media/rkvdec/rkvdec-h264.c
+++ b/drivers/staging/media/rkvdec/rkvdec-h264.c
@@ -109,7 +109,6 @@ struct rkvdec_h264_reflists {
 struct rkvdec_h264_run {
struct rkvdec_run base;
const struct v4l2_ctrl_h264_decode_params *decode_params;
-   const struct v4l2_ctrl_h264_slice_params *slices_params;
const struct v4l2_ctrl_h264_sps *sps;
const struct v4l2_ctrl_h264_pps *pps;
const struct v4l2_ctrl_h264_scaling_matrix *scaling_matrix;
@@ -1066,9 +1065,6 @@ static void rkvdec_h264_run_preamble(struct rkvdec_ctx 
*ctx,
ctrl = v4l2_ctrl_find(>ctrl_hdl,
  V4L2_CID_MPEG_VIDEO_H264_DECODE_PARAMS);
run->decode_params = ctrl ? ctrl->p_cur.p : NULL;
-   ctrl = v4l2_ctrl_find(>ctrl_hdl,
- V4L2_CID_MPEG_VIDEO_H264_SLICE_PARAMS);
-   run->slices_params = ctrl ? ctrl->p_cur.p : NULL;
ctrl = v4l2_ctrl_find(>ctrl_hdl,
  V4L2_CID_MPEG_VIDEO_H264_SPS);
run->sps = ctrl ? ctrl->p_cur.p : NULL;
diff --git a/drivers/staging/media/rkvdec/rkvdec.c 
b/drivers/staging/media/rkvdec/rkvdec.c
index c8151328fb70..7c5129593921 100644
--- a/drivers/staging/media/rkvdec/rkvdec.c
+++ b/drivers/staging/media/rkvdec/rkvdec.c
@@ -59,11 +59,6 @@ static const struct rkvdec_ctrl_desc 
rkvdec_h264_ctrl_descs[] = {
.mandatory = true,
.cfg.id = V4L2_CID_MPEG_VIDEO_H264_DECODE_PARAMS,
},
-   {
-   .per_request = true,
-   .mandatory = true,
-   .cfg.id = V4L2_CID_MPEG_VIDEO_H264_SLICE_PARAMS,
-   },
{
.per_request = true,
.mandatory = true,
-- 
2.27.0



  1   2   3   4   5   6   7   8   9   10   >