Linux kernel staging patches
 help / color / mirror / Atom feed
From: Umang Jain <umang.jain@ideasonboard.com>
To: linux-staging@lists.linux.dev
Cc: Stefan Wahren <stefan.wahren@i2se.com>,
	Dan Carpenter <error27@gmail.com>,
	Kieran Bingham <kieran.bingham@ideasonboard.com>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	Phil Elwell <phil@raspberrypi.com>,
	Dave Stevenson <dave.stevenson@raspberrypi.com>,
	Umang Jain <umang.jain@ideasonboard.com>
Subject: [PATCH 3/3] staging: vc04_services: Drop global members for tracking connections
Date: Tue, 12 Mar 2024 04:46:07 +0530	[thread overview]
Message-ID: <20240311231607.124491-4-umang.jain@ideasonboard.com> (raw)
In-Reply-To: <20240311231607.124491-1-umang.jain@ideasonboard.com>

Drop global members for tracking vchiq driver connections in
vchiq_connected.[ch] and use the struct vchiq_connected present
as a part of vchiq platform driver data.

All calls have been adjusted to use the struct vchiq_connected.

Since the non-essential global members have been eliminated,
drop the respective TODO item.

Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
---
 drivers/staging/vc04_services/interface/TODO  |  8 ----
 .../interface/vchiq_arm/vchiq_arm.c           |  2 +-
 .../interface/vchiq_arm/vchiq_connected.c     | 44 +++++++++----------
 .../interface/vchiq_arm/vchiq_connected.h     |  6 ++-
 4 files changed, 26 insertions(+), 34 deletions(-)

diff --git a/drivers/staging/vc04_services/interface/TODO b/drivers/staging/vc04_services/interface/TODO
index 05eb5140d096..15f12b8f213e 100644
--- a/drivers/staging/vc04_services/interface/TODO
+++ b/drivers/staging/vc04_services/interface/TODO
@@ -41,14 +41,6 @@ The code follows the 80 characters limitation yet tends to go 3 or 4 levels of
 indentation deep making it very unpleasant to read. This is specially relevant
 in the character driver ioctl code and in the core thread functions.
 
-* Get rid of all non essential global structures and create a proper per
-device structure
-
-The first thing one generally sees in a probe function is a memory allocation
-for all the device specific data. This structure is then passed all over the
-driver. This is good practice since it makes the driver work regardless of the
-number of devices probed.
-
 * Clean up Sparse warnings from __user annotations. See
 vchiq_irq_queue_bulk_tx_rx(). Ensure that the address of "&waiter->bulk_waiter"
 is never disclosed to userspace.
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
index b8b51267bcde..7daad927207a 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
@@ -560,7 +560,7 @@ static int vchiq_platform_init(struct platform_device *pdev, struct vchiq_state
 	dev_dbg(&pdev->dev, "arm: vchiq_init - done (slots %pK, phys %pad)\n",
 		vchiq_slot_zero, &slot_phys);
 
-	vchiq_call_connected_callbacks();
+	vchiq_call_connected_callbacks(&drvdata->drv_connected);
 
 	return 0;
 }
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_connected.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_connected.c
index 3cad13f09e37..4b79fccaa95e 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_connected.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_connected.c
@@ -6,19 +6,13 @@
 #include <linux/module.h>
 #include <linux/mutex.h>
 
-#define  MAX_CALLBACKS  10
-
-static   int                        g_connected;
-static   int                        g_num_deferred_callbacks;
-static   void (*g_deferred_callback[MAX_CALLBACKS])(void);
-static   int                        g_once_init;
 static   DEFINE_MUTEX(g_connected_mutex);
 
 /* Function to initialize our lock */
-static void connected_init(void)
+static void connected_init(struct vchiq_connected *drv_connected)
 {
-	if (!g_once_init)
-		g_once_init = 1;
+	if (!drv_connected->once_init)
+		drv_connected->once_init = 1;
 }
 
 /*
@@ -27,25 +21,29 @@ static void connected_init(void)
  * be made immediately, otherwise it will be deferred until
  * vchiq_call_connected_callbacks is called.
  */
