[PATCH] drm/nouveau/i2c: do not use assignment in if condition

sunran001@208suo.com posted 1 patch 2 years, 7 months ago
There is a newer version of this series
drivers/gpu/drm/nouveau/nvkm/subdev/i2c/aux.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
[PATCH] drm/nouveau/i2c: do not use assignment in if condition
Posted by sunran001@208suo.com 2 years, 7 months ago
Assignments in if condition are less readable and error-prone.  Fixes
also checkpatch warning:

ERROR: do not use assignment in if condition

Signed-off-by: Ran Sun <sunran001@208suo.com>
---
  drivers/gpu/drm/nouveau/nvkm/subdev/i2c/aux.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/aux.c 
b/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/aux.c
index d063d0dc13c5..098051d3755c 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/aux.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/aux.c
@@ -209,7 +209,8 @@ nvkm_i2c_aux_new_(const struct nvkm_i2c_aux_func 
*func,
            struct nvkm_i2c_pad *pad, int id,
            struct nvkm_i2c_aux **paux)
  {
-    if (!(*paux = kzalloc(sizeof(**paux), GFP_KERNEL)))
+    *paux = kzalloc(sizeof(**paux), GFP_KERNEL);
+    if (!*paux)
          return -ENOMEM;
      return nvkm_i2c_aux_ctor(func, pad, id, *paux);
  }
Re: [PATCH] drm/nouveau/i2c: do not use assignment in if condition
Posted by Karol Herbst 2 years, 6 months ago
On Mon, Jul 10, 2023 at 9:23 AM <sunran001@208suo.com> wrote:
>
> Assignments in if condition are less readable and error-prone.  Fixes
> also checkpatch warning:
>
> ERROR: do not use assignment in if condition
>
> Signed-off-by: Ran Sun <sunran001@208suo.com>
> ---
>   drivers/gpu/drm/nouveau/nvkm/subdev/i2c/aux.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/aux.c
> b/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/aux.c
> index d063d0dc13c5..098051d3755c 100644
> --- a/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/aux.c
> +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/aux.c
> @@ -209,7 +209,8 @@ nvkm_i2c_aux_new_(const struct nvkm_i2c_aux_func
> *func,
>             struct nvkm_i2c_pad *pad, int id,
>             struct nvkm_i2c_aux **paux)
>   {
> -    if (!(*paux = kzalloc(sizeof(**paux), GFP_KERNEL)))
> +    *paux = kzalloc(sizeof(**paux), GFP_KERNEL);
> +    if (!*paux)
>           return -ENOMEM;
>       return nvkm_i2c_aux_ctor(func, pad, id, *paux);
>   }
>

Reviewed-by: Karol Herbst <kherbst@redhat.com>