[dpdk-dev,v2,2/3] mempool: make declaration of handler structs const

Message ID 1463669335-30378-3-git-send-email-david.hunt@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers

Commit Message

Hunt, David May 19, 2016, 2:48 p.m. UTC
  For security, any data structure with function pointers should be const

Signed-off-by: David Hunt <david.hunt@intel.com>
---
 lib/librte_mempool/rte_mempool.h         | 2 +-
 lib/librte_mempool/rte_mempool_default.c | 8 ++++----
 lib/librte_mempool/rte_mempool_handler.c | 2 +-
 lib/librte_mempool/rte_mempool_stack.c   | 2 +-
 4 files changed, 7 insertions(+), 7 deletions(-)
  

Comments

Olivier Matz May 23, 2016, 12:55 p.m. UTC | #1
Hi David,

On 05/19/2016 04:48 PM, David Hunt wrote:
> For security, any data structure with function pointers should be const
> 
> Signed-off-by: David Hunt <david.hunt@intel.com>

I think this should be merged in the patchset adding the mempool
handler feature.
  
Hunt, David May 24, 2016, 2:01 p.m. UTC | #2
On 5/23/2016 1:55 PM, Olivier Matz wrote:
> Hi David,
>
> On 05/19/2016 04:48 PM, David Hunt wrote:
>> For security, any data structure with function pointers should be const
> I think this should be merged in the patchset adding the mempool
> handler feature.

Agreed, I'm working on that now, merging it in with some changes 
suggested by Jan on the other patch.

Thanks,
David.
  

Patch

diff --git a/lib/librte_mempool/rte_mempool.h b/lib/librte_mempool/rte_mempool.h
index ed2c110..baa5f48 100644
--- a/lib/librte_mempool/rte_mempool.h
+++ b/lib/librte_mempool/rte_mempool.h
@@ -491,7 +491,7 @@  rte_mempool_set_handler(struct rte_mempool *mp, const char *name);
  *   - >=0: Sucess; return the index of the handler in the table.
  *   - <0: Error (errno)
  */
-int rte_mempool_handler_register(struct rte_mempool_handler *h);
+int rte_mempool_handler_register(const struct rte_mempool_handler *h);
 
 /**
  * Macro to statically register an external pool handler.
diff --git a/lib/librte_mempool/rte_mempool_default.c b/lib/librte_mempool/rte_mempool_default.c
index a6ac65a..764f772 100644
--- a/lib/librte_mempool/rte_mempool_default.c
+++ b/lib/librte_mempool/rte_mempool_default.c
@@ -105,7 +105,7 @@  common_ring_free(void *p)
 	rte_ring_free((struct rte_ring *)p);
 }
 
-static struct rte_mempool_handler handler_mp_mc = {
+static const struct rte_mempool_handler handler_mp_mc = {
 	.name = "ring_mp_mc",
 	.alloc = common_ring_alloc,
 	.free = common_ring_free,
@@ -114,7 +114,7 @@  static struct rte_mempool_handler handler_mp_mc = {
 	.get_count = common_ring_get_count,
 };
 
-static struct rte_mempool_handler handler_sp_sc = {
+static const struct rte_mempool_handler handler_sp_sc = {
 	.name = "ring_sp_sc",
 	.alloc = common_ring_alloc,
 	.free = common_ring_free,
@@ -123,7 +123,7 @@  static struct rte_mempool_handler handler_sp_sc = {
 	.get_count = common_ring_get_count,
 };
 
-static struct rte_mempool_handler handler_mp_sc = {
+static const struct rte_mempool_handler handler_mp_sc = {
 	.name = "ring_mp_sc",
 	.alloc = common_ring_alloc,
 	.free = common_ring_free,
@@ -132,7 +132,7 @@  static struct rte_mempool_handler handler_mp_sc = {
 	.get_count = common_ring_get_count,
 };
 
-static struct rte_mempool_handler handler_sp_mc = {
+static const struct rte_mempool_handler handler_sp_mc = {
 	.name = "ring_sp_mc",
 	.alloc = common_ring_alloc,
 	.free = common_ring_free,
diff --git a/lib/librte_mempool/rte_mempool_handler.c b/lib/librte_mempool/rte_mempool_handler.c
index 78611f8..eab1e69 100644
--- a/lib/librte_mempool/rte_mempool_handler.c
+++ b/lib/librte_mempool/rte_mempool_handler.c
@@ -45,7 +45,7 @@  struct rte_mempool_handler_table rte_mempool_handler_table = {
 
 /* add a new handler in rte_mempool_handler_table, return its index */
 int
-rte_mempool_handler_register(struct rte_mempool_handler *h)
+rte_mempool_handler_register(const struct rte_mempool_handler *h)
 {
 	struct rte_mempool_handler *handler;
 	int16_t handler_idx;
diff --git a/lib/librte_mempool/rte_mempool_stack.c b/lib/librte_mempool/rte_mempool_stack.c
index 6e25028..ad49436 100644
--- a/lib/librte_mempool/rte_mempool_stack.c
+++ b/lib/librte_mempool/rte_mempool_stack.c
@@ -133,7 +133,7 @@  common_stack_free(void *p)
 	rte_free(p);
 }
 
-static struct rte_mempool_handler handler_stack = {
+static const struct rte_mempool_handler handler_stack = {
 	.name = "stack",
 	.alloc = common_stack_alloc,
 	.free = common_stack_free,