From a951e147ea95b26815c72eb710e0b2b8e5d85e40 Mon Sep 17 00:00:00 2001 From: Bruce Richardson Date: Tue, 2 Jul 2019 15:12:22 +0100 Subject: [PATCH] rawdev: allow devices to skip extra memory allocation Some device drivers want to allocate their own private memory, and should be allowed to do so. Therefore skip memory allocation and associated error checks if zero-length private memory is requested. While adjusting the code for new indent level, fix incorrect error message. Signed-off-by: Bruce Richardson Acked-by: Shreyansh Jain Acked-by: Hemant Agrawal --- lib/librte_rawdev/rte_rawdev.c | 11 ++++++----- lib/librte_rawdev/rte_rawdev_pmd.h | 4 +++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/librte_rawdev/rte_rawdev.c b/lib/librte_rawdev/rte_rawdev.c index 15de2d413c..b6f1e1c779 100644 --- a/lib/librte_rawdev/rte_rawdev.c +++ b/lib/librte_rawdev/rte_rawdev.c @@ -496,16 +496,17 @@ rte_rawdev_pmd_allocate(const char *name, size_t dev_priv_size, int socket_id) rawdev = &rte_rawdevs[dev_id]; - rawdev->dev_private = rte_zmalloc_socket("rawdev private", + if (dev_priv_size > 0) { + rawdev->dev_private = rte_zmalloc_socket("rawdev private", dev_priv_size, RTE_CACHE_LINE_SIZE, socket_id); - if (!rawdev->dev_private) { - RTE_RDEV_ERR("Unable to allocate memory to Skeleton dev"); - return NULL; + if (!rawdev->dev_private) { + RTE_RDEV_ERR("Unable to allocate memory for rawdev"); + return NULL; + } } - rawdev->dev_id = dev_id; rawdev->socket_id = socket_id; rawdev->started = 0; diff --git a/lib/librte_rawdev/rte_rawdev_pmd.h b/lib/librte_rawdev/rte_rawdev_pmd.h index aa6af4a375..cb3555ab50 100644 --- a/lib/librte_rawdev/rte_rawdev_pmd.h +++ b/lib/librte_rawdev/rte_rawdev_pmd.h @@ -568,7 +568,9 @@ struct rte_rawdev_ops { * @param name * Unique identifier name for each device * @param dev_private_size - * Private data allocated within rte_rawdev object. + * Size of private data memory allocated within rte_rawdev object. + * Set to 0 to disable internal memory allocation and allow for + * self-allocation. * @param socket_id * Socket to allocate resources on. * @return