[PATCH] uqmi: fix compilation with GCC12

e9hack e9hack at gmail.com
Sat Jun 11 00:04:09 PDT 2022


The 'dangling pointer' issue can be fix without using malloc().

--- a/dev.c	2022-05-04 02:18:17.000000000 +0200
+++ b/dev.c	2022-06-11 08:48:21.185567953 +0200
@@ -206,6 +206,7 @@ void qmi_request_cancel(struct qmi_dev *
  int qmi_request_wait(struct qmi_dev *qmi, struct qmi_request *req)
  {
  	bool complete = false;
+	bool *c;
  	bool cancelled;
  
  	if (!req->pending)
@@ -226,8 +227,10 @@ int qmi_request_wait(struct qmi_dev *qmi
  		uloop_cancelled = cancelled;
  	}
  
-	if (req->complete == &complete)
-		req->complete = NULL;
+	c = req->complete;
+	req->complete = NULL;
+	if (c != &complete)
+		req->complete = c;
  
  	return req->ret;
  }


Am 09.06.2022 um 03:47 schrieb Rosen Penev:
> GCC12 doesn't seem to see that the completed member gets nulled. Use
> malloc to work around this.
> 
> Signed-off-by: Rosen Penev <rosenp at gmail.com>
> ---
>   commands-nas.c | 2 +-
>   dev.c          | 9 +++++----
>   2 files changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/commands-nas.c b/commands-nas.c
> index 476cd61..9c0a626 100644
> --- a/commands-nas.c
> +++ b/commands-nas.c
> @@ -710,7 +710,7 @@ static void
>   cmd_nas_get_cell_location_info_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg)
>   {
>   	struct qmi_nas_get_cell_location_info_response res;
> -	void *c, *t, *cell, *freq;
> +	void *c = NULL, *t, *cell, *freq;
>   	int i, j;
>   
>   	qmi_parse_nas_get_cell_location_info_response(msg, &res);
> diff --git a/dev.c b/dev.c
> index bd10207..b1cf2a3 100644
> --- a/dev.c
> +++ b/dev.c
> @@ -205,7 +205,7 @@ void qmi_request_cancel(struct qmi_dev *qmi, struct qmi_request *req)
>   
>   int qmi_request_wait(struct qmi_dev *qmi, struct qmi_request *req)
>   {
> -	bool complete = false;
> +	bool *complete = malloc(sizeof(bool));
>   	bool cancelled;
>   
>   	if (!req->pending)
> @@ -214,8 +214,8 @@ int qmi_request_wait(struct qmi_dev *qmi, struct qmi_request *req)
>   	if (req->complete)
>   		*req->complete = true;
>   
> -	req->complete = &complete;
> -	while (!complete) {
> +	req->complete = complete;
> +	while (!*complete) {
>   		cancelled = uloop_cancelled;
>   		uloop_cancelled = false;
>   		uloop_run();
> @@ -226,9 +226,10 @@ int qmi_request_wait(struct qmi_dev *qmi, struct qmi_request *req)
>   		uloop_cancelled = cancelled;
>   	}
>   
> -	if (req->complete == &complete)
> +	if (req->complete == complete)
>   		req->complete = NULL;
>   
> +	free(complete);
>   	return req->ret;
>   }
>   




More information about the openwrt-devel mailing list