Re: [PATCH v3 2/2] remoteproc: k3-r5: Do not allow core1 to power up before core0 via sysfs

2024-05-18 Thread Christophe JAILLET

Le 30/04/2024 à 12:53, Beleswar Padhi a écrit :

PSC controller has a limitation that it can only power-up the second
core when the first core is in ON state. Power-state for core0 should be
equal to or higher than core1.

Therefore, prevent core1 from powering up before core0 during the start
process from sysfs. Similarly, prevent core0 from shutting down before
core1 has been shut down from sysfs.

Fixes: 6dedbd1d5443 ("remoteproc: k3-r5: Add a remoteproc driver for R5F 
subsystem")

Signed-off-by: Beleswar Padhi 
---
  drivers/remoteproc/ti_k3_r5_remoteproc.c | 23 +--
  1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/drivers/remoteproc/ti_k3_r5_remoteproc.c 
b/drivers/remoteproc/ti_k3_r5_remoteproc.c
index 6d6afd6beb3a..1799b4f6d11e 100644
--- a/drivers/remoteproc/ti_k3_r5_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_r5_remoteproc.c
@@ -548,7 +548,7 @@ static int k3_r5_rproc_start(struct rproc *rproc)
struct k3_r5_rproc *kproc = rproc->priv;
struct k3_r5_cluster *cluster = kproc->cluster;
struct device *dev = kproc->dev;
-   struct k3_r5_core *core;
+   struct k3_r5_core *core0, *core;
u32 boot_addr;
int ret;
  
@@ -574,6 +574,15 @@ static int k3_r5_rproc_start(struct rproc *rproc)

goto unroll_core_run;
}
} else {
+   /* do not allow core 1 to start before core 0 */
+   core0 = list_first_entry(>cores, struct k3_r5_core,
+elem);
+   if (core != core0 && core0->rproc->state == RPROC_OFFLINE) {
+   dev_err(dev, "%s: can not start core 1 before core 0\n",
+   __func__);
+   return -EPERM;
+   }
+
ret = k3_r5_core_run(core);
if (ret)
goto put_mbox;
@@ -619,7 +628,8 @@ static int k3_r5_rproc_stop(struct rproc *rproc)
  {
struct k3_r5_rproc *kproc = rproc->priv;
struct k3_r5_cluster *cluster = kproc->cluster;
-   struct k3_r5_core *core = kproc->core;
+   struct device *dev = kproc->dev;
+   struct k3_r5_core *core1, *core = kproc->core;
int ret;
  
  	/* halt all applicable cores */

@@ -632,6 +642,15 @@ static int k3_r5_rproc_stop(struct rproc *rproc)
}
}
} else {
+   /* do not allow core 0 to stop before core 1 */
+   core1 = list_last_entry(>cores, struct k3_r5_core,
+   elem);
+   if (core != core1 && core1->rproc->state != RPROC_OFFLINE) {
+   dev_err(dev, "%s: can not stop core 0 before core 1\n",
+   __func__);
+   return -EPERM;


Hi,

this patch has already reached -next, but should this "return -EPERM;" be :
ret = -EPERM;
goto put_mbox;

instead?

CJ


+   }
+
ret = k3_r5_core_halt(core);
if (ret)
goto out;





[PATCH v2] vhost-vdpa: Remove usage of the deprecated ida_simple_xx() API

2024-04-14 Thread Christophe JAILLET
ida_alloc() and ida_free() should be preferred to the deprecated
ida_simple_get() and ida_simple_remove().

Note that the upper limit of ida_simple_get() is exclusive, but the one of
ida_alloc_max() is inclusive. So a -1 has been added when needed.

Signed-off-by: Christophe JAILLET 
Reviewed-by: Simon Horman 
---
Changes in V2:
   - fix a typo in the commit message
   - Add a R-b tag

V1: 
https://lore.kernel.org/all/bd27d4066f7749997a75cf4111fbf51e11d5898d.1705350942.git.christophe.jail...@wanadoo.fr/
---
 drivers/vhost/vdpa.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
index ba52d128aeb7..63a53680a85c 100644
--- a/drivers/vhost/vdpa.c
+++ b/drivers/vhost/vdpa.c
@@ -1548,7 +1548,7 @@ static void vhost_vdpa_release_dev(struct device *device)
struct vhost_vdpa *v =
   container_of(device, struct vhost_vdpa, dev);
 
-   ida_simple_remove(_vdpa_ida, v->minor);
+   ida_free(_vdpa_ida, v->minor);
kfree(v->vqs);
kfree(v);
 }
@@ -1571,8 +1571,8 @@ static int vhost_vdpa_probe(struct vdpa_device *vdpa)
if (!v)
return -ENOMEM;
 
-   minor = ida_simple_get(_vdpa_ida, 0,
-  VHOST_VDPA_DEV_MAX, GFP_KERNEL);
+   minor = ida_alloc_max(_vdpa_ida, VHOST_VDPA_DEV_MAX - 1,
+ GFP_KERNEL);
if (minor < 0) {
kfree(v);
return minor;
-- 
2.44.0




Re: [PATCH] vhost-vdpa: Remove usage of the deprecated ida_simple_xx() API

2024-04-14 Thread Christophe JAILLET

Le 14/04/2024 à 10:35, Michael S. Tsirkin a écrit :

On Mon, Jan 15, 2024 at 09:35:50PM +0100, Christophe JAILLET wrote:

ida_alloc() and ida_free() should be preferred to the deprecated
ida_simple_get() and ida_simple_remove().

Note that the upper limit of ida_simple_get() is exclusive, buInputt the one of


What's buInputt? But?


Yes, sorry. It is "but".

Let me know if I should send a v2, or if it can be fixed when it is applied.

CJ




ida_alloc_max() is inclusive. So a -1 has been added when needed.

Signed-off-by: Christophe JAILLET 



Jason, wanna ack?


---
  drivers/vhost/vdpa.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
index bc4a51e4638b..849b9d2dd51f 100644
--- a/drivers/vhost/vdpa.c
+++ b/drivers/vhost/vdpa.c
@@ -1534,7 +1534,7 @@ static void vhost_vdpa_release_dev(struct device *device)
struct vhost_vdpa *v =
   container_of(device, struct vhost_vdpa, dev);
  
-	ida_simple_remove(_vdpa_ida, v->minor);

+   ida_free(_vdpa_ida, v->minor);
kfree(v->vqs);
kfree(v);
  }
@@ -1557,8 +1557,8 @@ static int vhost_vdpa_probe(struct vdpa_device *vdpa)
if (!v)
return -ENOMEM;
  
-	minor = ida_simple_get(_vdpa_ida, 0,

-  VHOST_VDPA_DEV_MAX, GFP_KERNEL);
+   minor = ida_alloc_max(_vdpa_ida, VHOST_VDPA_DEV_MAX - 1,
+ GFP_KERNEL);
if (minor < 0) {
kfree(v);
return minor;
--
2.43.0









Re: [PATCH] vhost-vdpa: Remove usage of the deprecated ida_simple_xx() API

2024-04-14 Thread Christophe JAILLET

Le 16/01/2024 à 15:57, Simon Horman a écrit :

On Mon, Jan 15, 2024 at 09:35:50PM +0100, Christophe JAILLET wrote:

ida_alloc() and ida_free() should be preferred to the deprecated
ida_simple_get() and ida_simple_remove().

Note that the upper limit of ida_simple_get() is exclusive, buInputt the one of
ida_alloc_max() is inclusive. So a -1 has been added when needed.

Signed-off-by: Christophe JAILLET 


Reviewed-by: Simon Horman 





Hi,

polite reminder ;-)

CJ



[PATCH] vhost-vdpa: Remove usage of the deprecated ida_simple_xx() API

2024-01-15 Thread Christophe JAILLET
ida_alloc() and ida_free() should be preferred to the deprecated
ida_simple_get() and ida_simple_remove().

Note that the upper limit of ida_simple_get() is exclusive, buInputt the one of
ida_alloc_max() is inclusive. So a -1 has been added when needed.

Signed-off-by: Christophe JAILLET 
---
 drivers/vhost/vdpa.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
index bc4a51e4638b..849b9d2dd51f 100644
--- a/drivers/vhost/vdpa.c
+++ b/drivers/vhost/vdpa.c
@@ -1534,7 +1534,7 @@ static void vhost_vdpa_release_dev(struct device *device)
struct vhost_vdpa *v =
   container_of(device, struct vhost_vdpa, dev);
 
-   ida_simple_remove(_vdpa_ida, v->minor);
+   ida_free(_vdpa_ida, v->minor);
kfree(v->vqs);
kfree(v);
 }
@@ -1557,8 +1557,8 @@ static int vhost_vdpa_probe(struct vdpa_device *vdpa)
if (!v)
return -ENOMEM;
 
