[PATCH] livepatch: drop const from heap pointers in struct payload

Dmytro Prokopchuk1 posted 1 patch 3 days, 16 hours ago
xen/common/livepatch.c              | 10 +++++-----
xen/include/xen/livepatch_payload.h |  6 +++---
2 files changed, 8 insertions(+), 8 deletions(-)
[PATCH] livepatch: drop const from heap pointers in struct payload
Posted by Dmytro Prokopchuk1 3 days, 16 hours ago
text_addr, symtab and strtab hold memory from vmalloc_xen() and
xmalloc(). Freeing them through xfree() and vfree(), which take
void *, casts away the const qualifier and violates MISRA C Rule 11.8.

Remove const from text_addr, symtab and strtab, so the pointers can be
passed to the deallocators directly.

rw_addr and ro_addr are left unchanged: they are interior pointers
of the text_addr mapping.

No functional changes.

Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@epam.com>
---
Test CI pipeline:
https://gitlab.com/xen-project/people/dimaprkp4k/xen/-/pipelines/3100089161
---
 xen/common/livepatch.c              | 10 +++++-----
 xen/include/xen/livepatch_payload.h |  6 +++---
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/xen/common/livepatch.c b/xen/common/livepatch.c
index 38d0cf8635..edfbe580ff 100644
--- a/xen/common/livepatch.c
+++ b/xen/common/livepatch.c
@@ -250,7 +250,7 @@ static void free_payload_data(struct payload *payload)
     if ( !payload->pages )
         return;
 
-    vfree((void *)payload->text_addr);
+    vfree(payload->text_addr);
 
     payload->pages = 0;
 
@@ -1133,8 +1133,8 @@ static void free_payload(struct payload *data)
     payload_cnt--;
     payload_version++;
     free_payload_data(data);
-    xfree((void *)data->symtab);
-    xfree((void *)data->strtab);
+    xfree(data->symtab);
+    xfree(data->strtab);
     xfree(data);
 }
 
@@ -1241,8 +1241,8 @@ static int livepatch_upload(struct xen_sysctl_livepatch_upload *upload)
 
     if ( rc && data )
     {
-        xfree((void *)data->symtab);
-        xfree((void *)data->strtab);
+        xfree(data->symtab);
+        xfree(data->strtab);
         xfree(data);
     }
 
diff --git a/xen/include/xen/livepatch_payload.h b/xen/include/xen/livepatch_payload.h
index c6dc7cb5fa..367fbbfcad 100644
--- a/xen/include/xen/livepatch_payload.h
+++ b/xen/include/xen/livepatch_payload.h
@@ -44,7 +44,7 @@ struct payload {
     bool reverted;                       /* Whether it was reverted. */
     bool safe_to_reapply;                /* Can apply safely after revert. */
     struct list_head list;               /* Linked to 'payload_list'. */
-    const void *text_addr;               /* Virtual address of .text. */
+    void *text_addr;                     /* Virtual address of .text. */
     size_t text_size;                    /* .. and its size. */
     const void *rw_addr;                 /* Virtual address of .data. */
     size_t rw_size;                      /* .. and its size (if any). */
@@ -55,8 +55,8 @@ struct payload {
     const struct livepatch_func *funcs;  /* The array of functions to patch. */
     struct livepatch_fstate *fstate;     /* State of patched functions. */
     unsigned int nfuncs;                 /* Nr of functions to patch. */
-    const struct livepatch_symbol *symtab; /* All symbols. */
-    const char *strtab;                  /* Pointer to .strtab. */
+    struct livepatch_symbol *symtab;     /* All symbols. */
+    char *strtab;                        /* Pointer to .strtab. */
     struct virtual_region region;        /* symbol, bug.frame patching and
                                             exception table (x86). */
     unsigned int nsyms;                  /* Nr of entries in .strtab and symbols. */
-- 
2.43.0