[Skiboot] [PATCH 3/3] core/i2c: Remove bus specific alloc and free callbacks

Oliver O'Halloran oohall at gmail.com
Thu Aug 23 13:47:32 AEST 2018


These are now pointless and they can be replaced with zalloc() and free().

Signed-off-by: Oliver O'Halloran <oohall at gmail.com>
---
 core/i2c.c                      | 17 +++++++++--------
 hw/p8-i2c.c                     | 10 ----------
 include/i2c.h                   | 12 ------------
 platforms/ibm-fsp/firenze-pci.c |  2 +-
 4 files changed, 10 insertions(+), 31 deletions(-)

diff --git a/core/i2c.c b/core/i2c.c
index b0d5d34bf692..26926fc28d17 100644
--- a/core/i2c.c
+++ b/core/i2c.c
@@ -51,7 +51,7 @@ static void opal_i2c_request_complete(int rc, struct i2c_request *req)
 	uint64_t token = (uint64_t)(unsigned long)req->user_data;
 
 	opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL, token, rc);
-	i2c_free_req(req);
+	free(req);
 }
 
 static int opal_i2c_request(uint64_t async_token, uint32_t bus_id,
@@ -80,7 +80,7 @@ static int opal_i2c_request(uint64_t async_token, uint32_t bus_id,
 		return OPAL_PARAMETER;
 	}
 
-	req = i2c_alloc_req(bus);
+	req = zalloc(sizeof(*req));
 	if (!req) {
 		/**
 		 * @fwts-label I2CFailedAllocation
@@ -110,7 +110,7 @@ static int opal_i2c_request(uint64_t async_token, uint32_t bus_id,
 		req->offset_bytes = oreq->subaddr_sz;
 		break;
 	default:
-		bus->free_req(req);
+		free(req);
 		return OPAL_PARAMETER;
 	}
 	req->dev_addr = oreq->addr;
@@ -121,14 +121,14 @@ static int opal_i2c_request(uint64_t async_token, uint32_t bus_id,
 	req->bus = bus;
 
 	if (i2c_check_quirk(req, &rc)) {
-		i2c_free_req(req);
+		free(req);
 		return rc;
 	}
 
 	/* Finally, queue the OPAL i2c request and return */
 	rc = i2c_queue_req(req);
 	if (rc) {
-		i2c_free_req(req);
+		free(req);
 		return rc;
 	}
 
@@ -189,7 +189,7 @@ int i2c_request_send(int bus_id, int dev_addr, int read_write,
 		return OPAL_PARAMETER;
 	}
 
-	req = i2c_alloc_req(bus);
+	req = zalloc(sizeof(*req));
 	if (!req) {
 		/**
 		 * @fwts-label I2CAllocationFailed
@@ -197,10 +197,11 @@ int i2c_request_send(int bus_id, int dev_addr, int read_write,
 		 * i2c_request. This points to an OPAL bug as OPAL run out of
 		 * memory and this should never happen.
 		 */
-		prlog(PR_ERR, "I2C: i2c_alloc_req failed\n");
+		prlog(PR_ERR, "I2C: allocating i2c_request failed\n");
 		return OPAL_INTERNAL_ERROR;
 	}
 
+	req->bus	= bus;
 	req->dev_addr   = dev_addr;
 	req->op         = read_write;
 	req->offset     = offset;
@@ -239,7 +240,7 @@ int i2c_request_send(int bus_id, int dev_addr, int read_write,
 	      (rc) ? "!!!!" : "----", req->op, req->offset,
 	      *(uint64_t*) buf, req->rw_len, tb_to_msecs(waited), timeout, rc);
 
-	i2c_free_req(req);
+	free(req);
 	if (rc)
 		return OPAL_HARDWARE;
 
diff --git a/hw/p8-i2c.c b/hw/p8-i2c.c
index 67a68cd2a6df..fa5af7cc495f 100644
--- a/hw/p8-i2c.c
+++ b/hw/p8-i2c.c
@@ -1269,14 +1269,6 @@ static int p8_i2c_queue_request(struct i2c_request *req)
 	return rc;
 }
 
-static struct i2c_request *p8_i2c_alloc_request(struct i2c_bus *bus)
-{
-	return zalloc(sizeof(struct i2c_request));
-}
-static void p8_i2c_free_request(struct i2c_request *req)
-{
-	free(req);
-}
 static uint64_t p8_i2c_run_request(struct i2c_request *req)
 {
 	struct i2c_bus *bus = req->bus;
@@ -1604,8 +1596,6 @@ static void p8_i2c_init_one(struct dt_node *i2cm, enum p8_i2c_master_type type)
 			p8_i2c_get_bit_rate_divisor(lb_freq, speed);
 		port->bus.dt_node = i2cm_port;
 		port->bus.queue_req = p8_i2c_queue_request;
-		port->bus.alloc_req = p8_i2c_alloc_request;
-		port->bus.free_req = p8_i2c_free_request;
 		port->bus.run_req = p8_i2c_run_request;
 
 		timeout_ms = dt_prop_get_u32_def(i2cm_port, "timeout-ms",
diff --git a/include/i2c.h b/include/i2c.h
index f33c2d83c195..67f8b995d5db 100644
--- a/include/i2c.h
+++ b/include/i2c.h
@@ -24,8 +24,6 @@ struct i2c_bus {
 	struct dt_node		*dt_node;
 	uint32_t		opal_id;
 	int			(*queue_req)(struct i2c_request *req);
-	struct i2c_request	*(*alloc_req)(struct i2c_bus *bus);
-	void			(*free_req)(struct i2c_request *req);
 	uint64_t		(*run_req)(struct i2c_request *req);
 	int			(*check_quirk)(void *data, struct i2c_request *req, int *rc);
 	void			*check_quirk_data;
@@ -70,16 +68,6 @@ struct i2c_request {
 extern void i2c_add_bus(struct i2c_bus *bus);
 extern struct i2c_bus *i2c_find_bus_by_id(uint32_t opal_id);
 
-static inline struct i2c_request *i2c_alloc_req(struct i2c_bus *bus)
-{
-	return bus->alloc_req(bus);
-}
-
-static inline void i2c_free_req(struct i2c_request *req)
-{
-	req->bus->free_req(req);
-}
-
 static inline int i2c_queue_req(struct i2c_request *req)
 {
 	return req->bus->queue_req(req);
diff --git a/platforms/ibm-fsp/firenze-pci.c b/platforms/ibm-fsp/firenze-pci.c
index 44fa6b5f1532..e075e37f378e 100644
--- a/platforms/ibm-fsp/firenze-pci.c
+++ b/platforms/ibm-fsp/firenze-pci.c
@@ -825,7 +825,7 @@ static void firenze_pci_setup_power_mgt(struct pci_slot *slot,
 	if (!plat_slot->i2c_bus)
 		return;
 
-	plat_slot->req = i2c_alloc_req(plat_slot->i2c_bus);
+	plat_slot->req = zalloc(sizeof(*plat_slot->req));
 	if (!plat_slot->req)
 		return;
 
-- 
2.9.5



More information about the Skiboot mailing list