Skip to content

Commit

Permalink
core/i2c: Remove bus specific alloc and free callbacks
Browse files Browse the repository at this point in the history
These are now pointless and they can be replaced with zalloc() and free().

Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
  • Loading branch information
oohal authored and stewartsmith committed Sep 18, 2018
1 parent bb27c72 commit 801462f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 31 deletions.
17 changes: 9 additions & 8 deletions core/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -189,18 +189,19 @@ 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
* @fwts-advice OPAL failed to allocate memory for an
* 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;
Expand Down Expand Up @@ -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;

Expand Down
10 changes: 0 additions & 10 deletions hw/p8-i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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",
Expand Down
12 changes: 0 additions & 12 deletions include/i2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion platforms/ibm-fsp/firenze-pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 801462f

Please sign in to comment.