-   minor = ida_simple_get(_vdpa_ida, 0,
-  VHOST_VDPA_DEV_MAX, GFP_KERNEL);
+   minor = ida_alloc_max(_vdpa_ida, VHOST_VDPA_DEV_MAX - 1,
+ GFP_KERNEL);
if (minor < 0) {
kfree(v);
return minor;
-- 
2.43.0




[PATCH] rpmsg: Remove usage of the deprecated ida_simple_xx() API

2024-01-14 Thread Christophe JAILLET
ida_alloc() and ida_free() should be preferred to the deprecated
ida_simple_get() and ida_simple_remove().

Note that the upper limit of ida_simple_get() is exclusive, but the one of
ida_alloc_max() is inclusive. So a -1 has been added when needed.

Signed-off-by: Christophe JAILLET 
---
 drivers/rpmsg/rpmsg_char.c | 12 ++--
 drivers/rpmsg/rpmsg_ctrl.c | 12 ++--
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/rpmsg/rpmsg_char.c b/drivers/rpmsg/rpmsg_char.c
index 09833ad05da7..1cb8d7474428 100644
--- a/drivers/rpmsg/rpmsg_char.c
+++ b/drivers/rpmsg/rpmsg_char.c
@@ -399,8 +399,8 @@ static void rpmsg_eptdev_release_device(struct device *dev)
 {
struct rpmsg_eptdev *eptdev = dev_to_eptdev(dev);
 
-   ida_simple_remove(_ept_ida, dev->id);
-   ida_simple_remove(_minor_ida, MINOR(eptdev->dev.devt));
+   ida_free(_ept_ida, dev->id);
+   ida_free(_minor_ida, MINOR(eptdev->dev.devt));
kfree(eptdev);
 }
 
@@ -441,12 +441,12 @@ static int rpmsg_chrdev_eptdev_add(struct rpmsg_eptdev 
*eptdev, struct rpmsg_cha
 
eptdev->chinfo = chinfo;
 
-   ret = ida_simple_get(_minor_ida, 0, RPMSG_DEV_MAX, GFP_KERNEL);
+   ret = ida_alloc_max(_minor_ida, RPMSG_DEV_MAX - 1, GFP_KERNEL);
if (ret < 0)
goto free_eptdev;
dev->devt = MKDEV(MAJOR(rpmsg_major), ret);
 
-   ret = ida_simple_get(_ept_ida, 0, 0, GFP_KERNEL);
+   ret = ida_alloc(_ept_ida, GFP_KERNEL);
if (ret < 0)
goto free_minor_ida;
dev->id = ret;
@@ -462,9 +462,9 @@ static int rpmsg_chrdev_eptdev_add(struct rpmsg_eptdev 
*eptdev, struct rpmsg_cha
return ret;
 
 free_ept_ida:
-   ida_simple_remove(_ept_ida, dev->id);
+   ida_free(_ept_ida, dev->id);
 free_minor_ida:
-   ida_simple_remove(_minor_ida, MINOR(dev->devt));
+   ida_free(_minor_ida, MINOR(dev->devt));
 free_eptdev:
put_device(dev);
kfree(eptdev);
diff --git a/drivers/rpmsg/rpmsg_ctrl.c b/drivers/rpmsg/rpmsg_ctrl.c
index 433253835690..c312794ba4b3 100644
--- a/drivers/rpmsg/rpmsg_ctrl.c
+++ b/drivers/rpmsg/rpmsg_ctrl.c
@@ -130,8 +130,8 @@ static void rpmsg_ctrldev_release_device(struct device *dev)
 {
struct rpmsg_ctrldev *ctrldev = dev_to_ctrldev(dev);
 
-   ida_simple_remove(_ctrl_ida, dev->id);
-   ida_simple_remove(_minor_ida, MINOR(dev->devt));
+   ida_free(_ctrl_ida, dev->id);
+   ida_free(_minor_ida, MINOR(dev->devt));
kfree(ctrldev);
 }
 
@@ -156,12 +156,12 @@ static int rpmsg_ctrldev_probe(struct rpmsg_device *rpdev)
cdev_init(>cdev, _ctrldev_fops);
ctrldev->cdev.owner = THIS_MODULE;
 
-   ret = ida_simple_get(_minor_ida, 0, RPMSG_DEV_MAX, GFP_KERNEL);
+   ret = ida_alloc_max(_minor_ida, RPMSG_DEV_MAX - 1, GFP_KERNEL);
if (ret < 0)
goto free_ctrldev;
dev->devt = MKDEV(MAJOR(rpmsg_major), ret);
 
-   ret = ida_simple_get(_ctrl_ida, 0, 0, GFP_KERNEL);
+   ret = ida_alloc(_ctrl_ida, GFP_KERNEL);
if (ret < 0)
goto free_minor_ida;
dev->id = ret;
@@ -179,9 +179,9 @@ static int rpmsg_ctrldev_probe(struct rpmsg_device *rpdev)
return ret;
 
 free_ctrl_ida:
-   ida_simple_remove(_ctrl_ida, dev->id);
+   ida_free(_ctrl_ida, dev->id);
 free_minor_ida:
-   ida_simple_remove(_minor_ida, MINOR(dev->devt));
+   ida_free(_minor_ida, MINOR(dev->devt));
 free_ctrldev:
put_device(dev);
kfree(ctrldev);
-- 
2.43.0




Re: [PATCH v5] can: virtio: Initial virtio CAN driver.

2024-01-08 Thread Christophe JAILLET

Le 08/01/2024 à 14:10, Mikhail Golubev-Ciuchea a écrit :

From: Harald Mommer 

- CAN Control

   - "ip link set up can0" starts the virtual CAN controller,
   - "ip link set up can0" stops the virtual CAN controller

- CAN RX

   Receive CAN frames. CAN frames can be standard or extended, classic or
   CAN FD. Classic CAN RTR frames are supported.

- CAN TX

   Send CAN frames. CAN frames can be standard or extended, classic or
   CAN FD. Classic CAN RTR frames are supported.

- CAN BusOff indication

   CAN BusOff is handled by a bit in the configuration space.

Signed-off-by: Harald Mommer 
Signed-off-by: Mikhail Golubev-Ciuchea 
Co-developed-by: Marc Kleine-Budde 
Signed-off-by: Marc Kleine-Budde 
Cc: Damir Shaikhutdinov 
---


Hi,
a few nits below, should there be a v6.



+static int virtio_can_alloc_tx_idx(struct virtio_can_priv *priv)
+{
+   int tx_idx;
+
+   tx_idx = ida_alloc_range(>tx_putidx_ida, 0,
+priv->can.echo_skb_max - 1, GFP_KERNEL);
+   if (tx_idx >= 0)
+   atomic_add(1, >tx_inflight);


atomic_inc() ?


+
+   return tx_idx;
+}
+
+static void virtio_can_free_tx_idx(struct virtio_can_priv *priv,
+  unsigned int idx)
+{
+   ida_free(>tx_putidx_ida, idx);
+   atomic_sub(1, >tx_inflight);


atomic_dec() ?


+}


...


+static int virtio_can_probe(struct virtio_device *vdev)
+{
+   struct virtio_can_priv *priv;
+   struct net_device *dev;
+   int err;
+
+   dev = alloc_candev(sizeof(struct virtio_can_priv),
+  VIRTIO_CAN_ECHO_SKB_MAX);
+   if (!dev)
+   return -ENOMEM;
+
+   priv = netdev_priv(dev);
+
+   ida_init(>tx_putidx_ida);
+
+   netif_napi_add(dev, >napi, virtio_can_rx_poll);
+   netif_napi_add(dev, >napi_tx, virtio_can_tx_poll);
+
+   SET_NETDEV_DEV(dev, >dev);
+
+   priv->dev = dev;
+   priv->vdev = vdev;
+   vdev->priv = priv;
+
+   priv->can.do_set_mode = virtio_can_set_mode;
+   /* Set Virtio CAN supported operations */
+   priv->can.ctrlmode_supported = CAN_CTRLMODE_BERR_REPORTING;
+   if (virtio_has_feature(vdev, VIRTIO_CAN_F_CAN_FD)) {
+   err = can_set_static_ctrlmode(dev, CAN_CTRLMODE_FD);
+   if (err != 0)
+   goto on_failure;
+   }
+
+   /* Initialize virtqueues */
+   err = virtio_can_find_vqs(priv);
+   if (err != 0)
+   goto on_failure;
+
+   INIT_LIST_HEAD(>tx_list);
+
+   spin_lock_init(>tx_lock);
+   mutex_init(>ctrl_lock);
+
+   init_completion(>ctrl_done);
+
+   virtio_can_populate_vqs(vdev);
+
+   register_virtio_can_dev(dev);


Check for error?

CJ


+
+   napi_enable(>napi);
+   napi_enable(>napi_tx);
+
+   /* Request device going live */
+   virtio_device_ready(vdev); /* Optionally done by virtio_dev_probe() */
+
+   return 0;
+
+on_failure:
+   virtio_can_free_candev(dev);
+   return err;
+}


...




[PATCH] vdpa: Remove usage of the deprecated ida_simple_xx() API

2023-12-10 Thread Christophe JAILLET
ida_alloc() and ida_free() should be preferred to the deprecated
ida_simple_get() and ida_simple_remove().

This is less verbose.

Signed-off-by: Christophe JAILLET 
---
 drivers/vdpa/vdpa.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c
index a7612e0783b3..d0695680b282 100644
--- a/drivers/vdpa/vdpa.c
+++ b/drivers/vdpa/vdpa.c
@@ -131,7 +131,7 @@ static void vdpa_release_dev(struct device *d)
if (ops->free)
ops->free(vdev);
 
-   ida_simple_remove(_index_ida, vdev->index);
+   ida_free(_index_ida, vdev->index);
kfree(vdev->driver_override);
kfree(vdev);
 }
@@ -205,7 +205,7 @@ struct vdpa_device *__vdpa_alloc_device(struct device 
*parent,
return vdev;
 
 err_name:
-   ida_simple_remove(_index_ida, vdev->index);
+   ida_free(_index_ida, vdev->index);
 err_ida:
kfree(vdev);
 err:
-- 
2.34.1




[PATCH] nvdimm: Remove usage of the deprecated ida_simple_xx() API

2023-12-10 Thread Christophe JAILLET
ida_alloc() and ida_free() should be preferred to the deprecated
ida_simple_get() and ida_simple_remove().

This is less verbose.

Signed-off-by: Christophe JAILLET 
---
 drivers/nvdimm/btt_devs.c   | 6 +++---
 drivers/nvdimm/bus.c| 4 ++--
 drivers/nvdimm/dax_devs.c   | 4 ++--
 drivers/nvdimm/dimm_devs.c  | 4 ++--
 drivers/nvdimm/namespace_devs.c | 7 +++
 drivers/nvdimm/pfn_devs.c   | 4 ++--
 6 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/drivers/nvdimm/btt_devs.c b/drivers/nvdimm/btt_devs.c
index fabbb31f2c35..497fd434a6a1 100644
--- a/drivers/nvdimm/btt_devs.c
+++ b/drivers/nvdimm/btt_devs.c
@@ -19,7 +19,7 @@ static void nd_btt_release(struct device *dev)
 
dev_dbg(dev, "trace\n");
nd_detach_ndns(_btt->dev, _btt->ndns);
-   ida_simple_remove(_region->btt_ida, nd_btt->id);
+   ida_free(_region->btt_ida, nd_btt->id);
kfree(nd_btt->uuid);
kfree(nd_btt);
 }
@@ -191,7 +191,7 @@ static struct device *__nd_btt_create(struct nd_region 
*nd_region,
if (!nd_btt)
return NULL;
 
-   nd_btt->id = ida_simple_get(_region->btt_ida, 0, 0, GFP_KERNEL);
+   nd_btt->id = ida_alloc(_region->btt_ida, GFP_KERNEL);
if (nd_btt->id < 0)
goto out_nd_btt;
 
@@ -217,7 +217,7 @@ static struct device *__nd_btt_create(struct nd_region 
*nd_region,
return dev;
 
 out_put_id:
-   ida_simple_remove(_region->btt_ida, nd_btt->id);
+   ida_free(_region->btt_ida, nd_btt->id);
 
 out_nd_btt:
kfree(nd_btt);
diff --git a/drivers/nvdimm/bus.c b/drivers/nvdimm/bus.c
index 5852fe290523..ef3d0f83318b 100644
--- a/drivers/nvdimm/bus.c
+++ b/drivers/nvdimm/bus.c
@@ -285,7 +285,7 @@ static void nvdimm_bus_release(struct device *dev)
struct nvdimm_bus *nvdimm_bus;
 
nvdimm_bus = container_of(dev, struct nvdimm_bus, dev);
-   ida_simple_remove(_ida, nvdimm_bus->id);
+   ida_free(_ida, nvdimm_bus->id);
kfree(nvdimm_bus);
 }
 
@@ -342,7 +342,7 @@ struct nvdimm_bus *nvdimm_bus_register(struct device 
*parent,
INIT_LIST_HEAD(_bus->list);
INIT_LIST_HEAD(_bus->mapping_list);
init_waitqueue_head(_bus->wait);
-   nvdimm_bus->id = ida_simple_get(_ida, 0, 0, GFP_KERNEL);
+   nvdimm_bus->id = ida_alloc(_ida, GFP_KERNEL);
if (nvdimm_bus->id < 0) {
kfree(nvdimm_bus);
return NULL;
diff --git a/drivers/nvdimm/dax_devs.c b/drivers/nvdimm/dax_devs.c
index 3bd61f245788..6b4922de3047 100644
--- a/drivers/nvdimm/dax_devs.c
+++ b/drivers/nvdimm/dax_devs.c
@@ -18,7 +18,7 @@ static void nd_dax_release(struct device *dev)
 
dev_dbg(dev, "trace\n");
nd_detach_ndns(dev, _pfn->ndns);
-   ida_simple_remove(_region->dax_ida, nd_pfn->id);
+   ida_free(_region->dax_ida, nd_pfn->id);
kfree(nd_pfn->uuid);
kfree(nd_dax);
 }
@@ -55,7 +55,7 @@ static struct nd_dax *nd_dax_alloc(struct nd_region 
*nd_region)
return NULL;
 
nd_pfn = _dax->nd_pfn;
-   nd_pfn->id = ida_simple_get(_region->dax_ida, 0, 0, GFP_KERNEL);
+   nd_pfn->id = ida_alloc(_region->dax_ida, GFP_KERNEL);
if (nd_pfn->id < 0) {
kfree(nd_dax);
return NULL;
diff --git a/drivers/nvdimm/dimm_devs.c b/drivers/nvdimm/dimm_devs.c
index 1273873582be..3ceddae0509f 100644
--- a/drivers/nvdimm/dimm_devs.c
+++ b/drivers/nvdimm/dimm_devs.c
@@ -194,7 +194,7 @@ static void nvdimm_release(struct device *dev)
 {
struct nvdimm *nvdimm = to_nvdimm(dev);
 
-   ida_simple_remove(_ida, nvdimm->id);
+   ida_free(_ida, nvdimm->id);
kfree(nvdimm);
 }
 
@@ -592,7 +592,7 @@ struct nvdimm *__nvdimm_create(struct nvdimm_bus 
*nvdimm_bus,
if (!nvdimm)
return NULL;
 
-   nvdimm->id = ida_simple_get(_ida, 0, 0, GFP_KERNEL);
+   nvdimm->id = ida_alloc(_ida, GFP_KERNEL);
if (nvdimm->id < 0) {
kfree(nvdimm);
return NULL;
diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c
index 07177eadc56e..fa1202e848d9 100644
--- a/drivers/nvdimm/namespace_devs.c
+++ b/drivers/nvdimm/namespace_devs.c
@@ -27,7 +27,7 @@ static void namespace_pmem_release(struct device *dev)
struct nd_region *nd_region = to_nd_region(dev->parent);
 
if (nspm->id >= 0)
-   ida_simple_remove(_region->ns_ida, nspm->id);
+   ida_free(_region->ns_ida, nspm->id);
kfree(nspm->alt_name);
kfree(nspm->uuid);
kfree(nspm);
@@ -1810,7 +1810,7 @@ static struct device *nd_namespace_pmem_create(struct 
nd_region *nd_region)
res->name = dev_name(_region->dev);
res->flags = IORESOURCE_MEM;
 
-   nspm->id = ida_simple_get(_region->

Re: [PATCH] vdpa: Fix an error handling path in eni_vdpa_probe()

2023-12-07 Thread Christophe JAILLET

Le 20/10/2022 à 21:21, Christophe JAILLET a écrit :

After a successful vp_legacy_probe() call, vp_legacy_remove() should be
called in the error handling path, as already done in the remove function.

Add the missing call.

Fixes: e85087beedca ("eni_vdpa: add vDPA driver for Alibaba ENI")
Signed-off-by: Christophe JAILLET 
---
  drivers/vdpa/alibaba/eni_vdpa.c | 6 --
  1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/vdpa/alibaba/eni_vdpa.c b/drivers/vdpa/alibaba/eni_vdpa.c
index 5a09a09cca70..cce3d1837104 100644
--- a/drivers/vdpa/alibaba/eni_vdpa.c
+++ b/drivers/vdpa/alibaba/eni_vdpa.c
@@ -497,7 +497,7 @@ static int eni_vdpa_probe(struct pci_dev *pdev, const 
struct pci_device_id *id)
if (!eni_vdpa->vring) {
ret = -ENOMEM;
ENI_ERR(pdev, "failed to allocate virtqueues\n");
-   goto err;
+   goto err_remove_vp_legacy;
}
  
  	for (i = 0; i < eni_vdpa->queues; i++) {

@@ -509,11 +509,13 @@ static int eni_vdpa_probe(struct pci_dev *pdev, const 
struct pci_device_id *id)
ret = vdpa_register_device(_vdpa->vdpa, eni_vdpa->queues);
if (ret) {
ENI_ERR(pdev, "failed to register to vdpa bus\n");
-   goto err;
+   goto err_remove_vp_legacy;
}
  
  	return 0;
  
+err_remove_vp_legacy:

+   vp_legacy_remove(_vdpa->ldev);
  err:
put_device(_vdpa->vdpa.dev);
return ret;


Polite reminder on a (very) old patch.

CJ



Re: [PATCH v3] seq_buf: Introduce DECLARE_SEQ_BUF and seq_buf_str()

2023-11-01 Thread Christophe JAILLET

Le 27/10/2023 à 17:56, Kees Cook a écrit :

Solve two ergonomic issues with struct seq_buf;

1) Too much boilerplate is required to initialize:

struct seq_buf s;
char buf[32];

seq_buf_init(s, buf, sizeof(buf));

Instead, we can build this directly on the stack. Provide
DECLARE_SEQ_BUF() macro to do this:

DECLARE_SEQ_BUF(s, 32);

2) %NUL termination is fragile and requires 2 steps to get a valid
C String (and is a layering violation exposing the "internals" of
seq_buf):

seq_buf_terminate(s);
do_something(s->buffer);

Instead, we can just return s->buffer directly after terminating it in
the refactored seq_buf_terminate(), now known as seq_buf_str():

do_something(seq_buf_str(s));

Cc: Steven Rostedt 
Cc: "Matthew Wilcox (Oracle)" 
Cc: Christoph Hellwig 
Cc: Justin Stitt 
Cc: Kent Overstreet 
Cc: Petr Mladek 
Cc: Andy Shevchenko 
Cc: Rasmus Villemoes 
Cc: Sergey Senozhatsky 
Cc: Masami Hiramatsu 
Cc: Greg Kroah-Hartman 
Cc: Arnd Bergmann 
Cc: Jonathan Corbet 
Cc: Yun Zhou 
Cc: Jacob Keller 
Cc: Zhen Lei 
Cc: linux-trace-ker...@vger.kernel.org
Link: https://lore.kernel.org/r/20231026194033.it.702-k...@kernel.org
Signed-off-by: Kees Cook 
---
v3
  - fix commit log typos
  - improve code style for DECLARE_SEQ_BUF (shevchenko)
  - const-ify seq_bug_str() return (rostedt)
v2 - https://lore.kernel.org/lkml/20231026194033.it.702-k...@kernel.org
v1 - https://lore.kernel.org/lkml/20231026170722.work.638-k...@kernel.org
---
  include/linux/seq_buf.h | 21 +
  kernel/trace/trace.c| 11 +--
  lib/seq_buf.c   |  4 +---
  3 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/include/linux/seq_buf.h b/include/linux/seq_buf.h
index 8483e4b2d0d2..5fb1f12c33f9 100644
--- a/include/linux/seq_buf.h
+++ b/include/linux/seq_buf.h
@@ -21,9 +21,18 @@ struct seq_buf {
size_t  len;
  };
  
+#define DECLARE_SEQ_BUF(NAME, SIZE)			\

+   char __ ## NAME ## _buffer[SIZE] = "";\
+   struct seq_buf NAME = { \
+   .buffer = &__ ## NAME ## _buffer,   \

 ~~~
Is the & needed here?

CJ


+   .size = SIZE,   \
+   }
+
  static inline void seq_buf_clear(struct seq_buf *s)
  {
s->len = 0;
+   if (s->size)
+   s->buffer[0] = '\0';
  }
  
  static inline void

@@ -69,8 +78,8 @@ static inline unsigned int seq_buf_used(struct seq_buf *s)
  }
  
  /**

- * seq_buf_terminate - Make sure buffer is nul terminated
- * @s: the seq_buf descriptor to terminate.
+ * seq_buf_str - get %NUL-terminated C string from seq_buf
+ * @s: the seq_buf handle
   *
   * This makes sure that the buffer in @s is nul terminated and
   * safe to read as a string.
@@ -81,16 +90,20 @@ static inline unsigned int seq_buf_used(struct seq_buf *s)
   *
   * After this function is called, s->buffer is safe to use
   * in string operations.
+ *
+ * Returns @s->buf after making sure it is terminated.
   */
-static inline void seq_buf_terminate(struct seq_buf *s)
+static inline const char *seq_buf_str(struct seq_buf *s)
  {
if (WARN_ON(s->size == 0))
-   return;
+   return "";
  
  	if (seq_buf_buffer_left(s))

s->buffer[s->len] = 0;
else
s->buffer[s->size - 1] = 0;
+
+   return s->buffer;
  }
  
  /**

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index d629065c2383..2539cfc20a97 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -3828,15 +3828,6 @@ static bool trace_safe_str(struct trace_iterator *iter, 
const char *str,
return false;
  }
  
-static const char *show_buffer(struct trace_seq *s)

-{
-   struct seq_buf *seq = >seq;
-
-   seq_buf_terminate(seq);
-
-   return seq->buffer;
-}
-
  static DEFINE_STATIC_KEY_FALSE(trace_no_verify);
  
  static int test_can_verify_check(const char *fmt, ...)

@@ -3976,7 +3967,7 @@ void trace_check_vprintf(struct trace_iterator *iter, 
const char *fmt,
 */
if (WARN_ONCE(!trace_safe_str(iter, str, star, len),
  "fmt: '%s' current_buffer: '%s'",
- fmt, show_buffer(>seq))) {
+ fmt, seq_buf_str(>seq.seq))) {
int ret;
  
  			/* Try to safely read the string */

diff --git a/lib/seq_buf.c b/lib/seq_buf.c
index b7477aefff53..23518f77ea9c 100644
--- a/lib/seq_buf.c
+++ b/lib/seq_buf.c
@@ -109,9 +109,7 @@ void seq_buf_do_printk(struct seq_buf *s, const char *lvl)
if (s->size == 0 || s->len == 0)
return;
  
-	seq_buf_terminate(s);

-
-   start = s->buffer;
+   start = seq_buf_str(s);
while ((lf = strchr(start, '\n'))) {
int len = lf - start + 1;
  





[PATCH] tracing/histograms: Simplify last_cmd_set()

2023-10-21 Thread Christophe JAILLET
Turn a kzalloc()+strcpy()+strncat() into an equivalent and less verbose
kasprintf().

Signed-off-by: Christophe JAILLET 
---
 kernel/trace/trace_events_hist.c | 11 ++-
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
index d06938ae0717..1abc07fba1b9 100644
--- a/kernel/trace/trace_events_hist.c
+++ b/kernel/trace/trace_events_hist.c
@@ -774,23 +774,16 @@ static void last_cmd_set(struct trace_event_file *file, 
char *str)
 {
const char *system = NULL, *name = NULL;
struct trace_event_call *call;
-   int len;
 
if (!str)
return;
 
-   /* sizeof() contains the nul byte */
-   len = sizeof(HIST_PREFIX) + strlen(str);
kfree(last_cmd);
-   last_cmd = kzalloc(len, GFP_KERNEL);
+
+   last_cmd = kasprintf(GFP_KERNEL, HIST_PREFIX "%s", str);
if (!last_cmd)
return;
 
-   strcpy(last_cmd, HIST_PREFIX);
-   /* Again, sizeof() contains the nul byte */
-   len -= sizeof(HIST_PREFIX);
-   strncat(last_cmd, str, len);
-
if (file) {
call = file->event_call;
system = call->class->system;
-- 
2.34.1




Re: [PATCH v5 2/2] leds: add ktd202x driver

2023-10-01 Thread Christophe JAILLET

Le 01/10/2023 à 18:56, André Apitzsch a écrit :

Hi Christophe,

Am Sonntag, dem 01.10.2023 um 17:15 +0200 schrieb Christophe JAILLET:

Le 01/10/2023 à 15:52, André Apitzsch a écrit :

This commit adds support for Kinetic KTD2026/7 RGB/White LED
driver.

Signed-off-by: André Apitzsch



...


+static int ktd202x_setup_led_rgb(struct ktd202x *chip, struct
device_node *np,
+    struct ktd202x_led *led, struct
led_init_data *init_data)
+{
+   struct led_classdev *cdev;
+   struct device_node *child;
+   struct mc_subled *info;
+   int num_channels;
+   int i = 0;
+   u32 reg;
+   int ret;
+
+   num_channels = of_get_available_child_count(np);
+   if (!num_channels || num_channels > chip->num_leds)
+   return -EINVAL;
+
+   info = devm_kcalloc(chip->dev, num_channels, sizeof(*info),
GFP_KERNEL);
+   if (!info)
+   return -ENOMEM;
+
+   for_each_available_child_of_node(np, child) {
+   u32 mono_color = 0;


Un-needed init.
And, why is it defined here, while reg is defined out-side the loop?


I'll move it out-side the loop (without initialization).




+
+   ret = of_property_read_u32(child, "reg", );
+   if (ret != 0 || reg >= chip->num_leds) {
+   dev_err(chip->dev, "invalid 'reg' of
%pOFn\n", np);


Mossing of_node_put(np);?


It shouldn't be needed here if handled in the calling function, right?


How can the caller do this?

The goal of this of_node_put() is to release a reference taken by the 
for_each_available_child_of_node() loop, in case of early exit.


The caller can't know if np needs to be released or not. An error code 
is returned either if an error occurs within the for_each loop, or if 
devm_led_classdev_multicolor_register_ext() fails.


More over, in your case the caller is ktd202x_add_led().
From there either ktd202x_setup_led_rgb() or ktd202x_setup_led_single() 
is called.


ktd202x_setup_led_single() does not take any reference to np.
But if it fails, of_node_put() would still be called.






+   return -EINVAL;
+   }
+
+   ret = of_property_read_u32(child, "color",
_color);
+   if (ret < 0 && ret != -EINVAL) {
+   dev_err(chip->dev, "failed to parse 'color'
of %pOF\n", np);


Mossing of_node_put(np);?


+   return ret;
+   }
+
+   info[i].color_index = mono_color;
+   info[i].channel = reg;
+   info[i].intensity = KTD202X_MAX_BRIGHTNESS;
+   i++;
+   }
+
+   led->mcdev.subled_info = info;
+   led->mcdev.num_colors = num_channels;
+
+   cdev = >mcdev.led_cdev;
+   cdev->brightness_set_blocking = ktd202x_brightness_mc_set;
+   cdev->blink_set = ktd202x_blink_mc_set;
+
+   return devm_led_classdev_multicolor_register_ext(chip->dev,
>mcdev, init_data);
+}
+
+static int ktd202x_setup_led_single(struct ktd202x *chip, struct
device_node *np,
+   struct ktd202x_led *led, struct
led_init_data *init_data)
+{
+   struct led_classdev *cdev;
+   u32 reg;
+   int ret;
+
+   ret = of_property_read_u32(np, "reg", );
+   if (ret != 0 || reg >= chip->num_leds) {
+   dev_err(chip->dev, "invalid 'reg' of %pOFn\n", np);
+   return -EINVAL;
+   }
+   led->index = reg;
+
+   cdev = >cdev;
+   cdev->brightness_set_blocking =
ktd202x_brightness_single_set;
+   cdev->blink_set = ktd202x_blink_single_set;
+
+   return devm_led_classdev_register_ext(chip->dev, 

cdev, init_data);

+}
+
+static int ktd202x_add_led(struct ktd202x *chip, struct
device_node *np, unsigned int index)
+{
+   struct ktd202x_led *led = >leds[index];
+   struct led_init_data init_data = {};
+   struct led_classdev *cdev;
+   u32 color = 0;

Un-needed init.


+   int ret;
+
+   /* Color property is optional in single color case */
+   ret = of_property_read_u32(np, "color", );
+   if (ret < 0 && ret != -EINVAL) {
+   dev_err(chip->dev, "failed to parse 'color' of
%pOF\n", np);
+   return ret;
+   }
+
+   led->chip = chip;
+   init_data.fwnode = of_fwnode_handle(np);
+
+   if (color == LED_COLOR_ID_RGB) {
+   cdev = >mcdev.led_cdev;
+   ret = ktd202x_setup_led_rgb(chip, np, led,
_data);
+   } else {
+   cdev = >cdev;
+   ret = ktd202x_setup_led_single(chip, np, led,
_data);
+   }
+
+   if (ret) {
+   dev_err(chip->dev, "unable to register %s\n", cdev-

name);

+   of_node_put(np);


This is strange to have it here.
Why not above after "i

Re: [PATCH v5 2/2] leds: add ktd202x driver

2023-10-01 Thread Christophe JAILLET

Le 01/10/2023 à 15:52, André Apitzsch a écrit :

This commit adds support for Kinetic KTD2026/7 RGB/White LED driver.

Signed-off-by: André Apitzsch 


...


+static int ktd202x_setup_led_rgb(struct ktd202x *chip, struct device_node *np,
+struct ktd202x_led *led, struct led_init_data 
*init_data)
+{
+   struct led_classdev *cdev;
+   struct device_node *child;
+   struct mc_subled *info;
+   int num_channels;
+   int i = 0;
+   u32 reg;
+   int ret;
+
+   num_channels = of_get_available_child_count(np);
+   if (!num_channels || num_channels > chip->num_leds)
+   return -EINVAL;
+
+   info = devm_kcalloc(chip->dev, num_channels, sizeof(*info), GFP_KERNEL);
+   if (!info)
+   return -ENOMEM;
+
+   for_each_available_child_of_node(np, child) {
+   u32 mono_color = 0;


Un-needed init.
And, why is it defined here, while reg is defined out-side the loop?


+
+   ret = of_property_read_u32(child, "reg", );
+   if (ret != 0 || reg >= chip->num_leds) {
+   dev_err(chip->dev, "invalid 'reg' of %pOFn\n", np);


Mossing of_node_put(np);?


+   return -EINVAL;
+   }
+
+   ret = of_property_read_u32(child, "color", _color);
+   if (ret < 0 && ret != -EINVAL) {
+   dev_err(chip->dev, "failed to parse 'color' of %pOF\n", 
np);


Mossing of_node_put(np);?


+   return ret;
+   }
+
+   info[i].color_index = mono_color;
+   info[i].channel = reg;
+   info[i].intensity = KTD202X_MAX_BRIGHTNESS;
+   i++;
+   }
+
+   led->mcdev.subled_info = info;
+   led->mcdev.num_colors = num_channels;
+
+   cdev = >mcdev.led_cdev;
+   cdev->brightness_set_blocking = ktd202x_brightness_mc_set;
+   cdev->blink_set = ktd202x_blink_mc_set;
+
+   return devm_led_classdev_multicolor_register_ext(chip->dev, 
>mcdev, init_data);
+}
+
+static int ktd202x_setup_led_single(struct ktd202x *chip, struct device_node 
*np,
+   struct ktd202x_led *led, struct 
led_init_data *init_data)
+{
+   struct led_classdev *cdev;
+   u32 reg;
+   int ret;
+
+   ret = of_property_read_u32(np, "reg", );
+   if (ret != 0 || reg >= chip->num_leds) {
+   dev_err(chip->dev, "invalid 'reg' of %pOFn\n", np);
+   return -EINVAL;
+   }
+   led->index = reg;
+
+   cdev = >cdev;
+   cdev->brightness_set_blocking = ktd202x_brightness_single_set;
+   cdev->blink_set = ktd202x_blink_single_set;
+
+   return devm_led_classdev_register_ext(chip->dev, >cdev, init_data);
+}
+
+static int ktd202x_add_led(struct ktd202x *chip, struct device_node *np, 
unsigned int index)
+{
+   struct ktd202x_led *led = >leds[index];
+   struct led_init_data init_data = {};
+   struct led_classdev *cdev;
+   u32 color = 0;

Un-needed init.


+   int ret;
+
+   /* Color property is optional in single color case */
+   ret = of_property_read_u32(np, "color", );
+   if (ret < 0 && ret != -EINVAL) {
+   dev_err(chip->dev, "failed to parse 'color' of %pOF\n", np);
+   return ret;
+   }
+
+   led->chip = chip;
+   init_data.fwnode = of_fwnode_handle(np);
+
+   if (color == LED_COLOR_ID_RGB) {
+   cdev = >mcdev.led_cdev;
+   ret = ktd202x_setup_led_rgb(chip, np, led, _data);
+   } else {
+   cdev = >cdev;
+   ret = ktd202x_setup_led_single(chip, np, led, _data);
+   }
+
+   if (ret) {
+   dev_err(chip->dev, "unable to register %s\n", cdev->name);
+   of_node_put(np);


This is strange to have it here.
Why not above after "if (ret < 0 && ret != -EINVAL) {"?

It would look much more natural to have it a few lines below, ... [1]


+   return ret;
+   }
+
+   cdev->max_brightness = KTD202X_MAX_BRIGHTNESS;
+
+   return 0;
+}
+
+static int ktd202x_probe_dt(struct ktd202x *chip)
+{
+   struct device_node *np = dev_of_node(chip->dev), *child;
+   unsigned int i;
+   int count, ret;
+
+   chip->num_leds = (int)(unsigned 
long)of_device_get_match_data(chip->dev);
+
+   count = of_get_available_child_count(np);
+   if (!count || count > chip->num_leds)
+   return -EINVAL;
+
+   regmap_write(chip->regmap, KTD202X_REG_RESET_CONTROL, 
KTD202X_RSTR_RESET);
+
+   /* Allow the device to execute the complete reset */
+   usleep_range(200, 300);
+
+   i = 0;
+   for_each_available_child_of_node(np, child) {
+   ret = ktd202x_add_led(chip, child, i);
+   if (ret)


[1] ... here.

Otherwise, it is likely that, thanks to a static checker, an additionnal 
of_node_put() will be added on early exit of the loop.


CJ


+   

[PATCH v3] nvdimm: Use kstrtobool() instead of strtobool()

2023-07-12 Thread Christophe JAILLET
strtobool() is the same as kstrtobool().
However, the latter is more used within the kernel.

In order to remove strtobool() and slightly simplify kstrtox.h, switch to
the other function name.

While at it, include the corresponding header file ()

Reviewed-by: Vishal Verma 
Signed-off-by: Christophe JAILLET 
---
This patch was already sent as a part of a serie ([1]) that axed all usages
of strtobool().
Most of the patches have been merged in -next.

I synch'ed with latest -next and re-send the remaining ones as individual
patches.

Even if R-b and told that it was applied for v6.3, it is still not in -next.
This is the very last patch of the initial serie that remains un-applied.

After it, strtobool() can be removed from linux/kstrtox.h.

Changes in v3:
  - synch with latest -next.
  - Adding R-b tag
  - Adding in cc: a...@linux-foundation.org

Changes in v2:
  - synch with latest -next.
  - 
https://lore.kernel.org/all/7565f107952e31fad2bc825b8c533df70c498537.1673686195.git.christophe.jail...@wanadoo.fr/

[1]: 
https://lore.kernel.org/all/cover.1667336095.git.christophe.jail...@wanadoo.fr/
---
 drivers/nvdimm/namespace_devs.c | 3 ++-
 drivers/nvdimm/pmem.c   | 3 ++-
 drivers/nvdimm/region_devs.c| 5 +++--
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c
index c60ec0b373c5..07177eadc56e 100644
--- a/drivers/nvdimm/namespace_devs.c
+++ b/drivers/nvdimm/namespace_devs.c
@@ -2,6 +2,7 @@
 /*
  * Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
  */
+#include 
 #include 
 #include 
 #include 
@@ -1338,7 +1339,7 @@ static ssize_t force_raw_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t len)
 {
bool force_raw;
-   int rc = strtobool(buf, _raw);
+   int rc = kstrtobool(buf, _raw);
 
if (rc)
return rc;
diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
index 80ded5a2838a..f2a336c6d8c6 100644
--- a/drivers/nvdimm/pmem.c
+++ b/drivers/nvdimm/pmem.c
@@ -17,6 +17,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -385,7 +386,7 @@ static ssize_t write_cache_store(struct device *dev,
bool write_cache;
int rc;
 
-   rc = strtobool(buf, _cache);
+   rc = kstrtobool(buf, _cache);
if (rc)
return rc;
dax_write_cache(pmem->dax_dev, write_cache);
diff --git a/drivers/nvdimm/region_devs.c b/drivers/nvdimm/region_devs.c
index 83dbf398ea84..f5872de7ea5a 100644
--- a/drivers/nvdimm/region_devs.c
+++ b/drivers/nvdimm/region_devs.c
@@ -5,6 +5,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -275,7 +276,7 @@ static ssize_t deep_flush_store(struct device *dev, struct 
device_attribute *att
const char *buf, size_t len)
 {
bool flush;
-   int rc = strtobool(buf, );
+   int rc = kstrtobool(buf, );
struct nd_region *nd_region = to_nd_region(dev);
 
if (rc)
@@ -530,7 +531,7 @@ static ssize_t read_only_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t len)
 {
bool ro;
-   int rc = strtobool(buf, );
+   int rc = kstrtobool(buf, );
struct nd_region *nd_region = to_nd_region(dev);
 
if (rc)
-- 
2.34.1




Re: RE: [PATCH v2] nvdimm: Use kstrtobool() instead of strtobool()

2023-05-04 Thread Christophe JAILLET

Le 25/01/2023 à 20:11, Dan Williams a écrit :

Christophe JAILLET wrote:

strtobool() is the same as kstrtobool().
However, the latter is more used within the kernel.

In order to remove strtobool() and slightly simplify kstrtox.h, switch to
the other function name.

While at it, include the corresponding header file ()

Signed-off-by: Christophe JAILLET 
---
This patch was already sent as a part of a serie ([1]) that axed all usages
of strtobool().
Most of the patches have been merged in -next.

I synch'ed with latest -next and re-send the remaining ones as individual
patches.

Changes in v2:
   - synch with latest -next.


Looks good, applied for v6.3.



Hi,

polite reminder.

If I'm right, only 2 places still use strtobool().
This one and net/bluetooth/hci_debugfs.c.

I'll also try to push the other one and get rid of strtobool().

CJ



[PATCH v2] nvdimm: Use kstrtobool() instead of strtobool()

2023-01-14 Thread Christophe JAILLET
strtobool() is the same as kstrtobool().
However, the latter is more used within the kernel.

In order to remove strtobool() and slightly simplify kstrtox.h, switch to
the other function name.

While at it, include the corresponding header file ()

Signed-off-by: Christophe JAILLET 
---
This patch was already sent as a part of a serie ([1]) that axed all usages
of strtobool().
Most of the patches have been merged in -next.

I synch'ed with latest -next and re-send the remaining ones as individual
patches.

Changes in v2:
  - synch with latest -next.

[1]: 
https://lore.kernel.org/all/cover.1667336095.git.christophe.jail...@wanadoo.fr/
---
 drivers/nvdimm/namespace_devs.c | 3 ++-
 drivers/nvdimm/pmem.c   | 3 ++-
 drivers/nvdimm/region_devs.c| 5 +++--
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c
index c60ec0b373c5..07177eadc56e 100644
--- a/drivers/nvdimm/namespace_devs.c
+++ b/drivers/nvdimm/namespace_devs.c
@@ -2,6 +2,7 @@
 /*
  * Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
  */
+#include 
 #include 
 #include 
 #include 
@@ -1338,7 +1339,7 @@ static ssize_t force_raw_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t len)
 {
bool force_raw;
-   int rc = strtobool(buf, _raw);
+   int rc = kstrtobool(buf, _raw);
 
if (rc)
return rc;
diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
index 80ded5a2838a..f2a336c6d8c6 100644
--- a/drivers/nvdimm/pmem.c
+++ b/drivers/nvdimm/pmem.c
@@ -17,6 +17,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -408,7 +409,7 @@ static ssize_t write_cache_store(struct device *dev,
bool write_cache;
int rc;
 
-   rc = strtobool(buf, _cache);
+   rc = kstrtobool(buf, _cache);
if (rc)
return rc;
dax_write_cache(pmem->dax_dev, write_cache);
diff --git a/drivers/nvdimm/region_devs.c b/drivers/nvdimm/region_devs.c
index 83dbf398ea84..f5872de7ea5a 100644
--- a/drivers/nvdimm/region_devs.c
+++ b/drivers/nvdimm/region_devs.c
@@ -5,6 +5,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -275,7 +276,7 @@ static ssize_t deep_flush_store(struct device *dev, struct 
device_attribute *att
const char *buf, size_t len)
 {
bool flush;
-   int rc = strtobool(buf, );
+   int rc = kstrtobool(buf, );
struct nd_region *nd_region = to_nd_region(dev);
 
if (rc)
@@ -530,7 +531,7 @@ static ssize_t read_only_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t len)
 {
bool ro;
-   int rc = strtobool(buf, );
+   int rc = kstrtobool(buf, );
struct nd_region *nd_region = to_nd_region(dev);
 
if (rc)
-- 
2.34.1




Re: [PATCH] libnvdimm: Add check for nd_dax_alloc

2022-11-22 Thread Christophe JAILLET

Le 22/11/2022 à 03:33, Jiasheng Jiang a écrit :

As the nd_dax_alloc may return NULL pointer,
it should be better to add check for the return
value, as same as the one in nd_dax_create().

Fixes: c5ed9268643c ("libnvdimm, dax: autodetect support")
Signed-off-by: Jiasheng Jiang 
---
  drivers/nvdimm/dax_devs.c | 2 ++
  1 file changed, 2 insertions(+)

diff --git a/drivers/nvdimm/dax_devs.c b/drivers/nvdimm/dax_devs.c
index 7f4a9d28b670..9efe62b95dd8 100644
--- a/drivers/nvdimm/dax_devs.c
+++ b/drivers/nvdimm/dax_devs.c
@@ -106,6 +106,8 @@ int nd_dax_probe(struct device *dev, struct 
nd_namespace_common *ndns)
  
  	nvdimm_bus_lock(>dev);

nd_dax = nd_dax_alloc(nd_region);
+   if (!nd_dax)
+   return -ENOMEM;
nd_pfn = _dax->nd_pfn;
dax_dev = nd_pfn_devinit(nd_pfn, ndns);
nvdimm_bus_unlock(>dev);


Hi,

Based on 6.1-rc6 ([1]), the error handling is already in place just 
after the nvdimm_bus_unlock() call.


CJ

[1]: 
https://elixir.bootlin.com/linux/v6.1-rc6/source/drivers/nvdimm/dax_devs.c#L112




[PATCH 05/30] nvdimm: Use kstrtobool() instead of strtobool()

2022-11-01 Thread Christophe JAILLET
strtobool() is the same as kstrtobool().
However, the latter is more used within the kernel.

In order to remove strtobool() and slightly simplify kstrtox.h, switch to
the other function name.

While at it, include the corresponding header file ()

Signed-off-by: Christophe JAILLET 
---
This patch is part of a serie that axes all usages of strtobool().
Each patch can be applied independently from the other ones.

The last patch of the serie removes the definition of strtobool().

You may not be in copy of the cover letter. So, if needed, it is available
at [1].

[1]: 
https://lore.kernel.org/all/cover.1667336095.git.christophe.jail...@wanadoo.fr/
---
 drivers/nvdimm/namespace_devs.c | 3 ++-
 drivers/nvdimm/pmem.c   | 3 ++-
 drivers/nvdimm/region_devs.c| 5 +++--
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c
index c60ec0b373c5..07177eadc56e 100644
--- a/drivers/nvdimm/namespace_devs.c
+++ b/drivers/nvdimm/namespace_devs.c
@@ -2,6 +2,7 @@
 /*
  * Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
  */
+#include 
 #include 
 #include 
 #include 
@@ -1338,7 +1339,7 @@ static ssize_t force_raw_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t len)
 {
bool force_raw;
-   int rc = strtobool(buf, _raw);
+   int rc = kstrtobool(buf, _raw);
 
if (rc)
return rc;
diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
index 3c63dc2cdc81..46475d146f64 100644
--- a/drivers/nvdimm/pmem.c
+++ b/drivers/nvdimm/pmem.c
@@ -17,6 +17,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -408,7 +409,7 @@ static ssize_t write_cache_store(struct device *dev,
bool write_cache;
int rc;
 
-   rc = strtobool(buf, _cache);
+   rc = kstrtobool(buf, _cache);
if (rc)
return rc;
dax_write_cache(pmem->dax_dev, write_cache);
diff --git a/drivers/nvdimm/region_devs.c b/drivers/nvdimm/region_devs.c
index e0875d369762..76e1ae6f830a 100644
--- a/drivers/nvdimm/region_devs.c
+++ b/drivers/nvdimm/region_devs.c
@@ -5,6 +5,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -229,7 +230,7 @@ static ssize_t deep_flush_store(struct device *dev, struct 
device_attribute *att
const char *buf, size_t len)
 {
bool flush;
-   int rc = strtobool(buf, );
+   int rc = kstrtobool(buf, );
struct nd_region *nd_region = to_nd_region(dev);
 
if (rc)
@@ -484,7 +485,7 @@ static ssize_t read_only_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t len)
 {
bool ro;
-   int rc = strtobool(buf, );
+   int rc = kstrtobool(buf, );
struct nd_region *nd_region = to_nd_region(dev);
 
if (rc)
-- 
2.34.1




Re: [PATCH] nvdimm: Avoid wasting some memory.

2022-09-04 Thread Christophe JAILLET

Le 04/09/2022 à 16:38, Dan Williams a écrit :

Christophe JAILLET wrote:

sizeof(struct btt_sb) is 4096.

When using devm_kzalloc(), there is a small memory overhead and, on most
systems, this leads to 40 bytes of extra memory allocation.
So 5036 bytes are expected to be allocated.

The memory allocator works with fixed size hunks of memory. In this case,
it will require 8192 bytes of memory because more than 4096 bytes are
required.

In order to avoid wasting 4ko of memory, just use kzalloc() and add a
devm action to free it when needed.

Signed-off-by: Christophe JAILLET 
---
  drivers/nvdimm/btt_devs.c | 17 -
  1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/drivers/nvdimm/btt_devs.c b/drivers/nvdimm/btt_devs.c
index fabbb31f2c35..7b79fb0b0338 100644
--- a/drivers/nvdimm/btt_devs.c
+++ b/drivers/nvdimm/btt_devs.c
@@ -332,6 +332,11 @@ static int __nd_btt_probe(struct nd_btt *nd_btt,
return 0;
  }
  
+void nd_btt_free(void *data)

+{
+   kfree(data);
+}
+
  int nd_btt_probe(struct device *dev, struct nd_namespace_common *ndns)
  {
int rc;
@@ -356,7 +361,17 @@ int nd_btt_probe(struct device *dev, struct 
nd_namespace_common *ndns)
nvdimm_bus_unlock(>dev);
if (!btt_dev)
return -ENOMEM;
-   btt_sb = devm_kzalloc(dev, sizeof(*btt_sb), GFP_KERNEL);
+
+   /*
+* 'struct btt_sb' is 4096. Using devm_kzalloc() would waste 4 ko of
+* memory because, because of a small memory over head, 8192 bytes
+* would be allocated. So keep this kzalloc()+devm_add_action_or_reset()
+*/
+   btt_sb = kzalloc(sizeof(*btt_sb), GFP_KERNEL);
+   rc = devm_add_action_or_reset(dev, nd_btt_free, btt_sb);
+   if (rc)
+   return rc;


Thanks for the analysis and the patch. However, shouldn't this be
something that is addressed internal to devm_kzalloc() rather than
open-coded at every potential call site?



Hi,
it would be fine, but it is not that easy.
(read: any idea to implement it is welcomed :) )

I made a try a few weeks ago. See [1].
It triggered obvious issues spotted by 0day robot .

In fact, "making clever things" in devm_kmalloc() prevent using 
devm_kfree() (or would require some over-engineering).



Greg also argued that it is likely that devm_  allocated memory does not 
happen that much.



I posted today a few similar patches as the one above in different 
subsystem to get some feed-backs whether open-coding it in "interesting" 
places make sense or not.


Spotted such places is not that hard with a home made additional check 
in smatch.


CJ

[1]: 
https://lore.kernel.org/all/92ec2f78e8d38f68da95d9250cf3f86b2fbe78ad.1658570017.git.christophe.jail...@wanadoo.fr/




[PATCH] nvdimm: Avoid wasting some memory.

2022-09-04 Thread Christophe JAILLET
sizeof(struct btt_sb) is 4096.

When using devm_kzalloc(), there is a small memory overhead and, on most
systems, this leads to 40 bytes of extra memory allocation.
So 5036 bytes are expected to be allocated.

The memory allocator works with fixed size hunks of memory. In this case,
it will require 8192 bytes of memory because more than 4096 bytes are
required.

In order to avoid wasting 4ko of memory, just use kzalloc() and add a
devm action to free it when needed.

Signed-off-by: Christophe JAILLET 
---
 drivers/nvdimm/btt_devs.c | 17 -
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/drivers/nvdimm/btt_devs.c b/drivers/nvdimm/btt_devs.c
index fabbb31f2c35..7b79fb0b0338 100644
--- a/drivers/nvdimm/btt_devs.c
+++ b/drivers/nvdimm/btt_devs.c
@@ -332,6 +332,11 @@ static int __nd_btt_probe(struct nd_btt *nd_btt,
return 0;
 }
 
+void nd_btt_free(void *data)
+{
+   kfree(data);
+}
+
 int nd_btt_probe(struct device *dev, struct nd_namespace_common *ndns)
 {
int rc;
@@ -356,7 +361,17 @@ int nd_btt_probe(struct device *dev, struct 
nd_namespace_common *ndns)
nvdimm_bus_unlock(>dev);
if (!btt_dev)
return -ENOMEM;
-   btt_sb = devm_kzalloc(dev, sizeof(*btt_sb), GFP_KERNEL);
+
+   /*
+* 'struct btt_sb' is 4096. Using devm_kzalloc() would waste 4 ko of
+* memory because, because of a small memory over head, 8192 bytes
+* would be allocated. So keep this kzalloc()+devm_add_action_or_reset()
+*/
+   btt_sb = kzalloc(sizeof(*btt_sb), GFP_KERNEL);
+   rc = devm_add_action_or_reset(dev, nd_btt_free, btt_sb);
+   if (rc)
+   return rc;
+
rc = __nd_btt_probe(to_nd_btt(btt_dev), ndns, btt_sb);
dev_dbg(dev, "btt: %s\n", rc == 0 ? dev_name(btt_dev) : "");
if (rc < 0) {
-- 
2.34.1




Re: [PATCH] nvdimm/pmem: Fix an error handling path in 'pmem_attach_disk()'

2021-11-07 Thread Marion &amp; Christophe JAILLET




Le 07/11/2021 à 18:25, Marion & Christophe JAILLET a écrit :



Le 07/11/2021 à 18:20, Christophe JAILLET a écrit :

Le 07/11/2021 à 18:11, Ira Weiny a écrit :

On Sat, Nov 06, 2021 at 06:27:11PM +0100, Christophe JAILLET wrote:
If 'devm_init_badblocks()' fails, a previous 'blk_alloc_disk()' call 
must

be undone.


I think this is a problem...



Signed-off-by: Christophe JAILLET 
---
This patch is speculative. Several fixes on error handling paths 
have been

done recently, but this one has been left as-is. There was maybe a good
reason that I have missed for that. So review with care!

I've not been able to identify a Fixes tag that please me :(
---
  drivers/nvdimm/pmem.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
index fe7ece1534e1..c37a1e6750b3 100644
--- a/drivers/nvdimm/pmem.c
+++ b/drivers/nvdimm/pmem.c
@@ -490,8 +490,9 @@ static int pmem_attach_disk(struct device *dev,
  nvdimm_namespace_disk_name(ndns, disk->disk_name);
  set_capacity(disk, (pmem->size - pmem->pfn_pad - 
pmem->data_offset)

  / 512);
-    if (devm_init_badblocks(dev, >bb))
-    return -ENOMEM;
+    rc = devm_init_badblocks(dev, >bb);
+    if (rc)
+    goto out;


But I don't see this 'out' label in the function currently?  Was that 
part of

your patch missing?


Hi,
the patch is based on the latest linux-next.
See [1]. The 'out' label exists there and is already used.

In fact, I run an own-made coccinelle script which tries to spot 
mix-up between return and goto.
In this case, we have a 'return -ENOMEM' after a 'goto out' which 
looks spurious. Hence, my patch.


[1]:https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/drivers/nvdimm/pmem.c#n512 



Lol, the #n512 above is in fact another place that should be updated as 
well. I missed it and only fixed #n494!


In fact, no, line 512 should be left as-is. The clean-up wilol be made 
by 'pmem_release_disk()'.


The patch attached at the very first mail of this thread looks good to me.

CJ



CJ



CJ



Ira


  nvdimm_badblocks_populate(nd_region, >bb, _range);
  disk->bb = >bb;
--
2.30.2












Re: [PATCH] nvdimm/pmem: Fix an error handling path in 'pmem_attach_disk()'

2021-11-07 Thread Marion &amp; Christophe JAILLET




Le 07/11/2021 à 18:20, Christophe JAILLET a écrit :

Le 07/11/2021 à 18:11, Ira Weiny a écrit :

On Sat, Nov 06, 2021 at 06:27:11PM +0100, Christophe JAILLET wrote:
If 'devm_init_badblocks()' fails, a previous 'blk_alloc_disk()' call 
must

be undone.


I think this is a problem...



Signed-off-by: Christophe JAILLET 
---
This patch is speculative. Several fixes on error handling paths have 
been

done recently, but this one has been left as-is. There was maybe a good
reason that I have missed for that. So review with care!

I've not been able to identify a Fixes tag that please me :(
---
  drivers/nvdimm/pmem.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
index fe7ece1534e1..c37a1e6750b3 100644
--- a/drivers/nvdimm/pmem.c
+++ b/drivers/nvdimm/pmem.c
@@ -490,8 +490,9 @@ static int pmem_attach_disk(struct device *dev,
  nvdimm_namespace_disk_name(ndns, disk->disk_name);
  set_capacity(disk, (pmem->size - pmem->pfn_pad - 
pmem->data_offset)

  / 512);
-    if (devm_init_badblocks(dev, >bb))
-    return -ENOMEM;
+    rc = devm_init_badblocks(dev, >bb);
+    if (rc)
+    goto out;


But I don't see this 'out' label in the function currently?  Was that 
part of

your patch missing?


Hi,
the patch is based on the latest linux-next.
See [1]. The 'out' label exists there and is already used.

In fact, I run an own-made coccinelle script which tries to spot mix-up 
between return and goto.
In this case, we have a 'return -ENOMEM' after a 'goto out' which looks 
spurious. Hence, my patch.


[1]:https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/drivers/nvdimm/pmem.c#n512 



Lol, the #n512 above is in fact another place that should be updated as 
well. I missed it and only fixed #n494!


CJ



CJ



Ira


  nvdimm_badblocks_populate(nd_region, >bb, _range);
  disk->bb = >bb;
--
2.30.2










Re: [PATCH] nvdimm/pmem: Fix an error handling path in 'pmem_attach_disk()'

2021-11-07 Thread Christophe JAILLET

Le 07/11/2021 à 18:11, Ira Weiny a écrit :

On Sat, Nov 06, 2021 at 06:27:11PM +0100, Christophe JAILLET wrote:

If 'devm_init_badblocks()' fails, a previous 'blk_alloc_disk()' call must
be undone.


I think this is a problem...



Signed-off-by: Christophe JAILLET 
---
This patch is speculative. Several fixes on error handling paths have been
done recently, but this one has been left as-is. There was maybe a good
reason that I have missed for that. So review with care!

I've not been able to identify a Fixes tag that please me :(
---
  drivers/nvdimm/pmem.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
index fe7ece1534e1..c37a1e6750b3 100644
--- a/drivers/nvdimm/pmem.c
+++ b/drivers/nvdimm/pmem.c
@@ -490,8 +490,9 @@ static int pmem_attach_disk(struct device *dev,
nvdimm_namespace_disk_name(ndns, disk->disk_name);
set_capacity(disk, (pmem->size - pmem->pfn_pad - pmem->data_offset)
/ 512);
-   if (devm_init_badblocks(dev, >bb))
-   return -ENOMEM;
+   rc = devm_init_badblocks(dev, >bb);
+   if (rc)
+   goto out;


But I don't see this 'out' label in the function currently?  Was that part of
your patch missing?


Hi,
the patch is based on the latest linux-next.
See [1]. The 'out' label exists there and is already used.

In fact, I run an own-made coccinelle script which tries to spot mix-up 
between return and goto.
In this case, we have a 'return -ENOMEM' after a 'goto out' which looks 
spurious. Hence, my patch.


[1]:https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/drivers/nvdimm/pmem.c#n512

CJ



Ira


nvdimm_badblocks_populate(nd_region, >bb, _range);
disk->bb = >bb;
  
--

2.30.2








[PATCH] nvdimm/pmem: Fix an error handling path in 'pmem_attach_disk()'

2021-11-06 Thread Christophe JAILLET
If 'devm_init_badblocks()' fails, a previous 'blk_alloc_disk()' call must
be undone.

Signed-off-by: Christophe JAILLET 
---
This patch is speculative. Several fixes on error handling paths have been
done recently, but this one has been left as-is. There was maybe a good
reason that I have missed for that. So review with care!

I've not been able to identify a Fixes tag that please me :(
---
 drivers/nvdimm/pmem.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
index fe7ece1534e1..c37a1e6750b3 100644
--- a/drivers/nvdimm/pmem.c
+++ b/drivers/nvdimm/pmem.c
@@ -490,8 +490,9 @@ static int pmem_attach_disk(struct device *dev,
nvdimm_namespace_disk_name(ndns, disk->disk_name);
set_capacity(disk, (pmem->size - pmem->pfn_pad - pmem->data_offset)
/ 512);
-   if (devm_init_badblocks(dev, >bb))
-   return -ENOMEM;
+   rc = devm_init_badblocks(dev, >bb);
+   if (rc)
+   goto out;
nvdimm_badblocks_populate(nd_region, >bb, _range);
disk->bb = >bb;
 
-- 
2.30.2




[PATCH] nvmem: core: add a missing of_node_put

2021-04-20 Thread Christophe JAILLET
'for_each_child_of_node' performs an of_node_get on each iteration, so a
return from the middle of the loop requires an of_node_put.

Fixes: e888d445ac33 ("nvmem: resolve cells from DT at registration time")
Signed-off-by: Christophe JAILLET 
---
 drivers/nvmem/core.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index bca671ff4e54..4375e52ba6c2 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -686,12 +686,15 @@ static int nvmem_add_cells_from_of(struct nvmem_device 
*nvmem)
continue;
if (len < 2 * sizeof(u32)) {
dev_err(dev, "nvmem: invalid reg on %pOF\n", child);
+   of_node_put(child);
return -EINVAL;
}
 
cell = kzalloc(sizeof(*cell), GFP_KERNEL);
-   if (!cell)
+   if (!cell) {
+   of_node_put(child);
return -ENOMEM;
+   }
 
cell->nvmem = nvmem;
cell->np = of_node_get(child);
@@ -717,6 +720,7 @@ static int nvmem_add_cells_from_of(struct nvmem_device 
*nvmem)
kfree_const(cell->name);
of_node_put(cell->np);
kfree(cell);
+   of_node_put(child);
return -EINVAL;
}
 
-- 
2.27.0



[PATCH] spi: fsi: add a missing of_node_put

2021-04-20 Thread Christophe JAILLET
'for_each_available_child_of_node' performs an of_node_get on each
iteration, so a return from the middle of the loop requires an of_node_put.

Fixes: bbb6b2f9865b ("spi: Add FSI-attached SPI controller driver")
Signed-off-by: Christophe JAILLET 
---
 drivers/spi/spi-fsi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi-fsi.c b/drivers/spi/spi-fsi.c
index de359718e816..87f8829c3995 100644
--- a/drivers/spi/spi-fsi.c
+++ b/drivers/spi/spi-fsi.c
@@ -566,8 +566,10 @@ static int fsi_spi_probe(struct device *dev)
continue;
 
ctlr = spi_alloc_master(dev, sizeof(*ctx));
-   if (!ctlr)
+   if (!ctlr) {
+   of_node_put(np);
break;
+   }
 
ctlr->dev.of_node = np;
ctlr->num_chipselect = of_get_available_child_count(np) ?: 1;
-- 
2.27.0



[PATCH] regulator: Avoid a double 'of_node_get' in 'regulator_of_get_init_node()'

2021-04-20 Thread Christophe JAILLET
'for_each_available_child_of_node()' already performs an 'of_node_get()'
on child, so there is no need to perform another one before returning.
Otherwise, a double 'get' is performed and a resource may never be
released.

Fixes: 925c85e21ed8 ("regulator: Factor out location of init data OF node")
Signed-off-by: Christophe JAILLET 
---
Untested, speculative patch
---
 drivers/regulator/of_regulator.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index 564f928eb1db..49f6c05fee34 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -422,7 +422,11 @@ device_node *regulator_of_get_init_node(struct device *dev,
 
if (!strcmp(desc->of_match, name)) {
of_node_put(search);
-   return of_node_get(child);
+   /*
+* 'of_node_get(child)' is already performed by the
+* for_each loop.
+*/
+   return child;
}
}
 
-- 
2.27.0



[PATCH] scsi: bfa: Remove some unused variables

2021-04-20 Thread Christophe JAILLET
'lp' is unused. It is just declared and memset'ed.
It can be removed.

Signed-off-by: Christophe JAILLET 
---
 drivers/scsi/bfa/bfa_svc.c | 6 --
 1 file changed, 6 deletions(-)

diff --git a/drivers/scsi/bfa/bfa_svc.c b/drivers/scsi/bfa/bfa_svc.c
index 11c0c3e6f014..5387883d6604 100644
--- a/drivers/scsi/bfa/bfa_svc.c
+++ b/drivers/scsi/bfa/bfa_svc.c
@@ -369,13 +369,10 @@ bfa_plog_fchdr(struct bfa_plog_s *plog, enum bfa_plog_mid 
mid,
enum bfa_plog_eid event,
u16 misc, struct fchs_s *fchdr)
 {
-   struct bfa_plog_rec_s  lp;
u32 *tmp_int = (u32 *) fchdr;
u32 ints[BFA_PL_INT_LOG_SZ];
 
if (plog->plog_enabled) {
-   memset(, 0, sizeof(struct bfa_plog_rec_s));
-
ints[0] = tmp_int[0];
ints[1] = tmp_int[1];
ints[2] = tmp_int[4];
@@ -389,13 +386,10 @@ bfa_plog_fchdr_and_pl(struct bfa_plog_s *plog, enum 
bfa_plog_mid mid,
  enum bfa_plog_eid event, u16 misc, struct fchs_s *fchdr,
  u32 pld_w0)
 {
-   struct bfa_plog_rec_s  lp;
u32 *tmp_int = (u32 *) fchdr;
u32 ints[BFA_PL_INT_LOG_SZ];
 
if (plog->plog_enabled) {
-   memset(, 0, sizeof(struct bfa_plog_rec_s));
-
ints[0] = tmp_int[0];
ints[1] = tmp_int[1];
ints[2] = tmp_int[4];
-- 
2.27.0



[PATCH] RDMA/mlx4: remove an unused variable

2021-04-20 Thread Christophe JAILLET
'in6' is unused. It is just declared and filled-in.
It can be removed.

This is a left over from commit 5ea8bbfc4929
("mlx4: Implement IP based gids support for RoCE/SRIOV")

Signed-off-by: Christophe JAILLET 
---
 drivers/infiniband/hw/mlx4/qp.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/infiniband/hw/mlx4/qp.c b/drivers/infiniband/hw/mlx4/qp.c
index 651785bd57f2..92ddbcc00eb2 100644
--- a/drivers/infiniband/hw/mlx4/qp.c
+++ b/drivers/infiniband/hw/mlx4/qp.c
@@ -3135,7 +3135,6 @@ static int build_mlx_header(struct mlx4_ib_qp *qp, const 
struct ib_ud_wr *wr,
}
 
if (is_eth) {
-   struct in6_addr in6;
u16 ether_type;
u16 pcp = (be32_to_cpu(ah->av.ib.sl_tclass_flowlabel) >> 29) << 
13;
 
@@ -3148,8 +3147,6 @@ static int build_mlx_header(struct mlx4_ib_qp *qp, const 
struct ib_ud_wr *wr,
memcpy(sqp->ud_header.eth.dmac_h, ah->av.eth.mac, 6);
memcpy(>srcrb_flags16[0], ah->av.eth.mac, 2);
memcpy(>imm, ah->av.eth.mac + 2, 4);
-   memcpy(, sgid.raw, sizeof(in6));
-
 
if (!memcmp(sqp->ud_header.eth.smac_h, 
sqp->ud_header.eth.dmac_h, 6))
mlx->flags |= cpu_to_be32(MLX4_WQE_CTRL_FORCE_LOOPBACK);
-- 
2.27.0



[PATCH resend] xhci: Do not use GFP_KERNEL in (potentially) atomic context

2021-04-20 Thread Christophe JAILLET
'xhci_urb_enqueue()' is passed a 'mem_flags' argument, because "URBs may be
submitted in interrupt context" (see comment related to 'usb_submit_urb()'
in 'drivers/usb/core/urb.c')

So this flag should be used in all the calling chain.
Up to now, 'xhci_check_maxpacket()' which is only called from
'xhci_urb_enqueue()', uses GFP_KERNEL.

Be safe and pass the mem_flags to this function as well.

Fixes: ddba5cd0aeff ("xhci: Use command structures when queuing commands on the 
command ring")
Signed-off-by: Christophe JAILLET 
---
I'm not 100% sure of the Fixes tag. The commit is the only that introduced
this GFP_KERNEL, but I've not checked what was the behavior before that.

If the patch is correct, I guess that a cc stable should be welcome.

This patch was proposed on 14/08/20. It has been rebased on latest -next tree.
---
 drivers/usb/host/xhci.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index ca9385d22f68..27283654ca08 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -1514,7 +1514,7 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci,
  * we need to issue an evaluate context command and wait on it.
  */
 static int xhci_check_maxpacket(struct xhci_hcd *xhci, unsigned int slot_id,
-   unsigned int ep_index, struct urb *urb)
+   unsigned int ep_index, struct urb *urb, gfp_t mem_flags)
 {
struct xhci_container_ctx *out_ctx;
struct xhci_input_control_ctx *ctrl_ctx;
@@ -1545,7 +1545,7 @@ static int xhci_check_maxpacket(struct xhci_hcd *xhci, 
unsigned int slot_id,
 * changes max packet sizes.
 */
 
-   command = xhci_alloc_command(xhci, true, GFP_KERNEL);
+   command = xhci_alloc_command(xhci, true, mem_flags);
if (!command)
return -ENOMEM;
 
@@ -1639,7 +1639,7 @@ static int xhci_urb_enqueue(struct usb_hcd *hcd, struct 
urb *urb, gfp_t mem_flag
 */
if (urb->dev->speed == USB_SPEED_FULL) {
ret = xhci_check_maxpacket(xhci, slot_id,
-   ep_index, urb);
+   ep_index, urb, mem_flags);
if (ret < 0) {
xhci_urb_free_priv(urb_priv);
urb->hcpriv = NULL;
-- 
2.27.0



[PATCH] staging: octeon: Use 'for_each_child_of_node'

2021-04-20 Thread Christophe JAILLET
Use 'for_each_child_of_node' instead of hand writing it.
This saves a few line of code.

Signed-off-by: Christophe JAILLET 
---
 drivers/staging/octeon/ethernet.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/octeon/ethernet.c 
b/drivers/staging/octeon/ethernet.c
index da7c2cd8ebb8..dcbba9621b21 100644
--- a/drivers/staging/octeon/ethernet.c
+++ b/drivers/staging/octeon/ethernet.c
@@ -610,14 +610,11 @@ static const struct net_device_ops cvm_oct_pow_netdev_ops 
= {
 static struct device_node *cvm_oct_of_get_child
(const struct device_node *parent, int reg_val)
 {
-   struct device_node *node = NULL;
-   int size;
+   struct device_node *node;
const __be32 *addr;
+   int size;
 
-   for (;;) {
-   node = of_get_next_child(parent, node);
-   if (!node)
-   break;
+   for_each_child_of_node(parent, node) {
addr = of_get_property(node, "reg", );
if (addr && (be32_to_cpu(*addr) == reg_val))
break;
-- 
2.27.0



[PATCH] brcmfmac: Avoid GFP_ATOMIC when GFP_KERNEL is enough

2021-04-19 Thread Christophe JAILLET
A workqueue is not atomic, so constraints can be relaxed here.
GFP_KERNEL can be used instead of GFP_ATOMIC.

Signed-off-by: Christophe JAILLET 
---
 drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c 
b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
index ea78fe527c5d..838b09b23abf 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
@@ -151,7 +151,7 @@ static void _brcmf_set_multicast_list(struct work_struct 
*work)
/* Send down the multicast list first. */
cnt = netdev_mc_count(ndev);
buflen = sizeof(cnt) + (cnt * ETH_ALEN);
-   buf = kmalloc(buflen, GFP_ATOMIC);
+   buf = kmalloc(buflen, GFP_KERNEL);
if (!buf)
return;
bufp = buf;
-- 
2.27.0



Re: [PATCH 1/2] workqueue: Have 'alloc_workqueue()' like macros accept a format specifier

2021-04-19 Thread Marion et Christophe JAILLET
 

> Message du 19/04/21 01:03
> De : "Bart Van Assche" 
> A : "Christophe JAILLET" , t...@kernel.org, jiangshan...@gmail.com, 
> sae...@nvidia.com, l...@kernel.org, da...@davemloft.net, k...@kernel.org, 
> "Tejun Heo" 
> Copie à : net...@vger.kernel.org, linux-r...@vger.kernel.org, 
> linux-kernel@vger.kernel.org, kernel-janit...@vger.kernel.org
> Objet : Re: [PATCH 1/2] workqueue: Have 'alloc_workqueue()' like macros 
> accept a format specifier
> 
> On 4/18/21 2:26 PM, Christophe JAILLET wrote:
> > Improve 'create_workqueue', 'create_freezable_workqueue' and
> > 'create_singlethread_workqueue' so that they accept a format
> > specifier and a variable number of arguments.
> > 
> > This will put these macros more in line with 'alloc_ordered_workqueue' and
> > the underlying 'alloc_workqueue()' function.
> > 
> > This will also allow further code simplification.
> 
> Please Cc Tejun for workqueue changes since he maintains the workqueue code.
>
 
Hi,

The list in To: is the one given by get_maintainer.pl. Usualy, I only put the 
ML in Cc:
I've run the script on the 2 patches of the serie and merged the 2 lists. 
Everyone is in the To: of the cover letter and of the 2 patches.

If Théo is "Tejun Heo" (  (maintainer:WORKQUEUE) ), he is already in the To: 
line.

CJ


> > diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
> > index d15a7730ee18..145e756ff315 100644
> > --- a/include/linux/workqueue.h
> > +++ b/include/linux/workqueue.h
> > @@ -425,13 +425,13 @@ struct workqueue_struct *alloc_workqueue(const char 
> > *fmt,
> > alloc_workqueue(fmt, WQ_UNBOUND | __WQ_ORDERED | \
> > __WQ_ORDERED_EXPLICIT | (flags), 1, ##args)
> > 
> > -#define create_workqueue(name) \
> > - alloc_workqueue("%s", __WQ_LEGACY | WQ_MEM_RECLAIM, 1, (name))
> > -#define create_freezable_workqueue(name) \
> > - alloc_workqueue("%s", __WQ_LEGACY | WQ_FREEZABLE | WQ_UNBOUND | \
> > - WQ_MEM_RECLAIM, 1, (name))
> > -#define create_singlethread_workqueue(name) \
> > - alloc_ordered_workqueue("%s", __WQ_LEGACY | WQ_MEM_RECLAIM, name)
> > +#define create_workqueue(fmt, args...) \
> > + alloc_workqueue(fmt, __WQ_LEGACY | WQ_MEM_RECLAIM, 1, ##args)
> > +#define create_freezable_workqueue(fmt, args...) \
> > + alloc_workqueue(fmt, __WQ_LEGACY | WQ_FREEZABLE | WQ_UNBOUND | \
> > + WQ_MEM_RECLAIM, 1, ##args)
> > +#define create_singlethread_workqueue(fmt, args...) \
> > + alloc_ordered_workqueue(fmt, __WQ_LEGACY | WQ_MEM_RECLAIM, ##args)
> > 
> > extern void destroy_workqueue(struct workqueue_struct *wq);
> > 
> > 
> 
>


Re: [PATCH] net/mlx5: Use kasprintf instead of hand-writing it

2021-04-18 Thread Christophe JAILLET

Le 18/04/2021 à 22:03, Bart Van Assche a écrit :

On 4/17/21 12:16 AM, Christophe JAILLET wrote:

'kasprintf()' can replace a kmalloc/strcpy/strcat sequence.
It is less verbose and avoid the use of a magic number (64).

Anyway, the underlying 'alloc_workqueue()' would only keep the 24 first
chars (i.e. sizeof(struct workqueue_struct->name) = WQ_NAME_LEN).

Signed-off-by: Christophe JAILLET 
---
  drivers/net/ethernet/mellanox/mlx5/core/health.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/health.c 
b/drivers/net/ethernet/mellanox/mlx5/core/health.c
index 9ff163c5bcde..a5383e701b4b 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/health.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/health.c
@@ -802,12 +802,10 @@ int mlx5_health_init(struct mlx5_core_dev *dev)
mlx5_fw_reporters_create(dev);
  
  	health = >priv.health;

-   name = kmalloc(64, GFP_KERNEL);
+   name = kasprintf(GFP_KERNEL, "mlx5_health%s", dev_name(dev->device));
if (!name)
goto out_err;
  
-	strcpy(name, "mlx5_health");

-   strcat(name, dev_name(dev->device));
health->wq = create_singlethread_workqueue(name);
kfree(name);
if (!health->wq)


Instead of modifying the mlx5 driver, please change the definition of
the create_singlethread_workqueue() such that it accept a format
specifier and a variable number of arguments.



Agreed. I've sent another patch serie which is more elegant.
Thanks for the feedback.

CJ


Thanks,

Bart.







[PATCH 2/2] net/mlx5: Simplify workqueue name creation

2021-04-18 Thread Christophe JAILLET
There is no need to explicitly allocate, populate and free some memory
just to pass a workqueue name to 'create_singlethread_workqueue()'.

This macro can do all this for us, so keep the code simple.

Signed-off-by: Christophe JAILLET 
---
A similar patch has also been sent. It was replacing the kmalloc/strcpy/
strcat with a kasprintf.
Updating 'create_singlethread_workqueue' gives an even more elegant solution.
---
 drivers/net/ethernet/mellanox/mlx5/core/health.c | 9 +
 1 file changed, 2 insertion(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/health.c 
b/drivers/net/ethernet/mellanox/mlx5/core/health.c
index 9ff163c5bcde..160f852b7bbe 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/health.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/health.c
@@ -797,19 +797,13 @@ void mlx5_health_cleanup(struct mlx5_core_dev *dev)
 int mlx5_health_init(struct mlx5_core_dev *dev)
 {
struct mlx5_core_health *health;
-   char *name;
 
mlx5_fw_reporters_create(dev);
 
health = >priv.health;
-   name = kmalloc(64, GFP_KERNEL);
-   if (!name)
-   goto out_err;
 
-   strcpy(name, "mlx5_health");
-   strcat(name, dev_name(dev->device));
-   health->wq = create_singlethread_workqueue(name);
-   kfree(name);
+   health->wq = create_singlethread_workqueue("mlx5_health%s",
+  dev_name(dev->device));
if (!health->wq)
goto out_err;
spin_lock_init(>wq_lock);
-- 
2.27.0



[PATCH 1/2] workqueue: Have 'alloc_workqueue()' like macros accept a format specifier

2021-04-18 Thread Christophe JAILLET
Improve 'create_workqueue', 'create_freezable_workqueue' and
'create_singlethread_workqueue' so that they accept a format
specifier and a variable number of arguments.

This will put these macros more in line with 'alloc_ordered_workqueue' and
the underlying 'alloc_workqueue()' function.

This will also allow further code simplification.

Suggested-by: Bart Van Assche 
Signed-off-by: Christophe JAILLET 
---
 include/linux/workqueue.h | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
index d15a7730ee18..145e756ff315 100644
--- a/include/linux/workqueue.h
+++ b/include/linux/workqueue.h
@@ -425,13 +425,13 @@ struct workqueue_struct *alloc_workqueue(const char *fmt,
alloc_workqueue(fmt, WQ_UNBOUND | __WQ_ORDERED |\
__WQ_ORDERED_EXPLICIT | (flags), 1, ##args)
 
-#define create_workqueue(name) \
-   alloc_workqueue("%s", __WQ_LEGACY | WQ_MEM_RECLAIM, 1, (name))
-#define create_freezable_workqueue(name)   \
-   alloc_workqueue("%s", __WQ_LEGACY | WQ_FREEZABLE | WQ_UNBOUND | \
-   WQ_MEM_RECLAIM, 1, (name))
-#define create_singlethread_workqueue(name)\
-   alloc_ordered_workqueue("%s", __WQ_LEGACY | WQ_MEM_RECLAIM, name)
+#define create_workqueue(fmt, args...) \
+   alloc_workqueue(fmt, __WQ_LEGACY | WQ_MEM_RECLAIM, 1, ##args)
+#define create_freezable_workqueue(fmt, args...)   \
+   alloc_workqueue(fmt, __WQ_LEGACY | WQ_FREEZABLE | WQ_UNBOUND |  \
+   WQ_MEM_RECLAIM, 1, ##args)
+#define create_singlethread_workqueue(fmt, args...)\
+   alloc_ordered_workqueue(fmt, __WQ_LEGACY | WQ_MEM_RECLAIM, ##args)
 
 extern void destroy_workqueue(struct workqueue_struct *wq);
 
-- 
2.27.0



[PATCH 0/2] workqueue: Have 'alloc_workqueue()' like macros accept a format specifier

2021-04-18 Thread Christophe JAILLET
Improve 'create_workqueue', 'create_freezable_workqueue' and
'create_singlethread_workqueue' so that they accept a format
specifier and a variable number of arguments.

This will put these macros more in line with 'alloc_ordered_workqueue' and
the underlying 'alloc_workqueue()' function.

This will also allow further code simplification.

Patch 1 is the modification of the macro.
Patch 2 is an example of simplification possible with this patch

Christophe JAILLET (2):
  workqueue: Have 'alloc_workqueue()' like macros accept a  format
specifier
  net/mlx5: Simplify workqueue name creation

 drivers/net/ethernet/mellanox/mlx5/core/health.c |  9 +
 include/linux/workqueue.h| 14 +++---
 2 files changed, 8 insertions(+), 15 deletions(-)

-- 
2.27.0



[PATCH] net/mlx5: Use kasprintf instead of hand-writing it

2021-04-17 Thread Christophe JAILLET
'kasprintf()' can replace a kmalloc/strcpy/strcat sequence.
It is less verbose and avoid the use of a magic number (64).

Anyway, the underlying 'alloc_workqueue()' would only keep the 24 first
chars (i.e. sizeof(struct workqueue_struct->name) = WQ_NAME_LEN).

Signed-off-by: Christophe JAILLET 
---
 drivers/net/ethernet/mellanox/mlx5/core/health.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/health.c 
b/drivers/net/ethernet/mellanox/mlx5/core/health.c
index 9ff163c5bcde..a5383e701b4b 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/health.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/health.c
@@ -802,12 +802,10 @@ int mlx5_health_init(struct mlx5_core_dev *dev)
mlx5_fw_reporters_create(dev);
 
health = >priv.health;
-   name = kmalloc(64, GFP_KERNEL);
+   name = kasprintf(GFP_KERNEL, "mlx5_health%s", dev_name(dev->device));
if (!name)
goto out_err;
 
-   strcpy(name, "mlx5_health");
-   strcat(name, dev_name(dev->device));
health->wq = create_singlethread_workqueue(name);
kfree(name);
if (!health->wq)
-- 
2.27.0



Re: [PATCH] checkpatch: Improve ALLOC_ARRAY_ARGS test

2021-04-16 Thread Christophe JAILLET

Le 16/04/2021 à 19:03, Joe Perches a écrit :

On Fri, 2021-04-16 at 18:51 +0200, Christophe JAILLET wrote:

Le 16/04/2021 à 18:11, Joe Perches a écrit :

On Fri, 2021-04-16 at 17:58 +0200, Christophe JAILLET wrote:

The devm_ variant of 'kcalloc()' and 'kmalloc_array()' are not tested
Add the corresponding check.

[]

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl

[]

@@ -7006,9 +7006,9 @@ sub process {
    }
   



   # check for alloc argument mismatch
-   if ($line =~ /\b(kcalloc|kmalloc_array)\s*\(\s*sizeof\b/) {
+   if ($line =~ 
/\b(devm_|)(kcalloc|kmalloc_array)\s*\(\s*sizeof\b/) {


Perhaps nicer using

I'll send a V2.

Thx for the feedback.

CJ



if ($line =~ 
/\b((?:devm_)?(?:kcalloc|kmalloc_array))\s*\*\s*sizeof\b/) {


The \* above should be \(.



Yes I've seen it when I tested the updated test case.


I can't type and apparently I don't proofread either.
I offer the excuse that the * and ( are adjacent on my keyboard...



Well, you should try with a French keyboard :)
Anyway, thanks for taking time for the update.

CJ


cheers, Joe







[PATCH v2] checkpatch: Improve ALLOC_ARRAY_ARGS test

2021-04-16 Thread Christophe JAILLET
The devm_ variant of 'kcalloc()' and 'kmalloc_array()' are not tested
Add the corresponding check.

Signed-off-by: Christophe JAILLET 
---
v2: use a cleaner regex as proposed by Joe Perches
---
 scripts/checkpatch.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 44b9dc330ac6..23697a6b1eaa 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -7006,7 +7006,7 @@ sub process {
}
 
 # check for alloc argument mismatch
-   if ($line =~ /\b(kcalloc|kmalloc_array)\s*\(\s*sizeof\b/) {
+   if ($line =~ 
/\b((?:devm_)?(?:kcalloc|kmalloc_array))\s*\(\s*sizeof\b/) {
WARN("ALLOC_ARRAY_ARGS",
 "$1 uses number as first arg, sizeof is generally 
wrong\n" . $herecurr);
}
-- 
2.27.0



Re: [PATCH] checkpatch: Improve ALLOC_ARRAY_ARGS test

2021-04-16 Thread Christophe JAILLET

Le 16/04/2021 à 18:11, Joe Perches a écrit :

On Fri, 2021-04-16 at 17:58 +0200, Christophe JAILLET wrote:

The devm_ variant of 'kcalloc()' and 'kmalloc_array()' are not tested
Add the corresponding check.

[]

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl

[]

@@ -7006,9 +7006,9 @@ sub process {
    }
  


  # check for alloc argument mismatch
-   if ($line =~ /\b(kcalloc|kmalloc_array)\s*\(\s*sizeof\b/) {
+   if ($line =~ 
/\b(devm_|)(kcalloc|kmalloc_array)\s*\(\s*sizeof\b/) {


Perhaps nicer using

Indeed, much better.
I'll send a V2.

Thx for the feedback.

CJ



if ($line =~ 
/\b((?:devm_)?(?:kcalloc|kmalloc_array))\s*\*\s*sizeof\b/) {


    WARN("ALLOC_ARRAY_ARGS",
-"$1 uses number as first arg, sizeof is generally 
wrong\n" . $herecurr);
+"$1$2 uses number as first arg, sizeof is generally 
wrong\n" . $herecurr);


So there's only one capture group and this line doesn't need to be changed.







[PATCH] checkpatch: Improve ALLOC_ARRAY_ARGS test

2021-04-16 Thread Christophe JAILLET
The devm_ variant of 'kcalloc()' and 'kmalloc_array()' are not tested
Add the corresponding check.

Signed-off-by: Christophe JAILLET 
---
 scripts/checkpatch.pl | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 44b9dc330ac6..c778edfdbad7 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -7006,9 +7006,9 @@ sub process {
}
 
 # check for alloc argument mismatch
-   if ($line =~ /\b(kcalloc|kmalloc_array)\s*\(\s*sizeof\b/) {
+   if ($line =~ 
/\b(devm_|)(kcalloc|kmalloc_array)\s*\(\s*sizeof\b/) {
WARN("ALLOC_ARRAY_ARGS",
-"$1 uses number as first arg, sizeof is generally 
wrong\n" . $herecurr);
+"$1$2 uses number as first arg, sizeof is 
generally wrong\n" . $herecurr);
}
 
 # check for multiple semicolons
-- 
2.27.0



[PATCH 2/2] Input: evbug - Use 'pr_debug()' instead of hand-writing it

2021-04-15 Thread Christophe JAILLET
'printk(KERN_DEBUG pr_fmt(...))' can be replaced by a much less verbose
'pr_debug()'.

Signed-off-by: Christophe JAILLET 
---
 drivers/input/evbug.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/input/evbug.c b/drivers/input/evbug.c
index e47bdf92088a..88ad88300181 100644
--- a/drivers/input/evbug.c
+++ b/drivers/input/evbug.c
@@ -21,8 +21,8 @@ MODULE_LICENSE("GPL");
 
 static void evbug_event(struct input_handle *handle, unsigned int type, 
unsigned int code, int value)
 {
-   printk(KERN_DEBUG pr_fmt("Event. Dev: %s, Type: %d, Code: %d, Value: 
%d\n"),
-  dev_name(>dev->dev), type, code, value);
+   pr_debug("Event. Dev: %s, Type: %d, Code: %d, Value: %d\n",
+dev_name(>dev->dev), type, code, value);
 }
 
 static int evbug_connect(struct input_handler *handler, struct input_dev *dev,
@@ -47,10 +47,10 @@ static int evbug_connect(struct input_handler *handler, 
struct input_dev *dev,
if (error)
goto err_unregister_handle;
 
-   printk(KERN_DEBUG pr_fmt("Connected device: %s (%s at %s)\n"),
-  dev_name(>dev),
-  dev->name ?: "unknown",
-  dev->phys ?: "unknown");
+   pr_debug("Connected device: %s (%s at %s)\n",
+dev_name(>dev),
+dev->name ?: "unknown",
+dev->phys ?: "unknown");
 
return 0;
 
@@ -63,8 +63,8 @@ static int evbug_connect(struct input_handler *handler, 
struct input_dev *dev,
 
 static void evbug_disconnect(struct input_handle *handle)
 {
-   printk(KERN_DEBUG pr_fmt("Disconnected device: %s\n"),
-  dev_name(>dev->dev));
+   pr_debug("Disconnected device: %s\n",
+dev_name(>dev->dev));
 
input_close_device(handle);
input_unregister_handle(handle);
-- 
2.27.0



[PATCH 1/2] Input: evbug - Remove an empty comment block

2021-04-15 Thread Christophe JAILLET
This is a left-over from commit 1a59d1b8e05e ("treewide: Replace GPLv2
boilerplate/reference with SPDX - rule 156")

Axe an empty and useless comment block.

Signed-off-by: Christophe JAILLET 
---
 drivers/input/evbug.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/input/evbug.c b/drivers/input/evbug.c
index c0d0b121ae7e..e47bdf92088a 100644
--- a/drivers/input/evbug.c
+++ b/drivers/input/evbug.c
@@ -7,9 +7,6 @@
  *  Input driver event debug module - dumps all events into syslog
  */
 
-/*
- */
-
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
 #include 
-- 
2.27.0



Re: [PATCH] ASoC: cs35l35: Fix an error handling path in 'cs35l35_i2c_probe()'

2021-04-13 Thread Christophe JAILLET

Le 13/04/2021 à 14:43, Mark Brown a écrit :

On Sun, Apr 11, 2021 at 02:51:06PM +0200, Christophe JAILLET wrote:

If 'devm_regmap_init_i2c()' fails, there is no need to goto err. We should
return directly as already done by the surrounding error handling paths.


These are stylistic improvements rather than bug fixes so it's probably
better not to call them fixes.



Ok, agreed.
The error handling path is a no-op in such a case.

What do you prefer:
  - you fix the subject?
  - I send a v2 with a new subject?
  - we leave it as-is as this patch is a no-op in the real world? So it 
doesn't really mater.


CJ


Re: [PATCH 2/3] staging: rtl8723bs: Use existing arc4 implementation

2021-04-12 Thread Christophe JAILLET

Le 12/04/2021 à 11:34, Greg KH a écrit :

On Sat, Apr 10, 2021 at 03:35:52PM +0200, Christophe JAILLET wrote:

Use functions provided by  instead of hand writing them.

The implementations are slightly different, but are equivalent. It has
been checked with a test program which compares the output of the 2 sets of
functions.

Signed-off-by: Christophe JAILLET 
---
  drivers/staging/rtl8723bs/core/rtw_security.c | 101 --
  1 file changed, 21 insertions(+), 80 deletions(-)

diff --git a/drivers/staging/rtl8723bs/core/rtw_security.c 
b/drivers/staging/rtl8723bs/core/rtw_security.c
index 9587d89a6b24..86949a65e96f 100644
--- a/drivers/staging/rtl8723bs/core/rtw_security.c
+++ b/drivers/staging/rtl8723bs/core/rtw_security.c
@@ -6,6 +6,7 @@
   
**/
  #define  _RTW_SECURITY_C_
  
+#include 

  #include 
  #include 
  #include 
@@ -31,66 +32,6 @@ const char *security_type_str(u8 value)
  
  /* WEP related = */
  
-struct arc4context {

-   u32 x;
-   u32 y;
-   u8 state[256];
-};
-
-
-static void arcfour_init(struct arc4context*parc4ctx, u8 *key, u32 key_len)
-{
-   u32 t, u;
-   u32 keyindex;
-   u32 stateindex;
-   u8 *state;
-   u32 counter;
-
-   state = parc4ctx->state;
-   parc4ctx->x = 0;
-   parc4ctx->y = 0;
-   for (counter = 0; counter < 256; counter++)
-   state[counter] = (u8)counter;
-   keyindex = 0;
-   stateindex = 0;
-   for (counter = 0; counter < 256; counter++) {
-   t = state[counter];
-   stateindex = (stateindex + key[keyindex] + t) & 0xff;
-   u = state[stateindex];
-   state[stateindex] = (u8)t;
-   state[counter] = (u8)u;
-   if (++keyindex >= key_len)
-   keyindex = 0;
-   }
-}
-
-static u32 arcfour_byte(struct arc4context *parc4ctx)
-{
-   u32 x;
-   u32 y;
-   u32 sx, sy;
-   u8 *state;
-
-   state = parc4ctx->state;
-   x = (parc4ctx->x + 1) & 0xff;
-   sx = state[x];
-   y = (sx + parc4ctx->y) & 0xff;
-   sy = state[y];
-   parc4ctx->x = x;
-   parc4ctx->y = y;
-   state[y] = (u8)sx;
-   state[x] = (u8)sy;
-   return state[(sx + sy) & 0xff];
-}
-
-static void arcfour_encrypt(struct arc4context *parc4ctx, u8 *dest, u8 *src, 
u32 len)
-{
-   u32 i;
-
-   for (i = 0; i < len; i++)
-   dest[i] = src[i] ^ (unsigned char)arcfour_byte(parc4ctx);
-}
-
  static signed int bcrc32initialized;
  static u32 crc32_table[256];
  
@@ -150,7 +91,7 @@ void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe)

  { 
/*  exclude ICV */
  
  	unsigned char crc[4];

-   struct arc4context   mycontext;
+   struct arc4_ctx mycontext;


Are you sure you can declare that much space on the stack?  Is that what
other users of this api do?  In looking at the in-kernel users, they do
not :(



In fact arc4context was a u8[256] but arc4_ctx uses a u32[256].

Maybe arc4 function should be modified to use u8? Or at least when
CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS is defined?



Concerning the other uses of the arc4 API, in fact there is only few of 
them. Most uses are buried into lib80211_crypt_tkip.c and 
lib80211_crypt_wep.c which is the way to go, IMHO.
In fact, I think that most, if not all 'rtl871x_security.c' could be 
removed.


However, it looks like a big step to me. And without any hardware to 
test, I'm pretty sure to break something.



Any hints on the best way to axe some duplicated code without to much 
risks to break everything?


CJ


Can you fix up this series to not take up so much stack memory?


I guess that _adapter could be used to store this arc4_ctx, but I'm not 
convinced that it is the way to go.


CJ



thanks,

greg k-h





[PATCH] ASoC: cs35l36: Fix an error handling path in 'cs35l36_i2c_probe()'

2021-04-11 Thread Christophe JAILLET
If 'devm_regmap_init_i2c()' fails, there is no need to goto err. We should
return directly as already done by the surrounding error handling paths.

Signed-off-by: Christophe JAILLET 
---
 sound/soc/codecs/cs35l36.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/soc/codecs/cs35l36.c b/sound/soc/codecs/cs35l36.c
index 4451ca9f4916..a038bcec2d17 100644
--- a/sound/soc/codecs/cs35l36.c
+++ b/sound/soc/codecs/cs35l36.c
@@ -1721,7 +1721,7 @@ static int cs35l36_i2c_probe(struct i2c_client 
*i2c_client,
if (IS_ERR(cs35l36->regmap)) {
ret = PTR_ERR(cs35l36->regmap);
dev_err(dev, "regmap_init() failed: %d\n", ret);
-   goto err;
+   return ret;
}
 
cs35l36->num_supplies = ARRAY_SIZE(cs35l36_supplies);
-- 
2.27.0



[PATCH] ASoC: cs35l35: Fix an error handling path in 'cs35l35_i2c_probe()'

2021-04-11 Thread Christophe JAILLET
If 'devm_regmap_init_i2c()' fails, there is no need to goto err. We should
return directly as already done by the surrounding error handling paths.

Signed-off-by: Christophe JAILLET 
---
 sound/soc/codecs/cs35l35.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/soc/codecs/cs35l35.c b/sound/soc/codecs/cs35l35.c
index 55d529aa0011..7b9f5498f8a7 100644
--- a/sound/soc/codecs/cs35l35.c
+++ b/sound/soc/codecs/cs35l35.c
@@ -1488,7 +1488,7 @@ static int cs35l35_i2c_probe(struct i2c_client 
*i2c_client,
if (IS_ERR(cs35l35->regmap)) {
ret = PTR_ERR(cs35l35->regmap);
dev_err(dev, "regmap_init() failed: %d\n", ret);
-   goto err;
+   return ret;
}
 
for (i = 0; i < ARRAY_SIZE(cs35l35_supplies); i++)
-- 
2.27.0



[PATCH] tracing/dynevent: Fix a memory leak in an error handling path

2021-04-11 Thread Christophe JAILLET
We must free 'argv' before returning, as already done in all the other
paths of this function.

Fixes: d262271d0483 ("tracing/dynevent: Delegate parsing to create function")
Signed-off-by: Christophe JAILLET 
---
 kernel/trace/trace_dynevent.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/kernel/trace/trace_dynevent.c b/kernel/trace/trace_dynevent.c
index dc971a68dda4..e57cc0870892 100644
--- a/kernel/trace/trace_dynevent.c
+++ b/kernel/trace/trace_dynevent.c
@@ -63,8 +63,10 @@ int dyn_event_release(const char *raw_command, struct 
dyn_event_operations *type
event = p + 1;
*p = '\0';
}
-   if (event[0] == '\0')
-   return -EINVAL;
+   if (event[0] == '\0') {
+   ret = -EINVAL;
+   goto out;
+   }
 
mutex_lock(_mutex);
for_each_dyn_event_safe(pos, n) {
-- 
2.27.0



[PATCH] scsi: qla2xxx: Re-use existing error handling path

2021-04-11 Thread Christophe JAILLET
There is no need to duplicate some code, use the existing error handling
path to free some resources.
This is more future-proof.

Signed-off-by: Christophe JAILLET 
---
The code above this hunk looks spurious to me.

It looks like an error handling path (i.e.
"if (response_len > bsg_job->reply_payload.payload_len)")
but returns 0, which is the initial value of 'ret'.

Shouldn't we have ret = - here?
---
 drivers/scsi/qla2xxx/qla_bsg.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_bsg.c b/drivers/scsi/qla2xxx/qla_bsg.c
index aef2f7cc89d3..d42b2ad84049 100644
--- a/drivers/scsi/qla2xxx/qla_bsg.c
+++ b/drivers/scsi/qla2xxx/qla_bsg.c
@@ -2585,8 +2585,8 @@ qla2x00_get_host_stats(struct bsg_job *bsg_job)
 
data = kzalloc(response_len, GFP_KERNEL);
if (!data) {
-   kfree(req_data);
-   return -ENOMEM;
+   ret = -ENOMEM;
+   goto host_stat_out;
}
 
ret = qla2xxx_get_ini_stats(fc_bsg_to_shost(bsg_job), 
req_data->stat_type,
-- 
2.27.0



[PATCH] net: davicom: Fix regulator not turned off on failed probe

2021-04-11 Thread Christophe JAILLET
When the probe fails, we must disable the regulator that was previously
enabled.

This patch is a follow-up to commit ac88c531a5b3
("net: davicom: Fix regulator not turned off on failed probe") which missed
one case.

Fixes: 7994fe55a4a2 ("dm9000: Add regulator and reset support to dm9000")
Signed-off-by: Christophe JAILLET 
---
 drivers/net/ethernet/davicom/dm9000.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/davicom/dm9000.c 
b/drivers/net/ethernet/davicom/dm9000.c
index 252adfa5d837..8a9096aa85cd 100644
--- a/drivers/net/ethernet/davicom/dm9000.c
+++ b/drivers/net/ethernet/davicom/dm9000.c
@@ -1471,8 +1471,10 @@ dm9000_probe(struct platform_device *pdev)
 
/* Init network device */
ndev = alloc_etherdev(sizeof(struct board_info));
-   if (!ndev)
-   return -ENOMEM;
+   if (!ndev) {
+   ret = -ENOMEM;
+   goto out_regulator_disable;
+   }
 
SET_NETDEV_DEV(ndev, >dev);
 
-- 
2.27.0



[PATCH 2/2] leds: lgm: Fix an error handling path in '__sso_led_dt_parse()'

2021-04-11 Thread Christophe JAILLET
If a memory allocation fails, we must free the already allocated resources
before returning.

Fixes: c3987cd2bca3 ("leds: lgm: Add LED controller driver for LGM SoC")
Signed-off-by: Christophe JAILLET 
---
 drivers/leds/blink/leds-lgm-sso.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/leds/blink/leds-lgm-sso.c 
b/drivers/leds/blink/leds-lgm-sso.c
index 3da242d4ce7d..ef632ebabac9 100644
--- a/drivers/leds/blink/leds-lgm-sso.c
+++ b/drivers/leds/blink/leds-lgm-sso.c
@@ -631,8 +631,10 @@ __sso_led_dt_parse(struct sso_led_priv *priv, struct 
fwnode_handle *fw_ssoled)
 
fwnode_for_each_child_node(fw_ssoled, fwnode_child) {
led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL);
-   if (!led)
-   return -ENOMEM;
+   if (!led) {
+   ret = -ENOMEM;
+   goto __dt_err;
+   }
 
INIT_LIST_HEAD(>list);
led->priv = priv;
-- 
2.27.0



[PATCH 1/2] leds: lgm: Propagate error codes to the caller

2021-04-11 Thread Christophe JAILLET
Do not always return -EINVAL in case of error in '__sso_led_dt_parse()'.
Propagate the error code instead.

Signed-off-by: Christophe JAILLET 
---
 drivers/leds/blink/leds-lgm-sso.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/leds/blink/leds-lgm-sso.c 
b/drivers/leds/blink/leds-lgm-sso.c
index 7d5c9ca007d6..3da242d4ce7d 100644
--- a/drivers/leds/blink/leds-lgm-sso.c
+++ b/drivers/leds/blink/leds-lgm-sso.c
@@ -643,6 +643,7 @@ __sso_led_dt_parse(struct sso_led_priv *priv, struct 
fwnode_handle *fw_ssoled)
  GPIOD_ASIS, NULL);
if (IS_ERR(led->gpiod)) {
dev_err(dev, "led: get gpio fail!\n");
+   ret = PTR_ERR(led->gpiod);
goto __dt_err;
}
 
@@ -664,6 +665,7 @@ __sso_led_dt_parse(struct sso_led_priv *priv, struct 
fwnode_handle *fw_ssoled)
ret = fwnode_property_read_u32(fwnode_child, "reg", );
if (ret != 0 || prop >= SSO_LED_MAX_NUM) {
dev_err(dev, "invalid LED pin:%u\n", prop);
+   ret = ret ? ret : -EINVAL;
goto __dt_err;
}
desc->pin = prop;
@@ -699,8 +701,10 @@ __sso_led_dt_parse(struct sso_led_priv *priv, struct 
fwnode_handle *fw_ssoled)
desc->brightness = LED_FULL;
}
 
-   if (sso_create_led(priv, led, fwnode_child))
+   if (sso_create_led(priv, led, fwnode_child)) {
+   ret = -EINVAL;
goto __dt_err;
+   }
}
fwnode_handle_put(fw_ssoled);
 
@@ -713,7 +717,7 @@ __sso_led_dt_parse(struct sso_led_priv *priv, struct 
fwnode_handle *fw_ssoled)
sso_led_shutdown(led);
}
 
-   return -EINVAL;
+   return ret;
 }
 
 static int sso_led_dt_parse(struct sso_led_priv *priv)
-- 
2.27.0



[PATCH] iommu/vt-d: Fix an error handling path in 'intel_prepare_irq_remapping()'

2021-04-11 Thread Christophe JAILLET
If 'intel_cap_audit()' fails, we should return directly, as already done in
the surrounding error handling path.

Fixes: ad3d19029979 ("iommu/vt-d: Audit IOMMU Capabilities and add helper 
functions")
Signed-off-by: Christophe JAILLET 
---
This patch is completely speculative.
It is based on a spurious mix-up of direct return and goto.
---
 drivers/iommu/intel/irq_remapping.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iommu/intel/irq_remapping.c 
b/drivers/iommu/intel/irq_remapping.c
index 75429a5373ec..f912fe45bea2 100644
--- a/drivers/iommu/intel/irq_remapping.c
+++ b/drivers/iommu/intel/irq_remapping.c
@@ -736,7 +736,7 @@ static int __init intel_prepare_irq_remapping(void)
return -ENODEV;
 
if (intel_cap_audit(CAP_AUDIT_STATIC_IRQR, NULL))
-   goto error;
+   return -ENODEV;
 
if (!dmar_ir_support())
return -ENODEV;
-- 
2.27.0



[PATCH] crypto: crc32-generic - Use SPDX-License-Identifier

2021-04-10 Thread Christophe JAILLET
Use SPDX-License-Identifier: GPL-2.0-only, instead of hand writing it.

This also removes a reference to http://www.xyratex.com which seems to be
down.

Signed-off-by: Christophe JAILLET 
---
 crypto/crc32_generic.c | 24 +---
 1 file changed, 1 insertion(+), 23 deletions(-)

diff --git a/crypto/crc32_generic.c b/crypto/crc32_generic.c
index 0e103fb5dd77..a989cb44fd16 100644
--- a/crypto/crc32_generic.c
+++ b/crypto/crc32_generic.c
@@ -1,26 +1,4 @@
-/* GPL HEADER START
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 only,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License version 2 for more details (a copy is included
- * in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU General Public License
- * version 2 along with this program; If not, see http://www.gnu.org/licenses
- *
- * Please  visit http://www.xyratex.com/contact if you need additional
- * information or have any questions.
- *
- * GPL HEADER END
- */
-
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * Copyright 2012 Xyratex Technology Limited
  */
-- 
2.27.0



[PATCH 2/3] staging: rtl8723bs: Use existing arc4 implementation

2021-04-10 Thread Christophe JAILLET
Use functions provided by  instead of hand writing them.

The implementations are slightly different, but are equivalent. It has
been checked with a test program which compares the output of the 2 sets of
functions.

Signed-off-by: Christophe JAILLET 
---
 drivers/staging/rtl8723bs/core/rtw_security.c | 101 --
 1 file changed, 21 insertions(+), 80 deletions(-)

diff --git a/drivers/staging/rtl8723bs/core/rtw_security.c 
b/drivers/staging/rtl8723bs/core/rtw_security.c
index 9587d89a6b24..86949a65e96f 100644
--- a/drivers/staging/rtl8723bs/core/rtw_security.c
+++ b/drivers/staging/rtl8723bs/core/rtw_security.c
@@ -6,6 +6,7 @@
  
**/
 #define  _RTW_SECURITY_C_
 
+#include 
 #include 
 #include 
 #include 
@@ -31,66 +32,6 @@ const char *security_type_str(u8 value)
 
 /* WEP related = */
 
-struct arc4context {
-   u32 x;
-   u32 y;
-   u8 state[256];
-};
-
-
-static void arcfour_init(struct arc4context*parc4ctx, u8 *key, u32 key_len)
-{
-   u32 t, u;
-   u32 keyindex;
-   u32 stateindex;
-   u8 *state;
-   u32 counter;
-
-   state = parc4ctx->state;
-   parc4ctx->x = 0;
-   parc4ctx->y = 0;
-   for (counter = 0; counter < 256; counter++)
-   state[counter] = (u8)counter;
-   keyindex = 0;
-   stateindex = 0;
-   for (counter = 0; counter < 256; counter++) {
-   t = state[counter];
-   stateindex = (stateindex + key[keyindex] + t) & 0xff;
-   u = state[stateindex];
-   state[stateindex] = (u8)t;
-   state[counter] = (u8)u;
-   if (++keyindex >= key_len)
-   keyindex = 0;
-   }
-}
-
-static u32 arcfour_byte(struct arc4context *parc4ctx)
-{
-   u32 x;
-   u32 y;
-   u32 sx, sy;
-   u8 *state;
-
-   state = parc4ctx->state;
-   x = (parc4ctx->x + 1) & 0xff;
-   sx = state[x];
-   y = (sx + parc4ctx->y) & 0xff;
-   sy = state[y];
-   parc4ctx->x = x;
-   parc4ctx->y = y;
-   state[y] = (u8)sx;
-   state[x] = (u8)sy;
-   return state[(sx + sy) & 0xff];
-}
-
-static void arcfour_encrypt(struct arc4context *parc4ctx, u8 *dest, u8 *src, 
u32 len)
-{
-   u32 i;
-
-   for (i = 0; i < len; i++)
-   dest[i] = src[i] ^ (unsigned char)arcfour_byte(parc4ctx);
-}
-
 static signed int bcrc32initialized;
 static u32 crc32_table[256];
 
@@ -150,7 +91,7 @@ void rtw_wep_encrypt(struct adapter *padapter, u8 
*pxmitframe)
 {  
/*  exclude ICV */
 
unsigned char crc[4];
-   struct arc4context   mycontext;
+   struct arc4_ctx mycontext;
 
signed int  curfragnum, length;
u32 keylength;
@@ -184,16 +125,16 @@ void rtw_wep_encrypt(struct adapter *padapter, u8 
*pxmitframe)
 
*((__le32 *)crc) = getcrc32(payload, length);
 
-   arcfour_init(, wepkey, 3+keylength);
-   arcfour_encrypt(, payload, payload, 
length);
-   arcfour_encrypt(, payload+length, 
crc, 4);
+   arc4_setkey(, wepkey, 3 + keylength);
+   arc4_crypt(, payload, payload, 
length);
+   arc4_crypt(, payload + length, crc, 
4);
 
} else {
length = 
pxmitpriv->frag_len-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len;
*((__le32 *)crc) = getcrc32(payload, length);
-   arcfour_init(, wepkey, 3+keylength);
-   arcfour_encrypt(, payload, payload, 
length);
-   arcfour_encrypt(, payload+length, 
crc, 4);
+   arc4_setkey(, wepkey, 3 + keylength);
+   arc4_crypt(, payload, payload, 
length);
+   arc4_crypt(, payload + length, crc, 
4);
 
pframe += pxmitpriv->frag_len;
pframe = (u8 *)round_up((SIZE_PTR)(pframe), 4);
@@ -206,7 +147,7 @@ void rtw_wep_decrypt(struct adapter  *padapter, u8 
*precvframe)
 {
/*  exclude ICV */
u8 crc[4];
-   struct arc4context   mycontext;
+   struct arc4_ctx mycontext;
signed int  length;
u32 keylength;
u8 *pframe, *payload, *iv, wepkey[16];
@@ -230,8 +171,8 @@ void rtw_wep_decrypt(struct adapter  *padapter, u8 
*precvframe)
payload = pframe+prxattrib->iv_len+prxattrib->hdrlen;
 
/* decrypt payload include icv */
-   arcfour_init(, wepkey, 3+keylength);
-   

[PATCH 3/3] staging: rtl8712: Use existing arc4 implementation

2021-04-10 Thread Christophe JAILLET
Use functions provided by  instead of hand writing them.

The implementations are slightly different, but are equivalent. It has
been checked with a test program which compares the output of the 2 sets of
functions.

Signed-off-by: Christophe JAILLET 
---
 drivers/staging/rtl8712/rtl871x_security.c | 118 +
 1 file changed, 29 insertions(+), 89 deletions(-)

diff --git a/drivers/staging/rtl8712/rtl871x_security.c 
b/drivers/staging/rtl8712/rtl871x_security.c
index 1c7df65db3c9..b546e2f19620 100644
--- a/drivers/staging/rtl8712/rtl871x_security.c
+++ b/drivers/staging/rtl8712/rtl871x_security.c
@@ -16,6 +16,7 @@
 
 #define  _RTL871X_SECURITY_C_
 
+#include 
 #include 
 #include 
 #include 
@@ -38,66 +39,6 @@
 
 /* =WEP related= */
 
-struct arc4context {
-   u32 x;
-   u32 y;
-   u8 state[256];
-};
-
-static void arcfour_init(struct arc4context *parc4ctx, u8 *key, u32 key_len)
-{
-   u32 t, u;
-   u32 keyindex;
-   u32 stateindex;
-   u8 *state;
-   u32 counter;
-
-   state = parc4ctx->state;
-   parc4ctx->x = 0;
-   parc4ctx->y = 0;
-   for (counter = 0; counter < 256; counter++)
-   state[counter] = (u8)counter;
-   keyindex = 0;
-   stateindex = 0;
-   for (counter = 0; counter < 256; counter++) {
-   t = state[counter];
-   stateindex = (stateindex + key[keyindex] + t) & 0xff;
-   u = state[stateindex];
-   state[stateindex] = (u8)t;
-   state[counter] = (u8)u;
-   if (++keyindex >= key_len)
-   keyindex = 0;
-   }
-}
-
-static u32 arcfour_byte(struct arc4context *parc4ctx)
-{
-   u32 x;
-   u32 y;
-   u32 sx, sy;
-   u8 *state;
-
-   state = parc4ctx->state;
-   x = (parc4ctx->x + 1) & 0xff;
-   sx = state[x];
-   y = (sx + parc4ctx->y) & 0xff;
-   sy = state[y];
-   parc4ctx->x = x;
-   parc4ctx->y = y;
-   state[y] = (u8)sx;
-   state[x] = (u8)sy;
-   return state[(sx + sy) & 0xff];
-}
-
-static void arcfour_encrypt(struct arc4context *parc4ctx,
-u8 *dest, u8 *src, u32 len)
-{
-   u32 i;
-
-   for (i = 0; i < len; i++)
-   dest[i] = src[i] ^ (unsigned char)arcfour_byte(parc4ctx);
-}
-
 static sint bcrc32initialized;
 static u32 crc32_table[256];
 
@@ -151,7 +92,7 @@ static u32 getcrc32(u8 *buf, u32 len)
 void r8712_wep_encrypt(struct _adapter *padapter, u8 *pxmitframe)
 {  /* exclude ICV */
unsigned char   crc[4];
-   struct arc4context  mycontext;
+   struct arc4_ctx  mycontext;
u32 curfragnum, length, keylength, pki;
u8 *pframe, *payload, *iv;/*,*wepkey*/
u8 wepkey[16];
@@ -182,22 +123,22 @@ void r8712_wep_encrypt(struct _adapter *padapter, u8 
*pxmitframe)
pattrib->icv_len;
*((__le32 *)crc) = cpu_to_le32(getcrc32(
payload, length));
-   arcfour_init(, wepkey, 3 + keylength);
-   arcfour_encrypt(, payload, payload,
-   length);
-   arcfour_encrypt(, payload + length,
-   crc, 4);
+   arc4_setkey(, wepkey, 3 + keylength);
+   arc4_crypt(, payload, payload,
+  length);
+   arc4_crypt(, payload + length,
+  crc, 4);
} else {
length = pxmitpriv->frag_len -
 pattrib->hdrlen - pattrib->iv_len -
 pattrib->icv_len;
*((__le32 *)crc) = cpu_to_le32(getcrc32(
payload, length));
-   arcfour_init(, wepkey, 3 + keylength);
-   arcfour_encrypt(, payload, payload,
-   length);
-   arcfour_encrypt(, payload + length,
-   crc, 4);
+   arc4_setkey(, wepkey, 3 + keylength);
+   arc4_crypt(, payload, payload,
+  length);
+   arc4_crypt(, payload + length,
+  crc, 4);
pframe += pxmitpriv->frag_len;
pframe = (u8 *)RND4((addr_t)(pframe));
}
@@ -209,7 +150,7 @@ void r8712_wep_decrypt(struct _adapter  *padapter, u8 
*prec

[PATCH 1/3] staging: rtl8188eu: Use existing arc4 implementation

2021-04-10 Thread Christophe JAILLET
Use functions provided by  instead of hand writing them.

The implementations are slightly different, but are equivalent. It has
been checked with a test program which compares the output of the 2 sets of
functions.

Signed-off-by: Christophe JAILLET 
---
 drivers/staging/rtl8188eu/core/rtw_security.c | 80 +++
 1 file changed, 11 insertions(+), 69 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_security.c 
b/drivers/staging/rtl8188eu/core/rtw_security.c
index 617f89842c81..61e3eb0a4791 100644
--- a/drivers/staging/rtl8188eu/core/rtw_security.c
+++ b/drivers/staging/rtl8188eu/core/rtw_security.c
@@ -6,6 +6,7 @@
  
**/
 #define  _RTW_SECURITY_C_
 
+#include 
 #include 
 #include 
 #include 
@@ -16,65 +17,6 @@
 
 #define CRC32_POLY 0x04c11db7
 
-struct arc4context {
-   u32 x;
-   u32 y;
-   u8 state[256];
-};
-
-static void arcfour_init(struct arc4context *parc4ctx, u8 *key, u32key_len)
-{
-   u32 t, u;
-   u32 keyindex;
-   u32 stateindex;
-   u8 *state;
-   u32 counter;
-
-   state = parc4ctx->state;
-   parc4ctx->x = 0;
-   parc4ctx->y = 0;
-   for (counter = 0; counter < 256; counter++)
-   state[counter] = (u8)counter;
-   keyindex = 0;
-   stateindex = 0;
-   for (counter = 0; counter < 256; counter++) {
-   t = state[counter];
-   stateindex = (stateindex + key[keyindex] + t) & 0xff;
-   u = state[stateindex];
-   state[stateindex] = (u8)t;
-   state[counter] = (u8)u;
-   if (++keyindex >= key_len)
-   keyindex = 0;
-   }
-}
-
-static u32 arcfour_byte(struct arc4context *parc4ctx)
-{
-   u32 x;
-   u32 y;
-   u32 sx, sy;
-   u8 *state;
-
-   state = parc4ctx->state;
-   x = (parc4ctx->x + 1) & 0xff;
-   sx = state[x];
-   y = (sx + parc4ctx->y) & 0xff;
-   sy = state[y];
-   parc4ctx->x = x;
-   parc4ctx->y = y;
-   state[y] = (u8)sx;
-   state[x] = (u8)sy;
-   return state[(sx + sy) & 0xff];
-}
-
-static void arcfour_encrypt(struct arc4context *parc4ctx, u8 *dest, u8 *src, 
u32 len)
-{
-   u32 i;
-
-   for (i = 0; i < len; i++)
-   dest[i] = src[i] ^ (unsigned char)arcfour_byte(parc4ctx);
-}
-
 static int bcrc32initialized;
 static u32 crc32_table[256];
 
@@ -564,7 +506,7 @@ u32 rtw_tkip_encrypt(struct adapter *padapter, struct 
xmit_frame *pxmitframe)
u8   ttkey[16];
u8  crc[4];
u8   hw_hdr_offset = 0;
-   struct arc4context mycontext;
+   struct arc4_ctx mycontext;
int curfragnum, length;
 
u8  *pframe, *payload, *iv, *prwskey;
@@ -614,15 +556,15 @@ u32   rtw_tkip_encrypt(struct adapter *padapter, 
struct xmit_frame *pxmitframe)
 pattrib->iv_len, 
pattrib->icv_len));
*((__le32 *)crc) = getcrc32(payload, 
length);/* modified by Amy*/
 
-   arcfour_init(, rc4key, 16);
-   arcfour_encrypt(, payload, 
payload, length);
-   arcfour_encrypt(, payload + 
length, crc, 4);
+   arc4_setkey(, rc4key, 16);
+   arc4_crypt(, payload, 
payload, length);
+   arc4_crypt(, payload + 
length, crc, 4);
} else {
length = pxmitpriv->frag_len - 
pattrib->hdrlen - pattrib->iv_len - pattrib->icv_len;
*((__le32 *)crc) = getcrc32(payload, 
length);/* modified by Amy*/
-   arcfour_init(, rc4key, 16);
-   arcfour_encrypt(, payload, 
payload, length);
-   arcfour_encrypt(, payload + 
length, crc, 4);
+   arc4_setkey(, rc4key, 16);
+   arc4_crypt(, payload, 
payload, length);
+   arc4_crypt(, payload + 
length, crc, 4);
 
pframe += pxmitpriv->frag_len;
pframe = (u8 
*)round_up((size_t)(pframe), 4);
@@ -644,7 +586,7 @@ u32 rtw_tkip_decrypt(struct adapter *padapter, struct 
recv_frame *precvframe)
u8   rc4key[16];
u8   ttkey[16];
u8  crc[4];
-   struct arc4context mycontext;
+   struct arc4_ctx mycontext;
int length;
u8  *pframe, *payload, *iv, *prwskey;
union pn48 dot11txpn;
@@ -685,8 +627,8 @@ u32 rtw_tkip_decrypt(struct adapter 

[PATCH 3/3] staging: rtl8712: remove (most of) enum WIFI_FRAME_TYPE

2021-04-08 Thread Christophe JAILLET
The values defined in enum WIFI_FRAME_TYPE are the same the #define
IEEE80211_FTYPE_xxx from 

Use these values to avoid code duplication.

WIFI_QOS_DATA_TYPE is a bit more tricky and doesn't have a direct
equivalence in . So leave this one as-is for now.

Signed-off-by: Christophe JAILLET 
---
 drivers/staging/rtl8712/rtl871x_recv.c | 7 ---
 drivers/staging/rtl8712/rtl871x_xmit.c | 5 ++---
 drivers/staging/rtl8712/wifi.h | 3 ---
 3 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/rtl8712/rtl871x_recv.c 
b/drivers/staging/rtl8712/rtl871x_recv.c
index c13076b0e3d1..db2add576418 100644
--- a/drivers/staging/rtl8712/rtl871x_recv.c
+++ b/drivers/staging/rtl8712/rtl871x_recv.c
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include "osdep_service.h"
@@ -565,13 +566,13 @@ sint r8712_validate_recv_frame(struct _adapter *adapter,
pattrib->privacy =  GetPrivacy(ptr);
pattrib->order = GetOrder(ptr);
switch (type) {
-   case WIFI_MGT_TYPE: /*mgnt*/
+   case IEEE80211_FTYPE_MGMT:
retval = validate_recv_mgnt_frame(adapter, precv_frame);
break;
-   case WIFI_CTRL_TYPE:/*ctrl*/
+   case IEEE80211_FTYPE_CTL:
retval = validate_recv_ctrl_frame(adapter, precv_frame);
break;
-   case WIFI_DATA_TYPE: /*data*/
+   case IEEE80211_FTYPE_DATA:
pattrib->qos = (subtype & BIT(7)) ? 1 : 0;
retval = validate_recv_data_frame(adapter, precv_frame);
break;
diff --git a/drivers/staging/rtl8712/rtl871x_xmit.c 
b/drivers/staging/rtl8712/rtl871x_xmit.c
index 15491859aeda..bb4de927fb02 100644
--- a/drivers/staging/rtl8712/rtl871x_xmit.c
+++ b/drivers/staging/rtl8712/rtl871x_xmit.c
@@ -18,7 +18,6 @@
 
 #include "osdep_service.h"
 #include "drv_types.h"
-#include "wifi.h"
 #include "osdep_intf.h"
 #include "usb_ops.h"
 
@@ -294,7 +293,7 @@ int r8712_update_attrib(struct _adapter *padapter, _pkt 
*pkt,
r8712_set_qos(, pattrib);
} else {
pattrib->hdrlen = WLAN_HDR_A3_LEN;
-   pattrib->subtype = WIFI_DATA_TYPE;
+   pattrib->subtype = IEEE80211_FTYPE_DATA;
pattrib->priority = 0;
}
if (psta->ieee8021x_blocked) {
@@ -480,7 +479,7 @@ static int make_wlanhdr(struct _adapter *padapter, u8 *hdr,
 
memset(hdr, 0, WLANHDR_OFFSET);
SetFrameSubType(fctrl, pattrib->subtype);
-   if (!(pattrib->subtype & WIFI_DATA_TYPE))
+   if (!(pattrib->subtype & IEEE80211_FTYPE_DATA))
return 0;
 
bssid = get_bssid(pmlmepriv);
diff --git a/drivers/staging/rtl8712/wifi.h b/drivers/staging/rtl8712/wifi.h
index 68c253b0f66d..577a95c62d6c 100644
--- a/drivers/staging/rtl8712/wifi.h
+++ b/drivers/staging/rtl8712/wifi.h
@@ -23,9 +23,6 @@
 #define P80211CAPTURE_VERSION  0x80211001
 
 enum WIFI_FRAME_TYPE {
-   WIFI_MGT_TYPE  =(0),
-   WIFI_CTRL_TYPE =(BIT(2)),
-   WIFI_DATA_TYPE =(BIT(3)),
WIFI_QOS_DATA_TYPE  = (BIT(7) | BIT(3)),/*!< QoS Data */
 };
 
-- 
2.27.0



[PATCH 2/3] staging: rtl8712: remove enum WIFI_FRAME_SUBTYPE

2021-04-08 Thread Christophe JAILLET
The values defined in enum WIFI_FRAME_SUBTYPE are the same the #define
IEEE80211_STYPE_xxx from 

Use theses values to avoid code duplication.

Signed-off-by: Christophe JAILLET 
---
 drivers/staging/rtl8712/rtl871x_recv.c |  2 +-
 drivers/staging/rtl8712/rtl871x_security.c | 14 +-
 drivers/staging/rtl8712/wifi.h | 32 --
 3 files changed, 8 insertions(+), 40 deletions(-)

diff --git a/drivers/staging/rtl8712/rtl871x_recv.c 
b/drivers/staging/rtl8712/rtl871x_recv.c
index f4b871637795..c13076b0e3d1 100644
--- a/drivers/staging/rtl8712/rtl871x_recv.c
+++ b/drivers/staging/rtl8712/rtl871x_recv.c
@@ -373,7 +373,7 @@ static sint ap2sta_data_frame(struct _adapter *adapter,
if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) &&
check_fwstate(pmlmepriv, _FW_LINKED)) {
/* if NULL-frame, drop packet */
-   if ((GetFrameSubType(ptr)) == WIFI_DATA_NULL)
+   if ((GetFrameSubType(ptr)) == IEEE80211_STYPE_NULLFUNC)
return _FAIL;
/* drop QoS-SubType Data, including QoS NULL,
 * excluding QoS-Data
diff --git a/drivers/staging/rtl8712/rtl871x_security.c 
b/drivers/staging/rtl8712/rtl871x_security.c
index b0cc3c922842..1c7df65db3c9 100644
--- a/drivers/staging/rtl8712/rtl871x_security.c
+++ b/drivers/staging/rtl8712/rtl871x_security.c
@@ -30,10 +30,10 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "osdep_service.h"
 #include "drv_types.h"
-#include "wifi.h"
 #include "osdep_intf.h"
 
 /* =WEP related= */
@@ -1045,9 +1045,9 @@ static void aes_cipher(u8 *key, uint hdrlen,
else
a4_exists = 1;
 
-   if ((frtype == WIFI_DATA_CFACK) ||
-(frtype == WIFI_DATA_CFPOLL) ||
-(frtype == WIFI_DATA_CFACKPOLL)) {
+   if ((frtype == IEEE80211_STYPE_DATA_CFACK) ||
+   (frtype == IEEE80211_STYPE_DATA_CFPOLL) ||
+   (frtype == IEEE80211_STYPE_DATA_CFACKPOLL)) {
qc_exists = 1;
if (hdrlen !=  WLAN_HDR_A3_QOS_LEN)
hdrlen += 2;
@@ -1225,9 +1225,9 @@ static void aes_decipher(u8 *key, uint hdrlen,
a4_exists = 0;
else
a4_exists = 1;
-   if ((frtype == WIFI_DATA_CFACK) ||
-   (frtype == WIFI_DATA_CFPOLL) ||
-   (frtype == WIFI_DATA_CFACKPOLL)) {
+   if ((frtype == IEEE80211_STYPE_DATA_CFACK) ||
+   (frtype == IEEE80211_STYPE_DATA_CFPOLL) ||
+   (frtype == IEEE80211_STYPE_DATA_CFACKPOLL)) {
qc_exists = 1;
if (hdrlen != WLAN_HDR_A3_QOS_LEN)
hdrlen += 2;
diff --git a/drivers/staging/rtl8712/wifi.h b/drivers/staging/rtl8712/wifi.h
index 61ebc730427f..68c253b0f66d 100644
--- a/drivers/staging/rtl8712/wifi.h
+++ b/drivers/staging/rtl8712/wifi.h
@@ -29,38 +29,6 @@ enum WIFI_FRAME_TYPE {
WIFI_QOS_DATA_TYPE  = (BIT(7) | BIT(3)),/*!< QoS Data */
 };
 
-enum WIFI_FRAME_SUBTYPE {
-   /* below is for mgt frame */
-   WIFI_ASSOCREQ   = (0 | WIFI_MGT_TYPE),
-   WIFI_ASSOCRSP   = (BIT(4) | WIFI_MGT_TYPE),
-   WIFI_REASSOCREQ = (BIT(5) | WIFI_MGT_TYPE),
-   WIFI_REASSOCRSP = (BIT(5) | BIT(4) | WIFI_MGT_TYPE),
-   WIFI_PROBEREQ   = (BIT(6) | WIFI_MGT_TYPE),
-   WIFI_PROBERSP   = (BIT(6) | BIT(4) | WIFI_MGT_TYPE),
-   WIFI_BEACON = (BIT(7) | WIFI_MGT_TYPE),
-   WIFI_ATIM   = (BIT(7) | BIT(4) | WIFI_MGT_TYPE),
-   WIFI_DISASSOC   = (BIT(7) | BIT(5) | WIFI_MGT_TYPE),
-   WIFI_AUTH   = (BIT(7) | BIT(5) | BIT(4) | WIFI_MGT_TYPE),
-   WIFI_DEAUTH = (BIT(7) | BIT(6) | WIFI_MGT_TYPE),
-   WIFI_ACTION = (BIT(7) | BIT(6) | BIT(4) | WIFI_MGT_TYPE),
-   /* below is for control frame */
-   WIFI_PSPOLL = (BIT(7) | BIT(5) | WIFI_CTRL_TYPE),
-   WIFI_RTS= (BIT(7) | BIT(5) | BIT(4) | WIFI_CTRL_TYPE),
-   WIFI_CTS= (BIT(7) | BIT(6) | WIFI_CTRL_TYPE),
-   WIFI_ACK= (BIT(7) | BIT(6) | BIT(4) | WIFI_CTRL_TYPE),
-   WIFI_CFEND  = (BIT(7) | BIT(6) | BIT(5) | WIFI_CTRL_TYPE),
-   WIFI_CFEND_CFACK = (BIT(7) | BIT(6) | BIT(5) | BIT(4) | WIFI_CTRL_TYPE),
-   /* below is for data frame */
-   WIFI_DATA   = (0 | WIFI_DATA_TYPE),
-   WIFI_DATA_CFACK = (BIT(4) | WIFI_DATA_TYPE),
-   WIFI_DATA_CFPOLL= (BIT(5) | WIFI_DATA_TYPE),
-   WIFI_DATA_CFACKPOLL = (BIT(5) | BIT(4) | WIFI_DATA_TYPE),
-   WIFI_DATA_NULL  = (BIT(6) | WIFI_DATA_TYPE),
-   WIFI_CF_ACK = (BIT(6) | BIT(4) | WIFI_DATA_TYPE),
-   WIFI_CF_POLL= (BIT(6) | BIT(5) | WIFI_DATA_TYPE),
-   WIFI_CF_ACKPOLL = (BIT(6) | BIT(5) | BIT(4) | WIFI_DATA_TYPE),
-};
-
 enum WIFI_REG_DOMAIN {
DOMAIN_FCC  = 1,
DOMAIN_IC   = 2,
-- 
2.27.0



[PATCH 1/3] staging: rtl8712: remove struct rtl_ieee80211_ht_cap and ieee80211_ht_addt_info

2021-04-08 Thread Christophe JAILLET
struct 'ieee80211_ht_addt_info' is unused and can be removed.

struct 'rtl_ieee80211_ht_cap' can be replaced by 'ieee80211_ht_cap'
defined in  which has the same layout.

Signed-off-by: Christophe JAILLET 
---
 drivers/staging/rtl8712/rtl871x_ht.h  |  2 +-
 drivers/staging/rtl8712/rtl871x_ioctl_linux.c |  6 ++--
 drivers/staging/rtl8712/rtl871x_mlme.c| 10 +++---
 drivers/staging/rtl8712/wifi.h| 35 ---
 4 files changed, 9 insertions(+), 44 deletions(-)

diff --git a/drivers/staging/rtl8712/rtl871x_ht.h 
b/drivers/staging/rtl8712/rtl871x_ht.h
index 4bcf5591c44d..ebd78665775d 100644
--- a/drivers/staging/rtl8712/rtl871x_ht.h
+++ b/drivers/staging/rtl8712/rtl871x_ht.h
@@ -26,7 +26,7 @@ struct ht_priv {
unsigned intrx_ampdu_maxlen; /* for rx reordering ctrl win_sz,
  * updated when join_callback.
  */
-   struct rtl_ieee80211_ht_cap ht_cap;
+   struct ieee80211_ht_cap ht_cap;
 };
 
 #endif /*_RTL871X_HT_H_ */
diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c 
b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
index 14fe12eb930c..3b6926613257 100644
--- a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
+++ b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
@@ -1389,7 +1389,7 @@ static int r8711_wx_get_rate(struct net_device *dev,
struct _adapter *padapter = netdev_priv(dev);
struct mlme_priv *pmlmepriv = >mlmepriv;
struct wlan_bssid_ex *pcur_bss = >cur_network.network;
-   struct rtl_ieee80211_ht_cap *pht_capie;
+   struct ieee80211_ht_cap *pht_capie;
unsigned char rf_type = padapter->registrypriv.rf_config;
int i;
u8 *p;
@@ -1405,8 +1405,8 @@ static int r8711_wx_get_rate(struct net_device *dev,
 pcur_bss->IELength - 12);
if (p && ht_ielen > 0) {
ht_cap = true;
-   pht_capie = (struct rtl_ieee80211_ht_cap *)(p + 2);
-   memcpy(_rate, pht_capie->supp_mcs_set, 2);
+   pht_capie = (struct ieee80211_ht_cap *)(p + 2);
+   memcpy(_rate, _capie->mcs, 2);
bw_40MHz = (le16_to_cpu(pht_capie->cap_info) &
IEEE80211_HT_CAP_SUP_WIDTH_20_40) ? 1 : 0;
short_GI = (le16_to_cpu(pht_capie->cap_info) &
diff --git a/drivers/staging/rtl8712/rtl871x_mlme.c 
b/drivers/staging/rtl8712/rtl871x_mlme.c
index b377c0b94cfb..6328da8a498e 100644
--- a/drivers/staging/rtl8712/rtl871x_mlme.c
+++ b/drivers/staging/rtl8712/rtl871x_mlme.c
@@ -1640,7 +1640,7 @@ unsigned int r8712_restructure_ht_ie(struct _adapter 
*padapter, u8 *in_ie,
 {
u32 ielen, out_len;
unsigned char *p;
-   struct rtl_ieee80211_ht_cap ht_capie;
+   struct ieee80211_ht_cap ht_capie;
unsigned char WMM_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x00, 0x01, 0x00};
struct mlme_priv *pmlmepriv = >mlmepriv;
struct qos_priv *pqospriv = >qospriv;
@@ -1656,7 +1656,7 @@ unsigned int r8712_restructure_ht_ie(struct _adapter 
*padapter, u8 *in_ie,
pqospriv->qos_option = 1;
}
out_len = *pout_len;
-   memset(_capie, 0, sizeof(struct rtl_ieee80211_ht_cap));
+   memset(_capie, 0, sizeof(struct ieee80211_ht_cap));
ht_capie.cap_info = 
cpu_to_le16(IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
IEEE80211_HT_CAP_SGI_20 |
IEEE80211_HT_CAP_SGI_40 |
@@ -1666,7 +1666,7 @@ unsigned int r8712_restructure_ht_ie(struct _adapter 
*padapter, u8 *in_ie,
ht_capie.ampdu_params_info = (IEEE80211_HT_AMPDU_PARM_FACTOR &
0x03) | (IEEE80211_HT_AMPDU_PARM_DENSITY & 
0x00);
r8712_set_ie(out_ie + out_len, WLAN_EID_HT_CAPABILITY,
-sizeof(struct rtl_ieee80211_ht_cap),
+sizeof(struct ieee80211_ht_cap),
 (unsigned char *)_capie, pout_len);
phtpriv->ht_option = 1;
}
@@ -1680,7 +1680,7 @@ static void update_ht_cap(struct _adapter *padapter, u8 
*pie, uint ie_len)
int i;
uint len;
struct sta_info *bmc_sta, *psta;
-   struct rtl_ieee80211_ht_cap *pht_capie;
+   struct ieee80211_ht_cap *pht_capie;
struct recv_reorder_ctrl *preorder_ctrl;
struct mlme_priv *pmlmepriv = >mlmepriv;
struct ht_priv *phtpriv = >htpriv;
@@ -1700,7 +1700,7 @@ static void update_ht_cap(struct _adapter *padapter, u8 
*pie, uint ie_len)
, ie_len -
sizeof(struct NDIS_802_11_FIXED_IEs));
if (p && len > 0) {
-   pht_capie = (struct rtl_ieee80211_ht_cap *)(p + 2);
+   pht_capie = (struct ieee8021

[PATCH] staging: rtl8712: Use constants from

2021-04-06 Thread Christophe JAILLET
Some constants defined in wifi.h are already defined in 
with some other (but similar) names.
Be consistent and use the ones from .

The conversions made are:
_SSID_IE_-->  WLAN_EID_SSID
_SUPPORTEDRATES_IE_  -->  WLAN_EID_SUPP_RATES
_DSSET_IE_   -->  WLAN_EID_DS_PARAMS
_IBSS_PARA_IE_   -->  WLAN_EID_IBSS_PARAMS
_ERPINFO_IE_ -->  WLAN_EID_ERP_INFO
_EXT_SUPPORTEDRATES_IE_  -->  WLAN_EID_EXT_SUPP_RATES

_HT_CAPABILITY_IE_   -->  WLAN_EID_HT_CAPABILITY
_HT_EXTRA_INFO_IE_   -->  WLAN_EID_HT_OPERATION(not used)
_HT_ADD_INFO_IE_ -->  WLAN_EID_HT_OPERATION

_VENDOR_SPECIFIC_IE_ -->  WLAN_EID_VENDOR_SPECIFIC

_RESERVED47_ --> (not used)

Signed-off-by: Christophe JAILLET 
---
 drivers/staging/rtl8712/ieee80211.c   | 12 ++--
 drivers/staging/rtl8712/rtl871x_ioctl_linux.c |  8 
 drivers/staging/rtl8712/rtl871x_mlme.c| 10 +-
 drivers/staging/rtl8712/rtl871x_xmit.c|  3 ++-
 drivers/staging/rtl8712/wifi.h| 15 ---
 5 files changed, 17 insertions(+), 31 deletions(-)

diff --git a/drivers/staging/rtl8712/ieee80211.c 
b/drivers/staging/rtl8712/ieee80211.c
index 13fc3c1ec0db..f926809b1021 100644
--- a/drivers/staging/rtl8712/ieee80211.c
+++ b/drivers/staging/rtl8712/ieee80211.c
@@ -181,25 +181,25 @@ int r8712_generate_ie(struct registry_priv *registrypriv)
sz += 2;
ie += 2;
/*SSID*/
-   ie = r8712_set_ie(ie, _SSID_IE_, dev_network->Ssid.SsidLength,
+   ie = r8712_set_ie(ie, WLAN_EID_SSID, dev_network->Ssid.SsidLength,
  dev_network->Ssid.Ssid, );
/*supported rates*/
set_supported_rate(dev_network->rates, registrypriv->wireless_mode);
rate_len = r8712_get_rateset_len(dev_network->rates);
if (rate_len > 8) {
-   ie = r8712_set_ie(ie, _SUPPORTEDRATES_IE_, 8,
+   ie = r8712_set_ie(ie, WLAN_EID_SUPP_RATES, 8,
  dev_network->rates, );
-   ie = r8712_set_ie(ie, _EXT_SUPPORTEDRATES_IE_, (rate_len - 8),
+   ie = r8712_set_ie(ie, WLAN_EID_EXT_SUPP_RATES, (rate_len - 8),
  (dev_network->rates + 8), );
} else {
-   ie = r8712_set_ie(ie, _SUPPORTEDRATES_IE_,
+   ie = r8712_set_ie(ie, WLAN_EID_SUPP_RATES,
  rate_len, dev_network->rates, );
}
/*DS parameter set*/
-   ie = r8712_set_ie(ie, _DSSET_IE_, 1,
+   ie = r8712_set_ie(ie, WLAN_EID_DS_PARAMS, 1,
  (u8 *)_network->Configuration.DSConfig, );
/*IBSS Parameter Set*/
-   ie = r8712_set_ie(ie, _IBSS_PARA_IE_, 2,
+   ie = r8712_set_ie(ie, WLAN_EID_IBSS_PARAMS, 2,
  (u8 *)_network->Configuration.ATIMWindow, );
return sz;
 }
diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c 
b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
index 60dd798a6e51..8fb02458618d 100644
--- a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
+++ b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
@@ -236,7 +236,7 @@ static char *translate_scan(struct _adapter *padapter,
start = iwe_stream_add_point(info, start, stop, ,
 pnetwork->network.Ssid.Ssid);
/* parsing HT_CAP_IE */
-   p = r8712_get_ie(>network.IEs[12], _HT_CAPABILITY_IE_,
+   p = r8712_get_ie(>network.IEs[12], WLAN_EID_HT_CAPABILITY,
 _ielen, pnetwork->network.IELength - 12);
if (p && ht_ielen > 0)
ht_cap = true;
@@ -567,7 +567,7 @@ static int r871x_set_wpa_ie(struct _adapter *padapter, char 
*pie,
while (cnt < ielen) {
eid = buf[cnt];
 
-   if ((eid == _VENDOR_SPECIFIC_IE_) &&
+   if ((eid == WLAN_EID_VENDOR_SPECIFIC) &&
(!memcmp([cnt + 2], wps_oui, 4))) {
netdev_info(padapter->pnetdev, "r8712u: 
SET WPS_IE\n");
padapter->securitypriv.wps_ie_len =
@@ -609,7 +609,7 @@ static int r8711_wx_get_name(struct net_device *dev,
if (check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE) ==
true) {
/* parsing HT_CAP_IE */
-   p = r8712_get_ie(_bss->IEs[12], _HT_CAPABILITY_IE_,
+   p = r8712_get_ie(_bss->IEs[12], WLAN_EID_HT_CAPABILITY,
 _ielen, pcur_bss->IELength - 12);
if (p && ht_ielen > 0)
ht_cap = true;
@@ -1403,7 +1403,7 @@ static int r8711_wx_get_rate(struct net_device *dev,
i = 0;
if (!check_fwstate(pmlmepriv, _F

[PATCH] rtl8xxxu: Simplify locking of a skb list accesses

2021-04-05 Thread Christophe JAILLET
The 'c2hcmd_lock' spinlock is only used to protect some __skb_queue_tail()
and __skb_dequeue() calls.
Use the lock provided in the skb itself and call skb_queue_tail() and
skb_dequeue(). These functions already include the correct locking.

Signed-off-by: Christophe JAILLET 
---
 drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h  |  1 -
 drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c | 11 ++-
 2 files changed, 2 insertions(+), 10 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h 
b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h
index d6d1be4169e5..d1a566cc0c9e 100644
--- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h
+++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h
@@ -1391,7 +1391,6 @@ struct rtl8xxxu_priv {
struct delayed_work ra_watchdog;
struct work_struct c2hcmd_work;
struct sk_buff_head c2hcmd_queue;
-   spinlock_t c2hcmd_lock;
struct rtl8xxxu_btcoex bt_coex;
struct rtl8xxxu_ra_report ra_report;
 };
diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c 
b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
index 5cd7ef3625c5..0eba42f2a66c 100644
--- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
+++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
@@ -5423,7 +5423,6 @@ static void rtl8xxxu_c2hcmd_callback(struct work_struct 
*work)
struct rtl8xxxu_priv *priv;
struct rtl8723bu_c2h *c2h;
struct sk_buff *skb = NULL;
-   unsigned long flags;
u8 bt_info = 0;
struct rtl8xxxu_btcoex *btcoex;
struct rtl8xxxu_ra_report *rarpt;
@@ -5439,9 +5438,7 @@ static void rtl8xxxu_c2hcmd_callback(struct work_struct 
*work)
goto out;
 
while (!skb_queue_empty(>c2hcmd_queue)) {
-   spin_lock_irqsave(>c2hcmd_lock, flags);
-   skb = __skb_dequeue(>c2hcmd_queue);
-   spin_unlock_irqrestore(>c2hcmd_lock, flags);
+   skb = skb_dequeue(>c2hcmd_queue);
 
c2h = (struct rtl8723bu_c2h *)skb->data;
 
@@ -5499,7 +5496,6 @@ static void rtl8723bu_handle_c2h(struct rtl8xxxu_priv 
*priv,
struct rtl8723bu_c2h *c2h = (struct rtl8723bu_c2h *)skb->data;
struct device *dev = >udev->dev;
int len;
-   unsigned long flags;
 
len = skb->len - 2;
 
@@ -5538,9 +5534,7 @@ static void rtl8723bu_handle_c2h(struct rtl8xxxu_priv 
*priv,
break;
}
 
-   spin_lock_irqsave(>c2hcmd_lock, flags);
-   __skb_queue_tail(>c2hcmd_queue, skb);
-   spin_unlock_irqrestore(>c2hcmd_lock, flags);
+   skb_queue_tail(>c2hcmd_queue, skb);
 
schedule_work(>c2hcmd_work);
 }
@@ -6606,7 +6600,6 @@ static int rtl8xxxu_probe(struct usb_interface *interface,
spin_lock_init(>rx_urb_lock);
INIT_WORK(>rx_urb_wq, rtl8xxxu_rx_urb_work);
INIT_DELAYED_WORK(>ra_watchdog, rtl8xxxu_watchdog_callback);
-   spin_lock_init(>c2hcmd_lock);
INIT_WORK(>c2hcmd_work, rtl8xxxu_c2hcmd_callback);
skb_queue_head_init(>c2hcmd_queue);
 
-- 
2.27.0



[PATCH] rtlwifi: Simplify locking of a skb list accesses

2021-04-05 Thread Christophe JAILLET
The 'c2hcmd_lock' spinlock is only used to protect some __skb_queue_tail()
and __skb_dequeue() calls.
Use the lock provided in the skb itself and call skb_queue_tail() and
skb_dequeue(). These functions already include the correct locking.

Signed-off-by: Christophe JAILLET 
---
 drivers/net/wireless/realtek/rtlwifi/base.c | 15 ++-
 drivers/net/wireless/realtek/rtlwifi/wifi.h |  1 -
 2 files changed, 2 insertions(+), 14 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/base.c 
b/drivers/net/wireless/realtek/rtlwifi/base.c
index 6e8bd99e8911..2a7ee90a3f54 100644
--- a/drivers/net/wireless/realtek/rtlwifi/base.c
+++ b/drivers/net/wireless/realtek/rtlwifi/base.c
@@ -551,7 +551,6 @@ int rtl_init_core(struct ieee80211_hw *hw)
spin_lock_init(>locks.rf_lock);
spin_lock_init(>locks.waitq_lock);
spin_lock_init(>locks.entry_list_lock);
-   spin_lock_init(>locks.c2hcmd_lock);
spin_lock_init(>locks.scan_list_lock);
spin_lock_init(>locks.cck_and_rw_pagea_lock);
spin_lock_init(>locks.fw_ps_lock);
@@ -2269,7 +2268,6 @@ static bool rtl_c2h_fast_cmd(struct ieee80211_hw *hw, 
struct sk_buff *skb)
 void rtl_c2hcmd_enqueue(struct ieee80211_hw *hw, struct sk_buff *skb)
 {
struct rtl_priv *rtlpriv = rtl_priv(hw);
-   unsigned long flags;
 
if (rtl_c2h_fast_cmd(hw, skb)) {
rtl_c2h_content_parsing(hw, skb);
@@ -2278,11 +2276,7 @@ void rtl_c2hcmd_enqueue(struct ieee80211_hw *hw, struct 
sk_buff *skb)
}
 
/* enqueue */
-   spin_lock_irqsave(>locks.c2hcmd_lock, flags);
-
-   __skb_queue_tail(>c2hcmd_queue, skb);
-
-   spin_unlock_irqrestore(>locks.c2hcmd_lock, flags);
+   skb_queue_tail(>c2hcmd_queue, skb);
 
/* wake up wq */
queue_delayed_work(rtlpriv->works.rtl_wq, >works.c2hcmd_wq, 0);
@@ -2340,16 +2334,11 @@ void rtl_c2hcmd_launcher(struct ieee80211_hw *hw, int 
exec)
 {
struct rtl_priv *rtlpriv = rtl_priv(hw);
struct sk_buff *skb;
-   unsigned long flags;
int i;
 
for (i = 0; i < 200; i++) {
/* dequeue a task */
-   spin_lock_irqsave(>locks.c2hcmd_lock, flags);
-
-   skb = __skb_dequeue(>c2hcmd_queue);
-
-   spin_unlock_irqrestore(>locks.c2hcmd_lock, flags);
+   skb = skb_dequeue(>c2hcmd_queue);
 
/* do it */
if (!skb)
diff --git a/drivers/net/wireless/realtek/rtlwifi/wifi.h 
b/drivers/net/wireless/realtek/rtlwifi/wifi.h
index 9119144bb5a3..877ed6a1589f 100644
--- a/drivers/net/wireless/realtek/rtlwifi/wifi.h
+++ b/drivers/net/wireless/realtek/rtlwifi/wifi.h
@@ -2450,7 +2450,6 @@ struct rtl_locks {
spinlock_t waitq_lock;
spinlock_t entry_list_lock;
spinlock_t usb_lock;
-   spinlock_t c2hcmd_lock;
spinlock_t scan_list_lock; /* lock for the scan list */
 
/*FW clock change */
-- 
2.27.0



[PATCH 2/2] qede: Use 'skb_add_rx_frag()' instead of hand coding it

2021-04-04 Thread Christophe JAILLET
Some lines of code can be merged into an equivalent 'skb_add_rx_frag()'
call which is less verbose.

Signed-off-by: Christophe JAILLET 
---
 drivers/net/ethernet/qlogic/qede/qede_fp.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/qlogic/qede/qede_fp.c 
b/drivers/net/ethernet/qlogic/qede/qede_fp.c
index ee3e45e38cb7..8e150dd4f899 100644
--- a/drivers/net/ethernet/qlogic/qede/qede_fp.c
+++ b/drivers/net/ethernet/qlogic/qede/qede_fp.c
@@ -1209,12 +1209,9 @@ static int qede_rx_build_jumbo(struct qede_dev *edev,
dma_unmap_page(rxq->dev, bd->mapping,
   PAGE_SIZE, DMA_FROM_DEVICE);
 
-   skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
-  bd->data, rxq->rx_headroom, cur_size);
+   skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, bd->data,
+   rxq->rx_headroom, cur_size, PAGE_SIZE);
 
-   skb->truesize += PAGE_SIZE;
-   skb->data_len += cur_size;
-   skb->len += cur_size;
pkt_len -= cur_size;
}
 
-- 
2.27.0



[PATCH 1/2] qede: Remove a erroneous ++ in 'qede_rx_build_jumbo()'

2021-04-04 Thread Christophe JAILLET
This ++ is confusing. It looks duplicated with the one already performed in
'skb_fill_page_desc()'.

In fact, it is harmless. 'nr_frags' is written twice with the same value.
Once, because of the nr_frags++, and once because of the 'nr_frags = i + 1'
in 'skb_fill_page_desc()'.

So axe this post-increment to avoid confusion.

Signed-off-by: Christophe JAILLET 
---
 drivers/net/ethernet/qlogic/qede/qede_fp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/qlogic/qede/qede_fp.c 
b/drivers/net/ethernet/qlogic/qede/qede_fp.c
index 102d0e0808d5..ee3e45e38cb7 100644
--- a/drivers/net/ethernet/qlogic/qede/qede_fp.c
+++ b/drivers/net/ethernet/qlogic/qede/qede_fp.c
@@ -1209,7 +1209,7 @@ static int qede_rx_build_jumbo(struct qede_dev *edev,
dma_unmap_page(rxq->dev, bd->mapping,
   PAGE_SIZE, DMA_FROM_DEVICE);
 
-   skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags++,
+   skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
   bd->data, rxq->rx_headroom, cur_size);
 
skb->truesize += PAGE_SIZE;
-- 
2.27.0



[PATCH] sfc: Use 'skb_add_rx_frag()' instead of hand coding it

2021-04-04 Thread Christophe JAILLET
Some lines of code can be merged into an equivalent 'skb_add_rx_frag()'
call which is less verbose.

Signed-off-by: Christophe JAILLET 
---
UNTESTED. Compile tested only

The 'skb->truesize' computation is likely to be slightly slower (n
additions hidden in 'skb_add_rx_frag' instead of 1 multiplication), but I
don't think that it is an issue here.
---
 drivers/net/ethernet/sfc/rx.c | 11 ---
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/sfc/rx.c b/drivers/net/ethernet/sfc/rx.c
index 89c5c75f479f..17b8119c48e5 100644
--- a/drivers/net/ethernet/sfc/rx.c
+++ b/drivers/net/ethernet/sfc/rx.c
@@ -94,12 +94,11 @@ static struct sk_buff *efx_rx_mk_skb(struct efx_channel 
*channel,
rx_buf->len -= hdr_len;
 
for (;;) {
-   skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
-  rx_buf->page, rx_buf->page_offset,
-  rx_buf->len);
+   skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags,
+   rx_buf->page, rx_buf->page_offset,
+   rx_buf->len, efx->rx_buffer_truesize);
rx_buf->page = NULL;
-   skb->len += rx_buf->len;
-   skb->data_len += rx_buf->len;
+
if (skb_shinfo(skb)->nr_frags == n_frags)
break;
 
@@ -111,8 +110,6 @@ static struct sk_buff *efx_rx_mk_skb(struct efx_channel 
*channel,
n_frags = 0;
}
 
-   skb->truesize += n_frags * efx->rx_buffer_truesize;
-
/* Move past the ethernet header */
skb->protocol = eth_type_trans(skb, efx->net_dev);
 
-- 
2.27.0



[PATCH] ibmvnic: Use 'skb_frag_address()' instead of hand coding it

2021-04-04 Thread Christophe JAILLET
'page_address(skb_frag_page()) + skb_frag_off()' can be replaced by an
equivalent 'skb_frag_address()' which is less verbose.

Signed-off-by: Christophe JAILLET 
---
 drivers/net/ethernet/ibm/ibmvnic.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/ibm/ibmvnic.c 
b/drivers/net/ethernet/ibm/ibmvnic.c
index 9c6438d3b3a5..473411542911 100644
--- a/drivers/net/ethernet/ibm/ibmvnic.c
+++ b/drivers/net/ethernet/ibm/ibmvnic.c
@@ -1678,9 +1678,8 @@ static netdev_tx_t ibmvnic_xmit(struct sk_buff *skb, 
struct net_device *netdev)
for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
const skb_frag_t *frag = _shinfo(skb)->frags[i];
 
-   memcpy(dst + cur,
-  page_address(skb_frag_page(frag)) +
-  skb_frag_off(frag), skb_frag_size(frag));
+   memcpy(dst + cur, skb_frag_address(frag),
+  skb_frag_size(frag));
cur += skb_frag_size(frag);
}
} else {
-- 
2.27.0



[PATCH] net: openvswitch: Use 'skb_push_rcsum()' instead of hand coding it

2021-04-04 Thread Christophe JAILLET
'skb_push()'/'skb_postpush_rcsum()' can be replaced by an equivalent
'skb_push_rcsum()' which is less verbose.

Signed-off-by: Christophe JAILLET 
---
 net/openvswitch/conntrack.c| 6 ++
 net/openvswitch/vport-netdev.c | 7 +++
 2 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/net/openvswitch/conntrack.c b/net/openvswitch/conntrack.c
index 71cec03e8612..c29b0ef1fc27 100644
--- a/net/openvswitch/conntrack.c
+++ b/net/openvswitch/conntrack.c
@@ -809,8 +809,7 @@ static int ovs_ct_nat_execute(struct sk_buff *skb, struct 
nf_conn *ct,
 
err = nf_nat_packet(ct, ctinfo, hooknum, skb);
 push:
-   skb_push(skb, nh_off);
-   skb_postpush_rcsum(skb, skb->data, nh_off);
+   skb_push_rcsum(skb, nh_off);
 
return err;
 }
@@ -1322,8 +1321,7 @@ int ovs_ct_execute(struct net *net, struct sk_buff *skb,
else
err = ovs_ct_lookup(net, key, info, skb);
 
-   skb_push(skb, nh_ofs);
-   skb_postpush_rcsum(skb, skb->data, nh_ofs);
+   skb_push_rcsum(skb, nh_ofs);
if (err)
kfree_skb(skb);
return err;
diff --git a/net/openvswitch/vport-netdev.c b/net/openvswitch/vport-netdev.c
index 57d6436e6f6a..8e1a88f13622 100644
--- a/net/openvswitch/vport-netdev.c
+++ b/net/openvswitch/vport-netdev.c
@@ -44,10 +44,9 @@ static void netdev_port_receive(struct sk_buff *skb)
if (unlikely(!skb))
return;
 
-   if (skb->dev->type == ARPHRD_ETHER) {
-   skb_push(skb, ETH_HLEN);
-   skb_postpush_rcsum(skb, skb->data, ETH_HLEN);
-   }
+   if (skb->dev->type == ARPHRD_ETHER)
+   skb_push_rcsum(skb, ETH_HLEN);
+
ovs_vport_receive(vport, skb, skb_tunnel_info(skb));
return;
 error:
-- 
2.27.0



[PATCH] net: ag71xx: Slightly simplify 'ag71xx_rx_packets()'

2021-04-04 Thread Christophe JAILLET
There is no need to use 'list_for_each_entry_safe' here, as nothing is
removed from the list in the 'for' loop.
Use 'list_for_each_entry' instead, it is slightly less verbose.

Signed-off-by: Christophe JAILLET 
---
 drivers/net/ethernet/atheros/ag71xx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/atheros/ag71xx.c 
b/drivers/net/ethernet/atheros/ag71xx.c
index a60ce9030581..7352f98123c7 100644
--- a/drivers/net/ethernet/atheros/ag71xx.c
+++ b/drivers/net/ethernet/atheros/ag71xx.c
@@ -1658,9 +1658,9 @@ static int ag71xx_rx_packets(struct ag71xx *ag, int limit)
struct net_device *ndev = ag->ndev;
int ring_mask, ring_size, done = 0;
unsigned int pktlen_mask, offset;
-   struct sk_buff *next, *skb;
struct ag71xx_ring *ring;
struct list_head rx_list;
+   struct sk_buff *skb;
 
ring = >rx_ring;
pktlen_mask = ag->dcfg->desc_pktlen_mask;
@@ -1725,7 +1725,7 @@ static int ag71xx_rx_packets(struct ag71xx *ag, int limit)
 
ag71xx_ring_rx_refill(ag);
 
-   list_for_each_entry_safe(skb, next, _list, list)
+   list_for_each_entry(skb, _list, list)
skb->protocol = eth_type_trans(skb, ndev);
netif_receive_skb_list(_list);
 
-- 
2.27.0



[PATCH] carl9170: remove get_tid_h

2021-04-02 Thread Christophe JAILLET
'get_tid_h()' is the same as 'ieee80211_get_tid()'.
So this function can be removed to save a few lines of code.

Signed-off-by: Christophe JAILLET 
---
 drivers/net/wireless/ath/carl9170/carl9170.h | 7 +--
 drivers/net/wireless/ath/carl9170/tx.c   | 2 +-
 2 files changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/net/wireless/ath/carl9170/carl9170.h 
b/drivers/net/wireless/ath/carl9170/carl9170.h
index 0d38100d6e4f..84a8ce0784b1 100644
--- a/drivers/net/wireless/ath/carl9170/carl9170.h
+++ b/drivers/net/wireless/ath/carl9170/carl9170.h
@@ -631,14 +631,9 @@ static inline u16 carl9170_get_seq(struct sk_buff *skb)
return get_seq_h(carl9170_get_hdr(skb));
 }
 
-static inline u16 get_tid_h(struct ieee80211_hdr *hdr)
-{
-   return (ieee80211_get_qos_ctl(hdr))[0] & IEEE80211_QOS_CTL_TID_MASK;
-}
-
 static inline u16 carl9170_get_tid(struct sk_buff *skb)
 {
-   return get_tid_h(carl9170_get_hdr(skb));
+   return ieee80211_get_tid(carl9170_get_hdr(skb));
 }
 
 static inline struct ieee80211_vif *
diff --git a/drivers/net/wireless/ath/carl9170/tx.c 
b/drivers/net/wireless/ath/carl9170/tx.c
index 6b8446ff48c8..88444fe6d1c6 100644
--- a/drivers/net/wireless/ath/carl9170/tx.c
+++ b/drivers/net/wireless/ath/carl9170/tx.c
@@ -394,7 +394,7 @@ static void carl9170_tx_status_process_ampdu(struct ar9170 
*ar,
if (unlikely(!sta))
goto out_rcu;
 
-   tid = get_tid_h(hdr);
+   tid = ieee80211_get_tid(hdr);
 
sta_info = (void *) sta->drv_priv;
tid_info = rcu_dereference(sta_info->agg[tid]);
-- 
2.27.0



[PATCH] rtlwifi: remove rtl_get_tid_h

2021-04-02 Thread Christophe JAILLET
'rtl_get_tid_h()' is the same as 'ieee80211_get_tid()'.
So this function can be removed to save a line of code.

Signed-off-by: Christophe JAILLET 
---
 drivers/net/wireless/realtek/rtlwifi/wifi.h | 7 +--
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/wifi.h 
b/drivers/net/wireless/realtek/rtlwifi/wifi.h
index fdccfd29fd61..9119144bb5a3 100644
--- a/drivers/net/wireless/realtek/rtlwifi/wifi.h
+++ b/drivers/net/wireless/realtek/rtlwifi/wifi.h
@@ -3086,14 +3086,9 @@ static inline __le16 rtl_get_fc(struct sk_buff *skb)
return rtl_get_hdr(skb)->frame_control;
 }
 
-static inline u16 rtl_get_tid_h(struct ieee80211_hdr *hdr)
-{
-   return (ieee80211_get_qos_ctl(hdr))[0] & IEEE80211_QOS_CTL_TID_MASK;
-}
-
 static inline u16 rtl_get_tid(struct sk_buff *skb)
 {
-   return rtl_get_tid_h(rtl_get_hdr(skb));
+   return ieee80211_get_tid(rtl_get_hdr(skb));
 }
 
 static inline struct ieee80211_sta *get_sta(struct ieee80211_hw *hw,
-- 
2.27.0



[PATCH] media: tw68: switch from 'pci_' to 'dma_' API

2021-03-28 Thread Christophe JAILLET
The wrappers in include/linux/pci-dma-compat.h should go away.

The patch has been generated with the coccinelle script below and has been
hand modified to replace GFP_ with a correct flag.
It has been compile tested.

When memory is allocated in 'tw68_risc_buffer()' (tw68-risc.c) GFP_KERNEL
can be used because this function is only called from a vb2_ops buf_prepare
function.
The call chain is:
  tw68_video_qops.buf_prepare(tw68-video.c)
--> tw68_buf_prepare   (tw68-video.c)
  --> tw68_risc_buffer

@@
@@
-PCI_DMA_BIDIRECTIONAL
+DMA_BIDIRECTIONAL

@@
@@
-PCI_DMA_TODEVICE
+DMA_TO_DEVICE

@@
@@
-PCI_DMA_FROMDEVICE
+DMA_FROM_DEVICE

@@
@@
-PCI_DMA_NONE
+DMA_NONE

@@
expression e1, e2, e3;
@@
-pci_alloc_consistent(e1, e2, e3)
+dma_alloc_coherent(>dev, e2, e3, GFP_)

@@
expression e1, e2, e3;
@@
-pci_zalloc_consistent(e1, e2, e3)
+dma_alloc_coherent(>dev, e2, e3, GFP_)

@@
expression e1, e2, e3, e4;
@@
-pci_free_consistent(e1, e2, e3, e4)
+dma_free_coherent(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_map_single(e1, e2, e3, e4)
+dma_map_single(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_unmap_single(e1, e2, e3, e4)
+dma_unmap_single(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4, e5;
@@
-pci_map_page(e1, e2, e3, e4, e5)
+dma_map_page(>dev, e2, e3, e4, e5)

@@
expression e1, e2, e3, e4;
@@
-pci_unmap_page(e1, e2, e3, e4)
+dma_unmap_page(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_map_sg(e1, e2, e3, e4)
+dma_map_sg(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_unmap_sg(e1, e2, e3, e4)
+dma_unmap_sg(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_dma_sync_single_for_cpu(e1, e2, e3, e4)
+dma_sync_single_for_cpu(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_dma_sync_single_for_device(e1, e2, e3, e4)
+dma_sync_single_for_device(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_dma_sync_sg_for_cpu(e1, e2, e3, e4)
+dma_sync_sg_for_cpu(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_dma_sync_sg_for_device(e1, e2, e3, e4)
+dma_sync_sg_for_device(>dev, e2, e3, e4)

@@
expression e1, e2;
@@
-pci_dma_mapping_error(e1, e2)
+dma_mapping_error(>dev, e2)

@@
expression e1, e2;
@@
-pci_set_dma_mask(e1, e2)
+dma_set_mask(>dev, e2)

@@
expression e1, e2;
@@
-pci_set_consistent_dma_mask(e1, e2)
+    dma_set_coherent_mask(>dev, e2)

Signed-off-by: Christophe JAILLET 
---
If needed, see post from Christoph Hellwig on the kernel-janitors ML:
   https://marc.info/?l=kernel-janitors=158745678307186=4
---
 drivers/media/pci/tw68/tw68-core.c  | 2 +-
 drivers/media/pci/tw68/tw68-risc.c  | 3 ++-
 drivers/media/pci/tw68/tw68-video.c | 2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/media/pci/tw68/tw68-core.c 
b/drivers/media/pci/tw68/tw68-core.c
index bf15fa7c0ea1..35dd19b2427e 100644
--- a/drivers/media/pci/tw68/tw68-core.c
+++ b/drivers/media/pci/tw68/tw68-core.c
@@ -248,7 +248,7 @@ static int tw68_initdev(struct pci_dev *pci_dev,
dev->name, pci_name(pci_dev), dev->pci_rev, pci_dev->irq,
dev->pci_lat, (u64)pci_resource_start(pci_dev, 0));
pci_set_master(pci_dev);
-   err = pci_set_dma_mask(pci_dev, DMA_BIT_MASK(32));
+   err = dma_set_mask(_dev->dev, DMA_BIT_MASK(32));
if (err) {
pr_info("%s: Oops: no 32bit PCI DMA ???\n", dev->name);
goto fail1;
diff --git a/drivers/media/pci/tw68/tw68-risc.c 
b/drivers/media/pci/tw68/tw68-risc.c
index eef0c5281f61..dacb136c4f3a 100644
--- a/drivers/media/pci/tw68/tw68-risc.c
+++ b/drivers/media/pci/tw68/tw68-risc.c
@@ -151,7 +151,8 @@ int tw68_risc_buffer(struct pci_dev *pci,
instructions  = fields * (1 + (((bpl + padding) * lines) /
 PAGE_SIZE) + lines) + 4;
buf->size = instructions * 8;
-   buf->cpu = pci_alloc_consistent(pci, buf->size, >dma);
+   buf->cpu = dma_alloc_coherent(>dev, buf->size, >dma,
+ GFP_KERNEL);
if (buf->cpu == NULL)
return -ENOMEM;
 
diff --git a/drivers/media/pci/tw68/tw68-video.c 
b/drivers/media/pci/tw68/tw68-video.c
index 10986fcd66a5..fe94944d0531 100644
--- a/drivers/media/pci/tw68/tw68-video.c
+++ b/drivers/media/pci/tw68/tw68-video.c
@@ -485,7 +485,7 @@ static void tw68_buf_finish(struct vb2_buffer *vb)
struct tw68_dev *dev = vb2_get_drv_priv(vq);
struct tw68_buf *buf = container_of(vbuf, struct tw68_buf, vb);
 
-   pci_free_consistent(dev->pci, buf->size, buf->cpu, buf->dma);
+   dma_free_coherent(>pci->dev, buf->size, buf->cpu, buf->dma);
 }
 
 static int tw68_start_streaming(struct vb2_queue *q, unsigned int count)
-- 
2.27.0



[PATCH] media: tw686x: switch from 'pci_' to 'dma_' API

2021-03-28 Thread Christophe JAILLET
The wrappers in include/linux/pci-dma-compat.h should go away.

The patch has been generated with the coccinelle script below and has been
hand modified to replace GFP_ with a correct flag.
It has been compile tested.

When memory is allocated in 'tw686x_audio_dma_alloc()' (tw686x-audio.c)
GFP_KERNEL can be used because it is only called from a probe function
and no spinlock is taken in the between.
The call chain is:
  tw686x_probe  (tw686x-core.c)
--> tw686x_audio_init   (tw686x-audio.c)
  --> tw686x_audio_dma_alloc
(tw686x-audio.c)

When memory is allocated in 'tw686x_memcpy_dma_alloc()' and in
'tw686x_sg_dma_alloc()' (tw686x-video.c) GFP_KERNEL can be used because
these functions are .alloc functions from a tw686x_dma_ops structure.


@@
@@
-PCI_DMA_BIDIRECTIONAL
+DMA_BIDIRECTIONAL

@@
@@
-PCI_DMA_TODEVICE
+DMA_TO_DEVICE

@@
@@
-PCI_DMA_FROMDEVICE
+DMA_FROM_DEVICE

@@
@@
-PCI_DMA_NONE
+DMA_NONE

@@
expression e1, e2, e3;
@@
-pci_alloc_consistent(e1, e2, e3)
+dma_alloc_coherent(>dev, e2, e3, GFP_)

@@
expression e1, e2, e3;
@@
-pci_zalloc_consistent(e1, e2, e3)
+dma_alloc_coherent(>dev, e2, e3, GFP_)

@@
expression e1, e2, e3, e4;
@@
-pci_free_consistent(e1, e2, e3, e4)
+dma_free_coherent(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_map_single(e1, e2, e3, e4)
+dma_map_single(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_unmap_single(e1, e2, e3, e4)
+dma_unmap_single(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4, e5;
@@
-pci_map_page(e1, e2, e3, e4, e5)
+dma_map_page(>dev, e2, e3, e4, e5)

@@
expression e1, e2, e3, e4;
@@
-pci_unmap_page(e1, e2, e3, e4)
+dma_unmap_page(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_map_sg(e1, e2, e3, e4)
+dma_map_sg(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_unmap_sg(e1, e2, e3, e4)
+dma_unmap_sg(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_dma_sync_single_for_cpu(e1, e2, e3, e4)
+dma_sync_single_for_cpu(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_dma_sync_single_for_device(e1, e2, e3, e4)
+dma_sync_single_for_device(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_dma_sync_sg_for_cpu(e1, e2, e3, e4)
+dma_sync_sg_for_cpu(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_dma_sync_sg_for_device(e1, e2, e3, e4)
+dma_sync_sg_for_device(>dev, e2, e3, e4)

@@
expression e1, e2;
@@
-pci_dma_mapping_error(e1, e2)
+dma_mapping_error(>dev, e2)

@@
expression e1, e2;
@@
-pci_set_dma_mask(e1, e2)
+dma_set_mask(>dev, e2)

@@
expression e1, e2;
@@
-pci_set_consistent_dma_mask(e1, e2)
+    dma_set_coherent_mask(>dev, e2)

Signed-off-by: Christophe JAILLET 
---
If needed, see post from Christoph Hellwig on the kernel-janitors ML:
   https://marc.info/?l=kernel-janitors=158745678307186=4
---
 drivers/media/pci/tw686x/tw686x-audio.c | 13 +++--
 drivers/media/pci/tw686x/tw686x-core.c  |  2 +-
 drivers/media/pci/tw686x/tw686x-video.c | 17 -
 3 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/drivers/media/pci/tw686x/tw686x-audio.c 
b/drivers/media/pci/tw686x/tw686x-audio.c
index 54144e23a487..74cba1368cfa 100644
--- a/drivers/media/pci/tw686x/tw686x-audio.c
+++ b/drivers/media/pci/tw686x/tw686x-audio.c
@@ -300,9 +300,9 @@ static void tw686x_audio_dma_free(struct tw686x_dev *dev,
for (pb = 0; pb < 2; pb++) {
if (!ac->dma_descs[pb].virt)
continue;
-   pci_free_consistent(dev->pci_dev, ac->dma_descs[pb].size,
-   ac->dma_descs[pb].virt,
-   ac->dma_descs[pb].phys);
+   dma_free_coherent(>pci_dev->dev, ac->dma_descs[pb].size,
+ ac->dma_descs[pb].virt,
+ ac->dma_descs[pb].phys);
ac->dma_descs[pb].virt = NULL;
}
 }
@@ -313,7 +313,7 @@ static int tw686x_audio_dma_alloc(struct tw686x_dev *dev,
int pb;
 
/*
-* In the memcpy DMA mode we allocate a consistent buffer
+* In the memcpy DMA mode we allocate a coherent buffer
 * and use it for the DMA capture. Otherwise, DMA
 * acts on the ALSA buffers as received in pcm_prepare.
 */
@@ -324,8 +324,9 @@ static int tw686x_audio_dma_alloc(struct tw686x_dev *dev,
u32 reg = pb ? ADMA_B_ADDR[ac->ch] : ADMA_P_ADDR[ac->ch];
void *virt;
 
-   virt = pci_alloc_consistent(dev->pci_dev, AUDIO_DMA_SIZE_MAX,
-   >dma_descs[pb].phys);
+   virt = dma_alloc_coherent(>pci_dev->dev,
+  

[PATCH] media: cx23885: switch from 'pci_' to 'dma_' API

2021-03-28 Thread Christophe JAILLET
The wrappers in include/linux/pci-dma-compat.h should go away.

The patch has been generated with the coccinelle script below and has been
hand modified to replace GFP_ with a correct flag.
It has been compile tested.

When memory is allocated in 'cx23885_risc_buffer()' GFP_KERNEL can be used
because this function is only called from a vb2_ops buf_prepare function.
The call chain is:
  cx23885_video_qops.buf_prepare(cx23885-video.c)
--> buffer_prepare  (cx23885-video.c)
  --> cx23885_risc_buffer

When memory is allocated in 'cx23885_risc_databuffer()' GFP_KERNEL can be
used because this function is only called from a function that already uses
GFP_KERNEL or from a vb2_ops buf_prepare
function.
The call chains are:
  snd_cx23885_hw_params (cx23885-alsa.c) --> use GFP_KERNEL
--> cx23885_risc_databuffer

  cx23885_qops.buffer_prepare   (cx23885-417.c)
 or
  dvb_qops.buffer_prepare   (cx23885-dvb.c)
--> cx23885_buf_prepare
  --> cx23885_risc_databuffer

When memory is allocated in 'cx23885_risc_vbibuffer()' GFP_KERNEL can be
used because this function is only called from a vb2_ops buf_prepare
function.
The call chains are:
  cx23885_vbi_qops.buffer_prepare   (cx23885-vbi.c)
--> cx23885_risc_vbibuffer


@@
@@
-PCI_DMA_BIDIRECTIONAL
+DMA_BIDIRECTIONAL

@@
@@
-PCI_DMA_TODEVICE
+DMA_TO_DEVICE

@@
@@
-PCI_DMA_FROMDEVICE
+DMA_FROM_DEVICE

@@
@@
-PCI_DMA_NONE
+DMA_NONE

@@
expression e1, e2, e3;
@@
-pci_alloc_consistent(e1, e2, e3)
+dma_alloc_coherent(>dev, e2, e3, GFP_)

@@
expression e1, e2, e3;
@@
-pci_zalloc_consistent(e1, e2, e3)
+dma_alloc_coherent(>dev, e2, e3, GFP_)

@@
expression e1, e2, e3, e4;
@@
-pci_free_consistent(e1, e2, e3, e4)
+dma_free_coherent(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_map_single(e1, e2, e3, e4)
+dma_map_single(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_unmap_single(e1, e2, e3, e4)
+dma_unmap_single(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4, e5;
@@
-pci_map_page(e1, e2, e3, e4, e5)
+dma_map_page(>dev, e2, e3, e4, e5)

@@
expression e1, e2, e3, e4;
@@
-pci_unmap_page(e1, e2, e3, e4)
+dma_unmap_page(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_map_sg(e1, e2, e3, e4)
+dma_map_sg(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_unmap_sg(e1, e2, e3, e4)
+dma_unmap_sg(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_dma_sync_single_for_cpu(e1, e2, e3, e4)
+dma_sync_single_for_cpu(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_dma_sync_single_for_device(e1, e2, e3, e4)
+dma_sync_single_for_device(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_dma_sync_sg_for_cpu(e1, e2, e3, e4)
+dma_sync_sg_for_cpu(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_dma_sync_sg_for_device(e1, e2, e3, e4)
+dma_sync_sg_for_device(>dev, e2, e3, e4)

@@
expression e1, e2;
@@
-pci_dma_mapping_error(e1, e2)
+dma_mapping_error(>dev, e2)

@@
expression e1, e2;
@@
-pci_set_dma_mask(e1, e2)
+dma_set_mask(>dev, e2)

@@
expression e1, e2;
@@
-pci_set_consistent_dma_mask(e1, e2)
+dma_set_coherent_mask(>dev, e2)

Signed-off-by: Christophe JAILLET 
---
If needed, see post from Christoph Hellwig on the kernel-janitors ML:
   https://marc.info/?l=kernel-janitors=158745678307186=4
---
 drivers/media/pci/cx23885/cx23885-alsa.c |  2 +-
 drivers/media/pci/cx23885/cx23885-core.c | 13 -
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/media/pci/cx23885/cx23885-alsa.c 
b/drivers/media/pci/cx23885/cx23885-alsa.c
index 13689c5dd47f..ab14d35214aa 100644
--- a/drivers/media/pci/cx23885/cx23885-alsa.c
+++ b/drivers/media/pci/cx23885/cx23885-alsa.c
@@ -266,7 +266,7 @@ static int dsp_buffer_free(struct cx23885_audio_dev *chip)
cx23885_alsa_dma_unmap(chip);
cx23885_alsa_dma_free(chip->buf);
risc = >buf->risc;
-   pci_free_consistent(chip->pci, risc->size, risc->cpu, risc->dma);
+   dma_free_coherent(>pci->dev, risc->size, risc->cpu, risc->dma);
kfree(chip->buf);
 
chip->buf = NULL;
diff --git a/drivers/media/pci/cx23885/cx23885-core.c 
b/drivers/media/pci/cx23885/cx23885-core.c
index d0ca260ecf70..f8f2ff3b00c3 100644
--- a/drivers/media/pci/cx23885/cx23885-core.c
+++ b/drivers/media/pci/cx23885/cx23885-core.c
@@ -1218,7 +1218,8 @@ int cx23885_risc_buffer(struct pci_dev *pci, struct 
cx23885_riscmem *risc,
/ PAGE_SIZE + lines);
instructions += 5;
risc->size = instructions * 12;
-   risc->cpu = pci_alloc_consistent(pci, risc->size, >dma);
+   risc->cpu = dma_alloc_coherent(>dev, risc->size, >dma,
+  GFP_KERNEL);

[PATCH v3 2/2] usb: gadget: s3c: Fix the error handling path in 's3c2410_udc_probe()'

2021-03-27 Thread Christophe JAILLET
Some 'clk_prepare_enable()' and 'clk_get()' must be undone in the error
handling path of the probe function, as already done in the remove
function.

Fixes: 3fc154b6b813 ("USB Gadget driver for Samsung s3c2410 ARM SoC")
Signed-off-by: Christophe JAILLET 
Reviewed-by: Krzysztof Kozlowski 
---
v2: Fix a stupid error in the hash in Fixes:
v3: Add Reviewed-by:
---
 drivers/usb/gadget/udc/s3c2410_udc.c | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/gadget/udc/s3c2410_udc.c 
b/drivers/usb/gadget/udc/s3c2410_udc.c
index b81979b3bdb6..b154b62abefa 100644
--- a/drivers/usb/gadget/udc/s3c2410_udc.c
+++ b/drivers/usb/gadget/udc/s3c2410_udc.c
@@ -1750,7 +1750,8 @@ static int s3c2410_udc_probe(struct platform_device *pdev)
udc_clock = clk_get(NULL, "usb-device");
if (IS_ERR(udc_clock)) {
dev_err(dev, "failed to get udc clock source\n");
-   return PTR_ERR(udc_clock);
+   retval = PTR_ERR(udc_clock);
+   goto err_usb_bus_clk;
}
 
clk_prepare_enable(udc_clock);
@@ -1773,7 +1774,7 @@ static int s3c2410_udc_probe(struct platform_device *pdev)
base_addr = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(base_addr)) {
retval = PTR_ERR(base_addr);
-   goto err;
+   goto err_udc_clk;
}
 
the_controller = udc;
@@ -1791,7 +1792,7 @@ static int s3c2410_udc_probe(struct platform_device *pdev)
if (retval != 0) {
dev_err(dev, "cannot get irq %i, err %d\n", irq_usbd, retval);
retval = -EBUSY;
-   goto err;
+   goto err_udc_clk;
}
 
dev_dbg(dev, "got irq %i\n", irq_usbd);
@@ -1862,7 +1863,14 @@ static int s3c2410_udc_probe(struct platform_device 
*pdev)
gpio_free(udc_info->vbus_pin);
 err_int:
free_irq(irq_usbd, udc);
-err:
+err_udc_clk:
+   clk_disable_unprepare(udc_clock);
+   clk_put(udc_clock);
+   udc_clock = NULL;
+err_usb_bus_clk:
+   clk_disable_unprepare(usb_bus_clock);
+   clk_put(usb_bus_clock);
+   usb_bus_clock = NULL;
 
return retval;
 }
-- 
2.27.0



[PATCH v3 1/2] usb: gadget: s3c: Fix incorrect resources releasing

2021-03-27 Thread Christophe JAILLET
Since commit 188db4435ac6 ("usb: gadget: s3c: use platform resources"),
'request_mem_region()' and 'ioremap()' are no more used, so they don't need
to be undone in the error handling path of the probe and in the remove
function.

Remove these calls and the unneeded 'rsrc_start' and 'rsrc_len' global
variables.

Fixes: 188db4435ac6 ("usb: gadget: s3c: use platform resources")
Signed-off-by: Christophe JAILLET 
Reviewed-by: Krzysztof Kozlowski 
---
the 'err' label is used only to reduce the diff size of this patch. It is
removed in the following patch.

v2: Fix a stupid error in the hash in Fixes:
v3: s/removre/remove/
Add Reviewed-by:
---
 drivers/usb/gadget/udc/s3c2410_udc.c | 14 +++---
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/drivers/usb/gadget/udc/s3c2410_udc.c 
b/drivers/usb/gadget/udc/s3c2410_udc.c
index 1d3ebb07ccd4..b81979b3bdb6 100644
--- a/drivers/usb/gadget/udc/s3c2410_udc.c
+++ b/drivers/usb/gadget/udc/s3c2410_udc.c
@@ -54,8 +54,6 @@ static struct clk *udc_clock;
 static struct clk  *usb_bus_clock;
 static void __iomem*base_addr;
 static int irq_usbd;
-static u64 rsrc_start;
-static u64 rsrc_len;
 static struct dentry   *s3c2410_udc_debugfs_root;
 
 static inline u32 udc_read(u32 reg)
@@ -1775,7 +1773,7 @@ static int s3c2410_udc_probe(struct platform_device *pdev)
base_addr = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(base_addr)) {
retval = PTR_ERR(base_addr);
-   goto err_mem;
+   goto err;
}
 
the_controller = udc;
@@ -1793,7 +1791,7 @@ static int s3c2410_udc_probe(struct platform_device *pdev)
if (retval != 0) {
dev_err(dev, "cannot get irq %i, err %d\n", irq_usbd, retval);
retval = -EBUSY;
-   goto err_map;
+   goto err;
}
 
dev_dbg(dev, "got irq %i\n", irq_usbd);
@@ -1864,10 +1862,7 @@ static int s3c2410_udc_probe(struct platform_device 
*pdev)
gpio_free(udc_info->vbus_pin);
 err_int:
free_irq(irq_usbd, udc);
-err_map:
-   iounmap(base_addr);
-err_mem:
-   release_mem_region(rsrc_start, rsrc_len);
+err:
 
return retval;
 }
@@ -1899,9 +1894,6 @@ static int s3c2410_udc_remove(struct platform_device 
*pdev)
 
free_irq(irq_usbd, udc);
 
-   iounmap(base_addr);
-   release_mem_region(rsrc_start, rsrc_len);
-
if (!IS_ERR(udc_clock) && udc_clock != NULL) {
clk_disable_unprepare(udc_clock);
clk_put(udc_clock);
-- 
2.27.0



[PATCH] media: cx25821: switch from 'pci_' to 'dma_' API

2021-03-21 Thread Christophe JAILLET
The wrappers in include/linux/pci-dma-compat.h should go away.

The patch has been generated with the coccinelle script below and has been
hand modified to replace GFP_ with a correct flag.
It has been compile tested.

When memory is allocated in 'cx25821_riscmem_alloc()' GFP_KERNEL can be
used because either this flag is already used in the call chain, or it is
called from a 'buf_prepare' function.

The call chains are:
  vb2_ops.buf_prepare  (in cx25821-video.c)
cx25821_buffer_prepare (in cx25821-video.c)
  cx25821_risc_buffer
cx25821_riscmem_alloc

  snd_cx25821_hw_params(in cx25821-alsa.c) <-- use GFP_KERNEL
cx25821_risc_databuffer_audio
  cx25821_riscmem_alloc


@@
@@
-PCI_DMA_BIDIRECTIONAL
+DMA_BIDIRECTIONAL

@@
@@
-PCI_DMA_TODEVICE
+DMA_TO_DEVICE

@@
@@
-PCI_DMA_FROMDEVICE
+DMA_FROM_DEVICE

@@
@@
-PCI_DMA_NONE
+DMA_NONE

@@
expression e1, e2, e3;
@@
-pci_alloc_consistent(e1, e2, e3)
+dma_alloc_coherent(>dev, e2, e3, GFP_)

@@
expression e1, e2, e3;
@@
-pci_zalloc_consistent(e1, e2, e3)
+dma_alloc_coherent(>dev, e2, e3, GFP_)

@@
expression e1, e2, e3, e4;
@@
-pci_free_consistent(e1, e2, e3, e4)
+dma_free_coherent(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_map_single(e1, e2, e3, e4)
+dma_map_single(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_unmap_single(e1, e2, e3, e4)
+dma_unmap_single(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4, e5;
@@
-pci_map_page(e1, e2, e3, e4, e5)
+dma_map_page(>dev, e2, e3, e4, e5)

@@
expression e1, e2, e3, e4;
@@
-pci_unmap_page(e1, e2, e3, e4)
+dma_unmap_page(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_map_sg(e1, e2, e3, e4)
+dma_map_sg(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_unmap_sg(e1, e2, e3, e4)
+dma_unmap_sg(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_dma_sync_single_for_cpu(e1, e2, e3, e4)
+dma_sync_single_for_cpu(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_dma_sync_single_for_device(e1, e2, e3, e4)
+dma_sync_single_for_device(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_dma_sync_sg_for_cpu(e1, e2, e3, e4)
+dma_sync_sg_for_cpu(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_dma_sync_sg_for_device(e1, e2, e3, e4)
+dma_sync_sg_for_device(>dev, e2, e3, e4)

@@
expression e1, e2;
@@
-pci_dma_mapping_error(e1, e2)
+dma_mapping_error(>dev, e2)

@@
expression e1, e2;
@@
-pci_set_dma_mask(e1, e2)
+dma_set_mask(>dev, e2)

@@
expression e1, e2;
@@
-pci_set_consistent_dma_mask(e1, e2)
+dma_set_coherent_mask(>dev, e2)

Signed-off-by: Christophe JAILLET 
---
If needed, see post from Christoph Hellwig on the kernel-janitors ML:
   https://marc.info/?l=kernel-janitors=158745678307186=4
---
 drivers/media/pci/cx25821/cx25821-alsa.c |  2 +-
 drivers/media/pci/cx25821/cx25821-core.c | 10 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/media/pci/cx25821/cx25821-alsa.c 
b/drivers/media/pci/cx25821/cx25821-alsa.c
index 8797d85a6b0a..438fdcec6eac 100644
--- a/drivers/media/pci/cx25821/cx25821-alsa.c
+++ b/drivers/media/pci/cx25821/cx25821-alsa.c
@@ -402,7 +402,7 @@ static int dsp_buffer_free(struct cx25821_audio_dev *chip)
dprintk(2, "Freeing buffer\n");
cx25821_alsa_dma_unmap(chip);
cx25821_alsa_dma_free(chip->buf);
-   pci_free_consistent(chip->pci, risc->size, risc->cpu, risc->dma);
+   dma_free_coherent(>pci->dev, risc->size, risc->cpu, risc->dma);
kfree(chip->buf);
 
chip->buf = NULL;
diff --git a/drivers/media/pci/cx25821/cx25821-core.c 
b/drivers/media/pci/cx25821/cx25821-core.c
index 07b6d0c49bbf..40c10ca94def 100644
--- a/drivers/media/pci/cx25821/cx25821-core.c
+++ b/drivers/media/pci/cx25821/cx25821-core.c
@@ -977,11 +977,11 @@ int cx25821_riscmem_alloc(struct pci_dev *pci,
dma_addr_t dma = 0;
 
if (risc->cpu && risc->size < size) {
-   pci_free_consistent(pci, risc->size, risc->cpu, risc->dma);
+   dma_free_coherent(>dev, risc->size, risc->cpu, risc->dma);
risc->cpu = NULL;
}
if (NULL == risc->cpu) {
-   cpu = pci_zalloc_consistent(pci, size, );
+   cpu = dma_alloc_coherent(>dev, size, , GFP_KERNEL);
if (NULL == cpu)
return -ENOMEM;
risc->cpu  = cpu;
@@ -1202,8 +1202,8 @@ void cx25821_free_buffer(struct cx25821_dev *dev, struct 
cx25821_buffer *buf)
 {
if (WARN_ON(buf->risc.size == 0))
return;
-   pci_free_consistent(dev->pci,
-   buf->risc.size, buf->risc.cpu, buf->risc.dma);
+   dma_free_coherent(>

Re: [PATCH 2/2 v2] usb: gadget: s3c: Fix the error handling path in 's3c2410_udc_probe()'

2021-03-06 Thread Christophe JAILLET

Le 06/03/2021 à 17:16, Krzysztof Kozlowski a écrit :

On 06/03/2021 15:21, Christophe JAILLET wrote:

Some 'clk_prepare_enable()' and 'clk_get()' must be undone in the error
handling path of the probe function, as already done in the remove
function.

Fixes: 3fc154b6b813 ("USB Gadget driver for Samsung s3c2410 ARM SoC")
Signed-off-by: Christophe JAILLET 
---
v2: Fix a stupid error in the hash in Fixes:
---
  drivers/usb/gadget/udc/s3c2410_udc.c | 16 
  1 file changed, 12 insertions(+), 4 deletions(-)



Do not ignore received tags but add them before sending a new version of patch.
https://lore.kernel.org/linux-samsung-soc/36ef897b-aedc-fcc3-89c8-c602d9733...@canonical.com/T/#t

Also somehow your 2nd patch is not in-reply to first one. Don't change
the settings of sending patches. git format-patch and
git send-email default settings are correct. Look here:
https://lore.kernel.org/linux-samsung-soc/
Only your patches are not threaded.

Best regards,
Krzysztof


Hi,

sorry for missing the typo in the first patch.

For your other comments above, however, I use standard settings only.
My patches are generated by commands like:
   git format-patch -2

I use cover letter only if it looks useful. In such a case, I use:
   git format-patch --thread --cover-letter -2

I've never seen that threading series was the rule and/or that cover 
letters were a must have. If I'm wrong, sorry, I was not aware of that.


I'll also add the "Reviewed-by:" tag.


Thx for the review and explanations.

CJ


[PATCH 2/2 v2] usb: gadget: s3c: Fix the error handling path in 's3c2410_udc_probe()'

2021-03-06 Thread Christophe JAILLET
Some 'clk_prepare_enable()' and 'clk_get()' must be undone in the error
handling path of the probe function, as already done in the remove
function.

Fixes: 3fc154b6b813 ("USB Gadget driver for Samsung s3c2410 ARM SoC")
Signed-off-by: Christophe JAILLET 
---
v2: Fix a stupid error in the hash in Fixes:
---
 drivers/usb/gadget/udc/s3c2410_udc.c | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/gadget/udc/s3c2410_udc.c 
b/drivers/usb/gadget/udc/s3c2410_udc.c
index 3fc436286bad..146250e93412 100644
--- a/drivers/usb/gadget/udc/s3c2410_udc.c
+++ b/drivers/usb/gadget/udc/s3c2410_udc.c
@@ -1750,7 +1750,8 @@ static int s3c2410_udc_probe(struct platform_device *pdev)
udc_clock = clk_get(NULL, "usb-device");
if (IS_ERR(udc_clock)) {
dev_err(dev, "failed to get udc clock source\n");
-   return PTR_ERR(udc_clock);
+   retval = PTR_ERR(udc_clock);
+   goto err_usb_bus_clk;
}
 
clk_prepare_enable(udc_clock);
@@ -1773,7 +1774,7 @@ static int s3c2410_udc_probe(struct platform_device *pdev)
base_addr = devm_platform_ioremap_resource(pdev, 0);
if (!base_addr) {
retval = -ENOMEM;
-   goto err;
+   goto err_udc_clk;
}
 
the_controller = udc;
@@ -1791,7 +1792,7 @@ static int s3c2410_udc_probe(struct platform_device *pdev)
if (retval != 0) {
dev_err(dev, "cannot get irq %i, err %d\n", irq_usbd, retval);
retval = -EBUSY;
-   goto err;
+   goto err_udc_clk;
}
 
dev_dbg(dev, "got irq %i\n", irq_usbd);
@@ -1862,7 +1863,14 @@ static int s3c2410_udc_probe(struct platform_device 
*pdev)
gpio_free(udc_info->vbus_pin);
 err_int:
free_irq(irq_usbd, udc);
-err:
+err_udc_clk:
+   clk_disable_unprepare(udc_clock);
+   clk_put(udc_clock);
+   udc_clock = NULL;
+err_usb_bus_clk:
+   clk_disable_unprepare(usb_bus_clock);
+   clk_put(usb_bus_clock);
+   usb_bus_clock = NULL;
 
return retval;
 }
-- 
2.27.0



[PATCH 1/2 V2] usb: gadget: s3c: Fix incorrect resources releasing

2021-03-06 Thread Christophe JAILLET
Since commit 188db4435ac6 ("usb: gadget: s3c: use platform resources"),
'request_mem_region()' and 'ioremap()' are no more used, so they don't need
to be undone in the error handling path of the probe and in the removre
function.

Remove these calls and the unneeded 'rsrc_start' and 'rsrc_len' global
variables.

Fixes: 188db4435ac6 ("usb: gadget: s3c: use platform resources")
Signed-off-by: Christophe JAILLET 
---
the 'err' label is used only to reduce the diff size of this patch. It is
removed in the following patch.

v2: Fix a stupid error in the hash in Fixes:
---
 drivers/usb/gadget/udc/s3c2410_udc.c | 14 +++---
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/drivers/usb/gadget/udc/s3c2410_udc.c 
b/drivers/usb/gadget/udc/s3c2410_udc.c
index f1ea51476add..3fc436286bad 100644
--- a/drivers/usb/gadget/udc/s3c2410_udc.c
+++ b/drivers/usb/gadget/udc/s3c2410_udc.c
@@ -54,8 +54,6 @@ static struct clk *udc_clock;
 static struct clk  *usb_bus_clock;
 static void __iomem*base_addr;
 static int irq_usbd;
-static u64 rsrc_start;
-static u64 rsrc_len;
 static struct dentry   *s3c2410_udc_debugfs_root;
 
 static inline u32 udc_read(u32 reg)
@@ -1775,7 +1773,7 @@ static int s3c2410_udc_probe(struct platform_device *pdev)
base_addr = devm_platform_ioremap_resource(pdev, 0);
if (!base_addr) {
retval = -ENOMEM;
-   goto err_mem;
+   goto err;
}
 
the_controller = udc;
@@ -1793,7 +1791,7 @@ static int s3c2410_udc_probe(struct platform_device *pdev)
if (retval != 0) {
dev_err(dev, "cannot get irq %i, err %d\n", irq_usbd, retval);
retval = -EBUSY;
-   goto err_map;
+   goto err;
}
 
dev_dbg(dev, "got irq %i\n", irq_usbd);
@@ -1864,10 +1862,7 @@ static int s3c2410_udc_probe(struct platform_device 
*pdev)
gpio_free(udc_info->vbus_pin);
 err_int:
free_irq(irq_usbd, udc);
-err_map:
-   iounmap(base_addr);
-err_mem:
-   release_mem_region(rsrc_start, rsrc_len);
+err:
 
return retval;
 }
@@ -1899,9 +1894,6 @@ static int s3c2410_udc_remove(struct platform_device 
*pdev)
 
free_irq(irq_usbd, udc);
 
-   iounmap(base_addr);
-   release_mem_region(rsrc_start, rsrc_len);
-
if (!IS_ERR(udc_clock) && udc_clock != NULL) {
clk_disable_unprepare(udc_clock);
clk_put(udc_clock);
-- 
2.27.0



Re: [PATCH 1/2] usb: gadget: s3c: Fix incorrect resources releasing

2021-02-23 Thread Christophe JAILLET

Le 22/02/2021 à 07:03, Dan Carpenter a écrit :

On Sun, Feb 21, 2021 at 08:41:17AM +0100, Christophe JAILLET wrote:

Since commit fe0f8e5c9ba8 ("usb: gadget: s3c: use platform resources"),


This the wrong hash.  It should be 188db4435ac6 from the URL you posted
below.

regards,
dan carpenter



Ouch!

Thx for spotting this so stupid and so trivial little error!
I'll send a v2 when -rc1 is out.

CJ


[PATCH 2/2] usb: gadget: s3c: Fix the error handling path in 's3c2410_udc_probe()'

2021-02-20 Thread Christophe JAILLET
Some 'clk_prepare_enable()' and 'clk_get()' must be undone in the error
handling path of the probe function, as already done in the remove
function.

Fixes: 1c6d47aa4f4b ("USB Gadget driver for Samsung s3c2410 ARM SoC")
Signed-off-by: Christophe JAILLET 
---
checkpatch reports:
WARNING: Unknown commit id '1c6d47aa4f4b', maybe rebased or not pulled?
According to 
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/drivers/usb/gadget/s3c2410_udc.c?id=3fc154b6b8134b98bb94d60cad9a46ec1ffbe372
the commit ID looks correct to me. Maybe something should be tweaked somewhere
before applying, but I don't know what!
---
 drivers/usb/gadget/udc/s3c2410_udc.c | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/gadget/udc/s3c2410_udc.c 
b/drivers/usb/gadget/udc/s3c2410_udc.c
index 3fc436286bad..146250e93412 100644
--- a/drivers/usb/gadget/udc/s3c2410_udc.c
+++ b/drivers/usb/gadget/udc/s3c2410_udc.c
@@ -1750,7 +1750,8 @@ static int s3c2410_udc_probe(struct platform_device *pdev)
udc_clock = clk_get(NULL, "usb-device");
if (IS_ERR(udc_clock)) {
dev_err(dev, "failed to get udc clock source\n");
-   return PTR_ERR(udc_clock);
+   retval = PTR_ERR(udc_clock);
+   goto err_usb_bus_clk;
}
 
clk_prepare_enable(udc_clock);
@@ -1773,7 +1774,7 @@ static int s3c2410_udc_probe(struct platform_device *pdev)
base_addr = devm_platform_ioremap_resource(pdev, 0);
if (!base_addr) {
retval = -ENOMEM;
-   goto err;
+   goto err_udc_clk;
}
 
the_controller = udc;
@@ -1791,7 +1792,7 @@ static int s3c2410_udc_probe(struct platform_device *pdev)
if (retval != 0) {
dev_err(dev, "cannot get irq %i, err %d\n", irq_usbd, retval);
retval = -EBUSY;
-   goto err;
+   goto err_udc_clk;
}
 
dev_dbg(dev, "got irq %i\n", irq_usbd);
@@ -1862,7 +1863,14 @@ static int s3c2410_udc_probe(struct platform_device 
*pdev)
gpio_free(udc_info->vbus_pin);
 err_int:
free_irq(irq_usbd, udc);
-err:
+err_udc_clk:
+   clk_disable_unprepare(udc_clock);
+   clk_put(udc_clock);
+   udc_clock = NULL;
+err_usb_bus_clk:
+   clk_disable_unprepare(usb_bus_clock);
+   clk_put(usb_bus_clock);
+   usb_bus_clock = NULL;
 
return retval;
 }
-- 
2.27.0



[PATCH 1/2] usb: gadget: s3c: Fix incorrect resources releasing

2021-02-20 Thread Christophe JAILLET
Since commit fe0f8e5c9ba8 ("usb: gadget: s3c: use platform resources"),
'request_mem_region()' and 'ioremap()' are no more used, so they don't need
to be undone in the error handling path of the probe and in the removre
function.

Remove these calls and the unneeded 'rsrc_start' and 'rsrc_len' global
variables.

Fixes: fe0f8e5c9ba8 ("usb: gadget: s3c: use platform resources")
Signed-off-by: Christophe JAILLET 
---
the 'err' label is used only to reduce the diff size of this patch. It is
removed in the following patch.

checkpatch reports:
WARNING: Unknown commit id 'fe0f8e5c9ba8', maybe rebased or not pulled?
According to 
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/drivers/usb/gadget/udc/s3c2410_udc.c?id=188db4435ac64f0918def7ba0593d408700ecc4b
the commit ID looks correct to me. Maybe something should be tweaked somewhere
before applying, but I don't know what!
---
 drivers/usb/gadget/udc/s3c2410_udc.c | 14 +++---
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/drivers/usb/gadget/udc/s3c2410_udc.c 
b/drivers/usb/gadget/udc/s3c2410_udc.c
index f1ea51476add..3fc436286bad 100644
--- a/drivers/usb/gadget/udc/s3c2410_udc.c
+++ b/drivers/usb/gadget/udc/s3c2410_udc.c
@@ -54,8 +54,6 @@ static struct clk *udc_clock;
 static struct clk  *usb_bus_clock;
 static void __iomem*base_addr;
 static int irq_usbd;
-static u64 rsrc_start;
-static u64 rsrc_len;
 static struct dentry   *s3c2410_udc_debugfs_root;
 
 static inline u32 udc_read(u32 reg)
@@ -1775,7 +1773,7 @@ static int s3c2410_udc_probe(struct platform_device *pdev)
base_addr = devm_platform_ioremap_resource(pdev, 0);
if (!base_addr) {
retval = -ENOMEM;
-   goto err_mem;
+   goto err;
}
 
the_controller = udc;
@@ -1793,7 +1791,7 @@ static int s3c2410_udc_probe(struct platform_device *pdev)
if (retval != 0) {
dev_err(dev, "cannot get irq %i, err %d\n", irq_usbd, retval);
retval = -EBUSY;
-   goto err_map;
+   goto err;
}
 
dev_dbg(dev, "got irq %i\n", irq_usbd);
@@ -1864,10 +1862,7 @@ static int s3c2410_udc_probe(struct platform_device 
*pdev)
gpio_free(udc_info->vbus_pin);
 err_int:
free_irq(irq_usbd, udc);
-err_map:
-   iounmap(base_addr);
-err_mem:
-   release_mem_region(rsrc_start, rsrc_len);
+err:
 
return retval;
 }
@@ -1899,9 +1894,6 @@ static int s3c2410_udc_remove(struct platform_device 
*pdev)
 
free_irq(irq_usbd, udc);
 
-   iounmap(base_addr);
-   release_mem_region(rsrc_start, rsrc_len);
-
if (!IS_ERR(udc_clock) && udc_clock != NULL) {
clk_disable_unprepare(udc_clock);
clk_put(udc_clock);
-- 
2.27.0



[PATCH 2/2] mmc: uniphier-sd: Fix a resource leak in the remove function

2021-02-20 Thread Christophe JAILLET
A 'tmio_mmc_host_free()' call is missing in the remove function, in order
to balance a 'tmio_mmc_host_alloc()' call in the probe.
This is done in the error handling path of the probe, but not in the remove
function.

Add the missing call.

Fixes: 3fd784f745dd ("mmc: uniphier-sd: add UniPhier SD/eMMC controller driver")
Signed-off-by: Christophe JAILLET 
---
 drivers/mmc/host/uniphier-sd.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/mmc/host/uniphier-sd.c b/drivers/mmc/host/uniphier-sd.c
index 6f0f05466917..ccbf9885a52b 100644
--- a/drivers/mmc/host/uniphier-sd.c
+++ b/drivers/mmc/host/uniphier-sd.c
@@ -660,6 +660,7 @@ static int uniphier_sd_remove(struct platform_device *pdev)
 
tmio_mmc_host_remove(host);
uniphier_sd_clk_disable(host);
+   tmio_mmc_host_free(host);
 
return 0;
 }
-- 
2.27.0



[PATCH 1/2] mmc: uniphier-sd: Fix an error handling path in uniphier_sd_probe()

2021-02-20 Thread Christophe JAILLET
A 'uniphier_sd_clk_enable()' call should be balanced by a corresponding
'uniphier_sd_clk_disable()' call.
This is done in the remove function, but not in the error handling path of
the probe.

Add the missing call.

Fixes: 3fd784f745dd ("mmc: uniphier-sd: add UniPhier SD/eMMC controller driver")
Signed-off-by: Christophe JAILLET 
---
 drivers/mmc/host/uniphier-sd.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/host/uniphier-sd.c b/drivers/mmc/host/uniphier-sd.c
index 2413b6750cec..6f0f05466917 100644
--- a/drivers/mmc/host/uniphier-sd.c
+++ b/drivers/mmc/host/uniphier-sd.c
@@ -635,7 +635,7 @@ static int uniphier_sd_probe(struct platform_device *pdev)
 
ret = tmio_mmc_host_probe(host);
if (ret)
-   goto free_host;
+   goto disable_clk;
 
ret = devm_request_irq(dev, irq, tmio_mmc_irq, IRQF_SHARED,
   dev_name(dev), host);
@@ -646,6 +646,8 @@ static int uniphier_sd_probe(struct platform_device *pdev)
 
 remove_host:
tmio_mmc_host_remove(host);
+disable_clk:
+   uniphier_sd_clk_disable(host);
 free_host:
tmio_mmc_host_free(host);
 
-- 
2.27.0



[PATCH] scsi: mpt3sas: Do not use GFP_KERNEL in atomic context

2021-02-20 Thread Christophe JAILLET
'mpt3sas_get_port_by_id()' can be called when a spinlock is hold. So use
GFP_ATOMIC instead of GFP_KERNEL when allocating memory.

Issue spotted by call_kern.cocci:
./drivers/scsi/mpt3sas/mpt3sas_scsih.c:416:42-52: ERROR: function 
mpt3sas_get_port_by_id called on line 7125 inside lock on line 7123 but uses 
GFP_KERNEL
./drivers/scsi/mpt3sas/mpt3sas_scsih.c:416:42-52: ERROR: function 
mpt3sas_get_port_by_id called on line 6842 inside lock on line 6839 but uses 
GFP_KERNEL
./drivers/scsi/mpt3sas/mpt3sas_scsih.c:416:42-52: ERROR: function 
mpt3sas_get_port_by_id called on line 6854 inside lock on line 6851 but uses 
GFP_KERNEL
./drivers/scsi/mpt3sas/mpt3sas_scsih.c:416:42-52: ERROR: function 
mpt3sas_get_port_by_id called on line 7706 inside lock on line 7702 but uses 
GFP_KERNEL
./drivers/scsi/mpt3sas/mpt3sas_scsih.c:416:42-52: ERROR: function 
mpt3sas_get_port_by_id called on line 10260 inside lock on line 10256 but uses 
GFP_KERNEL

Fixes: 324c122fc0a4 ("scsi: mpt3sas: Add module parameter multipath_on_hba")
Signed-off-by: Christophe JAILLET 
---
 drivers/scsi/mpt3sas/mpt3sas_scsih.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c 
b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index ffca03064797..6aa6de729187 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -413,7 +413,7 @@ mpt3sas_get_port_by_id(struct MPT3SAS_ADAPTER *ioc,
 * And add this object to port_table_list.
 */
if (!ioc->multipath_on_hba) {
-   port = kzalloc(sizeof(struct hba_port), GFP_KERNEL);
+   port = kzalloc(sizeof(struct hba_port), GFP_ATOMIC);
if (!port)
return NULL;
 
-- 
2.27.0



Re: [PATCH] scsi: pm80xx: switch from 'pci_' to 'dma_' API

2021-02-20 Thread Christophe JAILLET

Please ignore.

This one has already been applied, I'va attached the wrong patch.
Sorry for the noise.

CJ

Le 20/02/2021 à 09:31, Christophe JAILLET a écrit :

The wrappers in include/linux/pci-dma-compat.h should go away.

The patch has been generated with the coccinelle script below and has been
hand modified to replace GFP_ with a correct flag.
It has been compile tested.

When memory is allocated in 'pm8001_init_ccb_tag()' GFP_KERNEL can be used
because this function already uses this flag a few lines above.

While at it, remove "pm80xx: " in a debug message. 'pm8001_dbg()' already
add the driver name in the message.


@@
@@
-PCI_DMA_BIDIRECTIONAL
+DMA_BIDIRECTIONAL

@@
@@
-PCI_DMA_TODEVICE
+DMA_TO_DEVICE

@@
@@
-PCI_DMA_FROMDEVICE
+DMA_FROM_DEVICE

@@
@@
-PCI_DMA_NONE
+DMA_NONE

@@
expression e1, e2, e3;
@@
-pci_alloc_consistent(e1, e2, e3)
+dma_alloc_coherent(>dev, e2, e3, GFP_)

@@
expression e1, e2, e3;
@@
-pci_zalloc_consistent(e1, e2, e3)
+dma_alloc_coherent(>dev, e2, e3, GFP_)

@@
expression e1, e2, e3, e4;
@@
-pci_free_consistent(e1, e2, e3, e4)
+dma_free_coherent(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_map_single(e1, e2, e3, e4)
+dma_map_single(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_unmap_single(e1, e2, e3, e4)
+dma_unmap_single(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4, e5;
@@
-pci_map_page(e1, e2, e3, e4, e5)
+dma_map_page(>dev, e2, e3, e4, e5)

@@
expression e1, e2, e3, e4;
@@
-pci_unmap_page(e1, e2, e3, e4)
+dma_unmap_page(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_map_sg(e1, e2, e3, e4)
+dma_map_sg(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_unmap_sg(e1, e2, e3, e4)
+dma_unmap_sg(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_dma_sync_single_for_cpu(e1, e2, e3, e4)
+dma_sync_single_for_cpu(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_dma_sync_single_for_device(e1, e2, e3, e4)
+dma_sync_single_for_device(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_dma_sync_sg_for_cpu(e1, e2, e3, e4)
+dma_sync_sg_for_cpu(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_dma_sync_sg_for_device(e1, e2, e3, e4)
+dma_sync_sg_for_device(>dev, e2, e3, e4)

@@
expression e1, e2;
@@
-pci_dma_mapping_error(e1, e2)
+dma_mapping_error(>dev, e2)

@@
expression e1, e2;
@@
-pci_set_dma_mask(e1, e2)
+dma_set_mask(>dev, e2)

@@
expression e1, e2;
@@
-pci_set_consistent_dma_mask(e1, e2)
+dma_set_coherent_mask(>dev, e2)

Signed-off-by: Christophe JAILLET 
---
If needed, see post from Christoph Hellwig on the kernel-janitors ML:
https://marc.info/?l=kernel-janitors=158745678307186=4
---
  drivers/scsi/pm8001/pm8001_init.c | 9 +
  1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/pm8001/pm8001_init.c 
b/drivers/scsi/pm8001/pm8001_init.c
index d21078ca7fb3..bd626ef876da 100644
--- a/drivers/scsi/pm8001/pm8001_init.c
+++ b/drivers/scsi/pm8001/pm8001_init.c
@@ -423,7 +423,7 @@ static int pm8001_alloc(struct pm8001_hba_info *pm8001_ha,
  err_out_nodev:
for (i = 0; i < pm8001_ha->max_memcnt; i++) {
if (pm8001_ha->memoryMap.region[i].virt_ptr != NULL) {
-   pci_free_consistent(pm8001_ha->pdev,
+   dma_free_coherent(_ha->pdev->dev,
(pm8001_ha->memoryMap.region[i].total_len +
pm8001_ha->memoryMap.region[i].alignment),
pm8001_ha->memoryMap.region[i].virt_ptr,
@@ -1197,12 +1197,13 @@ pm8001_init_ccb_tag(struct pm8001_hba_info *pm8001_ha, 
struct Scsi_Host *shost,
goto err_out_noccb;
}
for (i = 0; i < ccb_count; i++) {
-   pm8001_ha->ccb_info[i].buf_prd = pci_alloc_consistent(pdev,
+   pm8001_ha->ccb_info[i].buf_prd = dma_alloc_coherent(>dev,
sizeof(struct pm8001_prd) * PM8001_MAX_DMA_SG,
-   _ha->ccb_info[i].ccb_dma_handle);
+   _ha->ccb_info[i].ccb_dma_handle,
+   GFP_KERNEL);
if (!pm8001_ha->ccb_info[i].buf_prd) {
pm8001_dbg(pm8001_ha, FAIL,
-  "pm80xx: ccb prd memory allocation error\n");
+  "ccb prd memory allocation error\n");
goto err_out;
}
pm8001_ha->ccb_info[i].task = NULL;





[PATCH] scsi: pm80xx: switch from 'pci_' to 'dma_' API

2021-02-20 Thread Christophe JAILLET
The wrappers in include/linux/pci-dma-compat.h should go away.

The patch has been generated with the coccinelle script below and has been
hand modified to replace GFP_ with a correct flag.
It has been compile tested.

When memory is allocated in 'pm8001_init_ccb_tag()' GFP_KERNEL can be used
because this function already uses this flag a few lines above.

While at it, remove "pm80xx: " in a debug message. 'pm8001_dbg()' already
add the driver name in the message.


@@
@@
-PCI_DMA_BIDIRECTIONAL
+DMA_BIDIRECTIONAL

@@
@@
-PCI_DMA_TODEVICE
+DMA_TO_DEVICE

@@
@@
-PCI_DMA_FROMDEVICE
+DMA_FROM_DEVICE

@@
@@
-PCI_DMA_NONE
+DMA_NONE

@@
expression e1, e2, e3;
@@
-pci_alloc_consistent(e1, e2, e3)
+dma_alloc_coherent(>dev, e2, e3, GFP_)

@@
expression e1, e2, e3;
@@
-pci_zalloc_consistent(e1, e2, e3)
+dma_alloc_coherent(>dev, e2, e3, GFP_)

@@
expression e1, e2, e3, e4;
@@
-pci_free_consistent(e1, e2, e3, e4)
+dma_free_coherent(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_map_single(e1, e2, e3, e4)
+dma_map_single(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_unmap_single(e1, e2, e3, e4)
+dma_unmap_single(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4, e5;
@@
-pci_map_page(e1, e2, e3, e4, e5)
+dma_map_page(>dev, e2, e3, e4, e5)

@@
expression e1, e2, e3, e4;
@@
-pci_unmap_page(e1, e2, e3, e4)
+dma_unmap_page(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_map_sg(e1, e2, e3, e4)
+dma_map_sg(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_unmap_sg(e1, e2, e3, e4)
+dma_unmap_sg(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_dma_sync_single_for_cpu(e1, e2, e3, e4)
+dma_sync_single_for_cpu(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_dma_sync_single_for_device(e1, e2, e3, e4)
+dma_sync_single_for_device(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_dma_sync_sg_for_cpu(e1, e2, e3, e4)
+dma_sync_sg_for_cpu(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_dma_sync_sg_for_device(e1, e2, e3, e4)
+dma_sync_sg_for_device(>dev, e2, e3, e4)

@@
expression e1, e2;
@@
-pci_dma_mapping_error(e1, e2)
+dma_mapping_error(>dev, e2)

@@
expression e1, e2;
@@
-pci_set_dma_mask(e1, e2)
+dma_set_mask(>dev, e2)

@@
expression e1, e2;
@@
-pci_set_consistent_dma_mask(e1, e2)
+dma_set_coherent_mask(>dev, e2)

Signed-off-by: Christophe JAILLET 
---
If needed, see post from Christoph Hellwig on the kernel-janitors ML:
   https://marc.info/?l=kernel-janitors=158745678307186=4
---
 drivers/scsi/pm8001/pm8001_init.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/pm8001/pm8001_init.c 
b/drivers/scsi/pm8001/pm8001_init.c
index d21078ca7fb3..bd626ef876da 100644
--- a/drivers/scsi/pm8001/pm8001_init.c
+++ b/drivers/scsi/pm8001/pm8001_init.c
@@ -423,7 +423,7 @@ static int pm8001_alloc(struct pm8001_hba_info *pm8001_ha,
 err_out_nodev:
for (i = 0; i < pm8001_ha->max_memcnt; i++) {
if (pm8001_ha->memoryMap.region[i].virt_ptr != NULL) {
-   pci_free_consistent(pm8001_ha->pdev,
+   dma_free_coherent(_ha->pdev->dev,
(pm8001_ha->memoryMap.region[i].total_len +
pm8001_ha->memoryMap.region[i].alignment),
pm8001_ha->memoryMap.region[i].virt_ptr,
@@ -1197,12 +1197,13 @@ pm8001_init_ccb_tag(struct pm8001_hba_info *pm8001_ha, 
struct Scsi_Host *shost,
goto err_out_noccb;
}
for (i = 0; i < ccb_count; i++) {
-   pm8001_ha->ccb_info[i].buf_prd = pci_alloc_consistent(pdev,
+   pm8001_ha->ccb_info[i].buf_prd = dma_alloc_coherent(>dev,
sizeof(struct pm8001_prd) * PM8001_MAX_DMA_SG,
-   _ha->ccb_info[i].ccb_dma_handle);
+   _ha->ccb_info[i].ccb_dma_handle,
+   GFP_KERNEL);
if (!pm8001_ha->ccb_info[i].buf_prd) {
pm8001_dbg(pm8001_ha, FAIL,
-  "pm80xx: ccb prd memory allocation error\n");
+  "ccb prd memory allocation error\n");
goto err_out;
}
pm8001_ha->ccb_info[i].task = NULL;
-- 
2.27.0



[PATCH resend] media: ngene: switch from 'pci_' to 'dma_' API

2021-01-30 Thread Christophe JAILLET
The wrappers in include/linux/pci-dma-compat.h should go away.

The patch has been generated with the coccinelle script below and has been
hand modified to replace GFP_ with a correct flag.
It has been compile tested.

When memory is allocated, GFP_KERNEL can be used because in all cases,
it is called from a probe function and no lock is taken in the between.

The call chain is:
  ngene_probe   (probe function, used in ngene-cards.c)
--> ngene_get_buffers
  --> AllocCommonBuffers  (call dma_alloc_coherent)
--> create_ring_buffer(call dma_alloc_coherent)
--> AllocateRingBuffers   (call dma_alloc_coherent)


@@
@@
-PCI_DMA_BIDIRECTIONAL
+DMA_BIDIRECTIONAL

@@
@@
-PCI_DMA_TODEVICE
+DMA_TO_DEVICE

@@
@@
-PCI_DMA_FROMDEVICE
+DMA_FROM_DEVICE

@@
@@
-PCI_DMA_NONE
+DMA_NONE

@@
expression e1, e2, e3;
@@
-pci_alloc_consistent(e1, e2, e3)
+dma_alloc_coherent(>dev, e2, e3, GFP_)

@@
expression e1, e2, e3;
@@
-pci_zalloc_consistent(e1, e2, e3)
+dma_alloc_coherent(>dev, e2, e3, GFP_)

@@
expression e1, e2, e3, e4;
@@
-pci_free_consistent(e1, e2, e3, e4)
+dma_free_coherent(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_map_single(e1, e2, e3, e4)
+dma_map_single(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_unmap_single(e1, e2, e3, e4)
+dma_unmap_single(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4, e5;
@@
-pci_map_page(e1, e2, e3, e4, e5)
+dma_map_page(>dev, e2, e3, e4, e5)

@@
expression e1, e2, e3, e4;
@@
-pci_unmap_page(e1, e2, e3, e4)
+dma_unmap_page(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_map_sg(e1, e2, e3, e4)
+dma_map_sg(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_unmap_sg(e1, e2, e3, e4)
+dma_unmap_sg(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_dma_sync_single_for_cpu(e1, e2, e3, e4)
+dma_sync_single_for_cpu(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_dma_sync_single_for_device(e1, e2, e3, e4)
+dma_sync_single_for_device(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_dma_sync_sg_for_cpu(e1, e2, e3, e4)
+dma_sync_sg_for_cpu(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_dma_sync_sg_for_device(e1, e2, e3, e4)
+dma_sync_sg_for_device(>dev, e2, e3, e4)

@@
expression e1, e2;
@@
-pci_dma_mapping_error(e1, e2)
+dma_mapping_error(>dev, e2)

@@
expression e1, e2;
@@
-pci_set_dma_mask(e1, e2)
+dma_set_mask(>dev, e2)

@@
expression e1, e2;
@@
-pci_set_consistent_dma_mask(e1, e2)
+dma_set_coherent_mask(>dev, e2)

Signed-off-by: Christophe JAILLET 
---
If needed, see post from Christoph Hellwig on the kernel-janitors ML:
   https://marc.info/?l=kernel-janitors=158745678307186=4
---
 drivers/media/pci/ngene/ngene-core.c | 56 ++--
 1 file changed, 28 insertions(+), 28 deletions(-)

diff --git a/drivers/media/pci/ngene/ngene-core.c 
b/drivers/media/pci/ngene/ngene-core.c
index f9f94f47d76b..07f342db6701 100644
--- a/drivers/media/pci/ngene/ngene-core.c
+++ b/drivers/media/pci/ngene/ngene-core.c
@@ -763,23 +763,22 @@ static void free_ringbuffer(struct ngene *dev, struct 
SRingBufferDescriptor *rb)
 
for (j = 0; j < rb->NumBuffers; j++, Cur = Cur->Next) {
if (Cur->Buffer1)
-   pci_free_consistent(dev->pci_dev,
-   rb->Buffer1Length,
-   Cur->Buffer1,
-   Cur->scList1->Address);
+   dma_free_coherent(>pci_dev->dev,
+ rb->Buffer1Length, Cur->Buffer1,
+ Cur->scList1->Address);
 
if (Cur->Buffer2)
-   pci_free_consistent(dev->pci_dev,
-   rb->Buffer2Length,
-   Cur->Buffer2,
-   Cur->scList2->Address);
+   dma_free_coherent(>pci_dev->dev,
+ rb->Buffer2Length, Cur->Buffer2,
+ Cur->scList2->Address);
}
 
if (rb->SCListMem)
-   pci_free_consistent(dev->pci_dev, rb->SCListMemSize,
-   rb->SCListMem, rb->PASCListMem);
+   dma_free_coherent(>pci_dev->dev, rb->SCListMemSize,
+ rb->SCListMem, rb->PASCListMem);
 
-   pci_free_consistent(dev->pci_dev, rb->MemSize, rb->Head, rb->PAHead);
+   dma_free_coherent(>pci_dev->dev, rb->MemSize, rb->Head,
+

[PATCH resend] e100: switch from 'pci_' to 'dma_' API

2021-01-28 Thread Christophe JAILLET
The wrappers in include/linux/pci-dma-compat.h should go away.

The patch has been generated with the coccinelle script below and has been
hand modified to replace GFP_ with a correct flag.
It has been compile tested.

When memory is allocated in 'e100_alloc()', GFP_KERNEL can be used because
it is only called from the probe function and no lock is acquired.


@@
@@
-PCI_DMA_BIDIRECTIONAL
+DMA_BIDIRECTIONAL

@@
@@
-PCI_DMA_TODEVICE
+DMA_TO_DEVICE

@@
@@
-PCI_DMA_FROMDEVICE
+DMA_FROM_DEVICE

@@
@@
-PCI_DMA_NONE
+DMA_NONE

@@
expression e1, e2, e3;
@@
-pci_alloc_consistent(e1, e2, e3)
+dma_alloc_coherent(>dev, e2, e3, GFP_)

@@
expression e1, e2, e3;
@@
-pci_zalloc_consistent(e1, e2, e3)
+dma_alloc_coherent(>dev, e2, e3, GFP_)

@@
expression e1, e2, e3, e4;
@@
-pci_free_consistent(e1, e2, e3, e4)
+dma_free_coherent(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_map_single(e1, e2, e3, e4)
+dma_map_single(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_unmap_single(e1, e2, e3, e4)
+dma_unmap_single(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4, e5;
@@
-pci_map_page(e1, e2, e3, e4, e5)
+dma_map_page(>dev, e2, e3, e4, e5)

@@
expression e1, e2, e3, e4;
@@
-pci_unmap_page(e1, e2, e3, e4)
+dma_unmap_page(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_map_sg(e1, e2, e3, e4)
+dma_map_sg(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_unmap_sg(e1, e2, e3, e4)
+dma_unmap_sg(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_dma_sync_single_for_cpu(e1, e2, e3, e4)
+dma_sync_single_for_cpu(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_dma_sync_single_for_device(e1, e2, e3, e4)
+dma_sync_single_for_device(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_dma_sync_sg_for_cpu(e1, e2, e3, e4)
+dma_sync_sg_for_cpu(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_dma_sync_sg_for_device(e1, e2, e3, e4)
+dma_sync_sg_for_device(>dev, e2, e3, e4)

@@
expression e1, e2;
@@
-pci_dma_mapping_error(e1, e2)
+dma_mapping_error(>dev, e2)

@@
expression e1, e2;
@@
-pci_set_dma_mask(e1, e2)
+dma_set_mask(>dev, e2)

@@
expression e1, e2;
@@
-pci_set_consistent_dma_mask(e1, e2)
+dma_set_coherent_mask(>dev, e2)

Signed-off-by: Christophe JAILLET 
Tested-by: Aaron Brown 
---
If needed, see post from Christoph Hellwig on the kernel-janitors ML:
   https://marc.info/?l=kernel-janitors=158745678307186=4

First sent on 18 Jul. 2020, see:

https://lore.kernel.org/lkml/20200718115546.358240-1-christophe.jail...@wanadoo.fr/
It still applies cleanly with latest linux-next

Tested tag, see:
   
https://lore.kernel.org/lkml/dm6pr11mb289001e5538e536f0cb60a1fbc...@dm6pr11mb2890.namprd11.prod.outlook.com/

---
 drivers/net/ethernet/intel/e100.c | 92 ---
 1 file changed, 49 insertions(+), 43 deletions(-)

diff --git a/drivers/net/ethernet/intel/e100.c 
b/drivers/net/ethernet/intel/e100.c
index 91c64f91a835..ec6b1024cd8a 100644
--- a/drivers/net/ethernet/intel/e100.c
+++ b/drivers/net/ethernet/intel/e100.c
@@ -1739,10 +1739,10 @@ static int e100_xmit_prepare(struct nic *nic, struct cb 
*cb,
dma_addr_t dma_addr;
cb->command = nic->tx_command;
 
-   dma_addr = pci_map_single(nic->pdev,
- skb->data, skb->len, PCI_DMA_TODEVICE);
+   dma_addr = dma_map_single(>pdev->dev, skb->data, skb->len,
+ DMA_TO_DEVICE);
/* If we can't map the skb, have the upper layer try later */
-   if (pci_dma_mapping_error(nic->pdev, dma_addr)) {
+   if (dma_mapping_error(>pdev->dev, dma_addr)) {
dev_kfree_skb_any(skb);
skb = NULL;
return -ENOMEM;
@@ -1828,10 +1828,10 @@ static int e100_tx_clean(struct nic *nic)
dev->stats.tx_packets++;
dev->stats.tx_bytes += cb->skb->len;
 
-   pci_unmap_single(nic->pdev,
-   le32_to_cpu(cb->u.tcb.tbd.buf_addr),
-   le16_to_cpu(cb->u.tcb.tbd.size),
-   PCI_DMA_TODEVICE);
+   dma_unmap_single(>pdev->dev,
+le32_to_cpu(cb->u.tcb.tbd.buf_addr),
+le16_to_cpu(cb->u.tcb.tbd.size),
+DMA_TO_DEVICE);
dev_kfree_skb_any(cb->skb);
cb->skb = NULL;
tx_cleaned = 1;
@@ -1855,10 +1855,10 @@ static void e100_clean_cbs(struct nic *nic)
while (nic->cbs_avail != nic->params.cbs.count) {
struct cb *cb = nic->cb_to_clean;
  

[PATCH v2] media: venus: core: Fix some resource leaks in the error path of 'venus_probe()'

2021-01-28 Thread Christophe JAILLET
If an error occurs after a successful 'of_icc_get()' call, it must be
undone.

Use 'devm_of_icc_get()' instead of 'of_icc_get()' to avoid the leak.
Update the remove function accordingly and axe the now unneeded
'icc_put()' calls.

Fixes: 32f0a6ddc8c9 ("media: venus: Use on-chip interconnect API")
Signed-off-by: Christophe JAILLET 
---
v1->v2: use managed resources instead of expanding the error handling path.
---
 drivers/media/platform/qcom/venus/core.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/media/platform/qcom/venus/core.c 
b/drivers/media/platform/qcom/venus/core.c
index 0bde19edac86..c2458dee794b 100644
--- a/drivers/media/platform/qcom/venus/core.c
+++ b/drivers/media/platform/qcom/venus/core.c
@@ -195,11 +195,11 @@ static int venus_probe(struct platform_device *pdev)
if (IS_ERR(core->base))
return PTR_ERR(core->base);
 
-   core->video_path = of_icc_get(dev, "video-mem");
+   core->video_path = devm_of_icc_get(dev, "video-mem");
if (IS_ERR(core->video_path))
return PTR_ERR(core->video_path);
 
-   core->cpucfg_path = of_icc_get(dev, "cpu-cfg");
+   core->cpucfg_path = devm_of_icc_get(dev, "cpu-cfg");
if (IS_ERR(core->cpucfg_path))
return PTR_ERR(core->cpucfg_path);
 
@@ -334,9 +334,6 @@ static int venus_remove(struct platform_device *pdev)
 
hfi_destroy(core);
 
-   icc_put(core->video_path);
-   icc_put(core->cpucfg_path);
-
v4l2_device_unregister(>v4l2_dev);
mutex_destroy(>pm_lock);
mutex_destroy(>lock);
-- 
2.27.0



Re: [PATCH] media: venus: core: Fix some resource leaks in the error path of 'venus_probe()'

2021-01-28 Thread Christophe JAILLET



Le 28/01/2021 à 11:49, Georgi Djakov a écrit :

Hi Christophe,

Thanks for the fix!

On 1/27/21 22:17, Christophe JAILLET wrote:

If an error occurs after a successful 'of_icc_get()' call, it must be
undone by a corresponding 'icc_put()' call.


This works, but why not switch to devm_of_icc_get() instead?


Because I was not aware of devm_of_icc_get :)

I'll send a V2.

Thanks for the review and the feedback.

CJ



Thanks,
Georgi



Add it in the error handling path of the probe function as already 
done in

the remove function.

Fixes: 32f0a6ddc8c9 ("media: venus: Use on-chip interconnect API")
Signed-off-by: Christophe JAILLET 
---
  drivers/media/platform/qcom/venus/core.c | 31 +---
  1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/drivers/media/platform/qcom/venus/core.c 
b/drivers/media/platform/qcom/venus/core.c

index 0bde19edac86..8fd5da941067 100644
--- a/drivers/media/platform/qcom/venus/core.c
+++ b/drivers/media/platform/qcom/venus/core.c
@@ -200,27 +200,35 @@ static int venus_probe(struct platform_device 
*pdev)

  return PTR_ERR(core->video_path);
    core->cpucfg_path = of_icc_get(dev, "cpu-cfg");
-    if (IS_ERR(core->cpucfg_path))
-    return PTR_ERR(core->cpucfg_path);
+    if (IS_ERR(core->cpucfg_path)) {
+    ret = PTR_ERR(core->cpucfg_path);
+    goto err_video_path_put;
+    }
    core->irq = platform_get_irq(pdev, 0);
-    if (core->irq < 0)
-    return core->irq;
+    if (core->irq < 0) {
+    ret = core->irq;
+    goto err_cpucfg_path_put;
+    }
    core->res = of_device_get_match_data(dev);
-    if (!core->res)
-    return -ENODEV;
+    if (!core->res) {
+    ret = -ENODEV;
+    goto err_cpucfg_path_put;
+    }
    mutex_init(>pm_lock);
    core->pm_ops = venus_pm_get(core->res->hfi_version);
-    if (!core->pm_ops)
-    return -ENODEV;
+    if (!core->pm_ops) {
+    ret = -ENODEV;
+    goto err_cpucfg_path_put;
+    }
    if (core->pm_ops->core_get) {
  ret = core->pm_ops->core_get(dev);
  if (ret)
-    return ret;
+    goto err_cpucfg_path_put;
  }
    ret = dma_set_mask_and_coherent(dev, core->res->dma_mask);
@@ -305,6 +313,11 @@ static int venus_probe(struct platform_device 
*pdev)

  err_core_put:
  if (core->pm_ops->core_put)
  core->pm_ops->core_put(dev);
+err_cpucfg_path_put:
+    icc_put(core->cpucfg_path);
+err_video_path_put:
+    icc_put(core->video_path);
+
  return ret;
  }



[PATCH] media: venus: core: Fix some resource leaks in the error path of 'venus_probe()'

2021-01-27 Thread Christophe JAILLET
If an error occurs after a successful 'of_icc_get()' call, it must be
undone by a corresponding 'icc_put()' call.

Add it in the error handling path of the probe function as already done in
the remove function.

Fixes: 32f0a6ddc8c9 ("media: venus: Use on-chip interconnect API")
Signed-off-by: Christophe JAILLET 
---
 drivers/media/platform/qcom/venus/core.c | 31 +---
 1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/drivers/media/platform/qcom/venus/core.c 
b/drivers/media/platform/qcom/venus/core.c
index 0bde19edac86..8fd5da941067 100644
--- a/drivers/media/platform/qcom/venus/core.c
+++ b/drivers/media/platform/qcom/venus/core.c
@@ -200,27 +200,35 @@ static int venus_probe(struct platform_device *pdev)
return PTR_ERR(core->video_path);
 
core->cpucfg_path = of_icc_get(dev, "cpu-cfg");
-   if (IS_ERR(core->cpucfg_path))
-   return PTR_ERR(core->cpucfg_path);
+   if (IS_ERR(core->cpucfg_path)) {
+   ret = PTR_ERR(core->cpucfg_path);
+   goto err_video_path_put;
+   }
 
core->irq = platform_get_irq(pdev, 0);
-   if (core->irq < 0)
-   return core->irq;
+   if (core->irq < 0) {
+   ret = core->irq;
+   goto err_cpucfg_path_put;
+   }
 
core->res = of_device_get_match_data(dev);
-   if (!core->res)
-   return -ENODEV;
+   if (!core->res) {
+   ret = -ENODEV;
+   goto err_cpucfg_path_put;
+   }
 
mutex_init(>pm_lock);
 
core->pm_ops = venus_pm_get(core->res->hfi_version);
-   if (!core->pm_ops)
-   return -ENODEV;
+   if (!core->pm_ops) {
+   ret = -ENODEV;
+   goto err_cpucfg_path_put;
+   }
 
if (core->pm_ops->core_get) {
ret = core->pm_ops->core_get(dev);
if (ret)
-   return ret;
+   goto err_cpucfg_path_put;
}
 
ret = dma_set_mask_and_coherent(dev, core->res->dma_mask);
@@ -305,6 +313,11 @@ static int venus_probe(struct platform_device *pdev)
 err_core_put:
if (core->pm_ops->core_put)
core->pm_ops->core_put(dev);
+err_cpucfg_path_put:
+   icc_put(core->cpucfg_path);
+err_video_path_put:
+   icc_put(core->video_path);
+
return ret;
 }
 
-- 
2.27.0



[PATCH] ACPICA: Common: Fix a typo

2021-01-24 Thread Christophe JAILLET
This module is 'cmfsize', not 'cfsize'.
Fix it.

Signed-off-by: Christophe JAILLET 
---
 tools/power/acpi/common/cmfsize.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/power/acpi/common/cmfsize.c 
b/tools/power/acpi/common/cmfsize.c
index 9ea2c0aeb86c..185b8c588e1d 100644
--- a/tools/power/acpi/common/cmfsize.c
+++ b/tools/power/acpi/common/cmfsize.c
@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
 /**
  *
- * Module Name: cfsize - Common get file size function
+ * Module Name: cmfsize - Common get file size function
  *
  * Copyright (C) 2000 - 2021, Intel Corp.
  *
-- 
2.27.0



[PATCH v2] iwlwifi: mvm: Fix an error handling path in 'iwl_mvm_wowlan_config_key_params()'

2021-01-24 Thread Christophe JAILLET
If the 'cmd_ver' check fails, we must release some memory as already done
in all the other error handling paths of this function.

Fixes: 9e3c39361a30 ("iwlwifi: mvm: support new KEK KCK api")
Signed-off-by: Christophe JAILLET 
---
v1->v2: Fix the subject
---
 drivers/net/wireless/intel/iwlwifi/mvm/d3.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/d3.c 
b/drivers/net/wireless/intel/iwlwifi/mvm/d3.c
index c025188fa9bc..2fb897cbfca6 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/d3.c
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/d3.c
@@ -810,8 +810,10 @@ static int iwl_mvm_wowlan_config_key_params(struct iwl_mvm 
*mvm,
WOWLAN_KEK_KCK_MATERIAL,
IWL_FW_CMD_VER_UNKNOWN);
if (WARN_ON(cmd_ver != 2 && cmd_ver != 3 &&
-   cmd_ver != IWL_FW_CMD_VER_UNKNOWN))
-   return -EINVAL;
+   cmd_ver != IWL_FW_CMD_VER_UNKNOWN)) {
+   ret = -EINVAL;
+   goto out;
+   }
if (cmd_ver == 3)
cmd_size = sizeof(struct 
iwl_wowlan_kek_kck_material_cmd_v3);
else
-- 
2.27.0



Re: [PATCH] iwlwifi: mvm: Fix an error handling path in 'ebu_dma_start()'

2021-01-24 Thread Christophe JAILLET

Le 24/01/2021 à 08:56, Christophe JAILLET a écrit :

If the 'cmd_ver' check fails, we must release some memory as already done
in all the other error handling paths of this function.

Fixes: 9e3c39361a30 ("iwlwifi: mvm: support new KEK KCK api")
Signed-off-by: Christophe JAILLET 
---
  drivers/net/wireless/intel/iwlwifi/mvm/d3.c | 6 --
  1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/d3.c 
b/drivers/net/wireless/intel/iwlwifi/mvm/d3.c
index c025188fa9bc..2fb897cbfca6 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/d3.c
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/d3.c
@@ -810,8 +810,10 @@ static int iwl_mvm_wowlan_config_key_params(struct iwl_mvm 
*mvm,
WOWLAN_KEK_KCK_MATERIAL,
IWL_FW_CMD_VER_UNKNOWN);
if (WARN_ON(cmd_ver != 2 && cmd_ver != 3 &&
-   cmd_ver != IWL_FW_CMD_VER_UNKNOWN))
-   return -EINVAL;
+   cmd_ver != IWL_FW_CMD_VER_UNKNOWN)) {
+   ret = -EINVAL;
+   goto out;
+   }
if (cmd_ver == 3)
cmd_size = sizeof(struct 
iwl_wowlan_kek_kck_material_cmd_v3);
else



NACK.
I'll resend with the correct subject.

CJ


[PATCH] iwlwifi: mvm: Fix an error handling path in 'ebu_dma_start()'

2021-01-24 Thread Christophe JAILLET
If the 'cmd_ver' check fails, we must release some memory as already done
in all the other error handling paths of this function.

Fixes: 9e3c39361a30 ("iwlwifi: mvm: support new KEK KCK api")
Signed-off-by: Christophe JAILLET 
---
 drivers/net/wireless/intel/iwlwifi/mvm/d3.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/d3.c 
b/drivers/net/wireless/intel/iwlwifi/mvm/d3.c
index c025188fa9bc..2fb897cbfca6 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/d3.c
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/d3.c
@@ -810,8 +810,10 @@ static int iwl_mvm_wowlan_config_key_params(struct iwl_mvm 
*mvm,
WOWLAN_KEK_KCK_MATERIAL,
IWL_FW_CMD_VER_UNKNOWN);
if (WARN_ON(cmd_ver != 2 && cmd_ver != 3 &&
-   cmd_ver != IWL_FW_CMD_VER_UNKNOWN))
-   return -EINVAL;
+   cmd_ver != IWL_FW_CMD_VER_UNKNOWN)) {
+   ret = -EINVAL;
+   goto out;
+   }
if (cmd_ver == 3)
cmd_size = sizeof(struct 
iwl_wowlan_kek_kck_material_cmd_v3);
else
-- 
2.27.0



[PATCH] mtd: rawnand: Fix an error handling path in 'ebu_dma_start()'

2021-01-23 Thread Christophe JAILLET
If 'dmaengine_prep_slave_single()' fails, we must undo a previous
'dma_map_single()' call, as already done in all the other error handling
paths of this function.

Fixes: 0b1039f016e8 ("mtd: rawnand: Add NAND controller support on Intel LGM 
SoC")
Signed-off-by: Christophe JAILLET 
---
 drivers/mtd/nand/raw/intel-nand-controller.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/nand/raw/intel-nand-controller.c 
b/drivers/mtd/nand/raw/intel-nand-controller.c
index a304fda5d1fa..8b49fd56cf96 100644
--- a/drivers/mtd/nand/raw/intel-nand-controller.c
+++ b/drivers/mtd/nand/raw/intel-nand-controller.c
@@ -318,8 +318,10 @@ static int ebu_dma_start(struct ebu_nand_controller 
*ebu_host, u32 dir,
}
 
tx = dmaengine_prep_slave_single(chan, buf_dma, len, dir, flags);
-   if (!tx)
-   return -ENXIO;
+   if (!tx) {
+   ret = -ENXIO;
+   goto err_unmap;
+   }
 
tx->callback = callback;
tx->callback_param = ebu_host;
-- 
2.27.0



  1   2   3   4   5   6   7   8   9   10   >