diff mbox series

[uqmi,v2] uqmi: avoid gcc-12.x false error reporting (storing the address of local variable 'complete' in '*req.complete')

Message ID 20230311114652.23804-1-ps.report@gmx.net
State New
Headers show
Series [uqmi,v2] uqmi: avoid gcc-12.x false error reporting (storing the address of local variable 'complete' in '*req.complete') | expand

Commit Message

Peter Seiderer March 11, 2023, 11:46 a.m. UTC
Avoid gcc-12.x false error reporting (req->complete is later reset to NULL
in case of use of local complete):

  dev.c:217:23: error: storing the address of local variable 'complete' in '*req.complete' [-Werror=dangling-pointer=]
    217 |         req->complete = &complete;
        |         ~~~~~~~~~~~~~~^~~~~~~~~~~

Signed-off-by: Peter Seiderer <ps.report@gmx.net>
---
Changes v1 -> v2:
  - apply pragma ignored only for gcc >= 12.x (as the warning
    '-Wdangling-pointer' was introduced with gcc-12.x)
---
 dev.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
diff mbox series

Patch

diff --git a/dev.c b/dev.c
index bd10207..dbd42d4 100644
--- a/dev.c
+++ b/dev.c
@@ -203,6 +203,15 @@  void qmi_request_cancel(struct qmi_dev *qmi, struct qmi_request *req)
 	__qmi_request_complete(qmi, req, NULL);
 }
 
+/* avoid gcc-12.x false error reporting:
+ *   dev.c:217:23: error: storing the address of local variable ‘complete’ in ‘*req.complete’ [-Werror=dangling-pointer=]
+ *     217 |         req->complete = &complete;
+ *         |         ~~~~~~~~~~~~~~^~~~~~~~~~~
+ */
+#if __GNUC__ >= 12
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdangling-pointer"
+#endif
 int qmi_request_wait(struct qmi_dev *qmi, struct qmi_request *req)
 {
 	bool complete = false;
@@ -231,6 +240,9 @@  int qmi_request_wait(struct qmi_dev *qmi, struct qmi_request *req)
 
 	return req->ret;
 }
+#if __GNUC__ >= 12
+#pragma GCC diagnostic pop
+#endif
 
 struct qmi_connect_request {
 	struct qmi_request req;