-void vchiq_add_connected_callback(struct vchiq_device *device, void (*callback)(void))
+void vchiq_add_connected_callback(struct vchiq_device *device,
+				  void (*callback)(void),
+				  struct vchiq_connected *drv_connected)
 {
-	connected_init();
+	unsigned int index;
+
+	connected_init(drv_connected);
 
 	if (mutex_lock_killable(&g_connected_mutex))
 		return;
 
-	if (g_connected) {
+	if (drv_connected->connected) {
 		/* We're already connected. Call the callback immediately. */
 		callback();
 	} else {
-		if (g_num_deferred_callbacks >= MAX_CALLBACKS) {
+		if (drv_connected->num_deferred_callbacks >= VCHIQ_DRV_MAX_CALLBACKS) {
 			dev_err(&device->dev,
 				"core: There already %d callback registered - please increase MAX_CALLBACKS\n",
-				g_num_deferred_callbacks);
+				drv_connected->num_deferred_callbacks);
 		} else {
-			g_deferred_callback[g_num_deferred_callbacks] =
-				callback;
-			g_num_deferred_callbacks++;
+			index = drv_connected->num_deferred_callbacks;
+			drv_connected->deferred_callback[index] = callback;
+			drv_connected->num_deferred_callbacks++;
 		}
 	}
 	mutex_unlock(&g_connected_mutex);
@@ -56,19 +54,19 @@ EXPORT_SYMBOL(vchiq_add_connected_callback);
  * This function is called by the vchiq stack once it has been connected to
  * the videocore and clients can start to use the stack.
  */
-void vchiq_call_connected_callbacks(void)
+void vchiq_call_connected_callbacks(struct vchiq_connected *drv_connected)
 {
 	int i;
 
-	connected_init();
+	connected_init(drv_connected);
 
 	if (mutex_lock_killable(&g_connected_mutex))
 		return;
 
-	for (i = 0; i <  g_num_deferred_callbacks; i++)
-		g_deferred_callback[i]();
+	for (i = 0; i < drv_connected->num_deferred_callbacks; i++)
+		drv_connected->deferred_callback[i]();
 
-	g_num_deferred_callbacks = 0;
-	g_connected = 1;
+	drv_connected->num_deferred_callbacks = 0;
+	drv_connected->connected = 1;
 	mutex_unlock(&g_connected_mutex);
 }
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_connected.h b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_connected.h
index cb5cba94dd54..f40d68fc44df 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_connected.h
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_connected.h
@@ -16,7 +16,9 @@ struct vchiq_connected {
 	void (*deferred_callback[VCHIQ_DRV_MAX_CALLBACKS])(void);
 };
 
-void vchiq_add_connected_callback(struct vchiq_device *device, void (*callback)(void));
-void vchiq_call_connected_callbacks(void);
+void vchiq_add_connected_callback(struct vchiq_device *device, void (*callback)(void),
+				  struct vchiq_connected *drv_connected);
+void vchiq_call_connected_callbacks(struct vchiq_connected *drv_connected);
+
 
 #endif /* VCHIQ_CONNECTED_H */
-- 
2.43.0


  parent reply	other threads:[~2024-03-11 23:16 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-11 23:16 [PATCH 0/3] staging: vc04_services: Drop remaining global members Umang Jain
2024-03-11 23:16 ` [PATCH 1/3] staging: vc04_services: Move struct vchiq_drvdata to vchiq_core header Umang Jain
2024-03-11 23:16 ` [PATCH 2/3] staging: v04_services: Add connection structure to driver data Umang Jain
2024-03-13  5:28   ` Dan Carpenter
2024-03-11 23:16 ` Umang Jain [this message]
2024-03-13  5:31   ` [PATCH 3/3] staging: vc04_services: Drop global members for tracking connections Dan Carpenter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240311231607.124491-4-umang.jain@ideasonboard.com \
    --to=umang.jain@ideasonboard.com \
    --cc=dave.stevenson@raspberrypi.com \
    --cc=error27@gmail.com \
    --cc=kieran.bingham@ideasonboard.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-staging@lists.linux.dev \
    --cc=phil@raspberrypi.com \
    --cc=stefan.wahren@i2se.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).