[Pdbg] [PATCH 3/7] target: Store "fd" for struct pib
Amitay Isaacs
amitay at ozlabs.org
Wed Apr 10 18:08:50 AEST 2019
From: Benjamin Herrenschmidt <benh at kernel.crashing.org>
Almost all backends use a file descriptor, put it directly
in struct pib rather than allocating 4 bytes and use an untyped
pointer.
Convert the host scom backend to use it
Signed-off-by: Benjamin Herrenschmidt <benh at kernel.crashing.org>
---
libpdbg/cfam.c | 1 +
libpdbg/fake.c | 1 +
libpdbg/host.c | 24 +++++++++---------------
libpdbg/i2c.c | 1 +
libpdbg/target.h | 1 +
5 files changed, 13 insertions(+), 15 deletions(-)
diff --git a/libpdbg/cfam.c b/libpdbg/cfam.c
index c9bdf3b..511f8c0 100644
--- a/libpdbg/cfam.c
+++ b/libpdbg/cfam.c
@@ -124,6 +124,7 @@ static struct pib fsi_pib = {
},
.read = fsi2pib_getscom,
.write = fsi2pib_putscom,
+ .fd = -1,
};
DECLARE_HW_UNIT(fsi_pib);
diff --git a/libpdbg/fake.c b/libpdbg/fake.c
index 0955dc0..a8ebeb2 100644
--- a/libpdbg/fake.c
+++ b/libpdbg/fake.c
@@ -64,6 +64,7 @@ static struct pib fake_pib = {
},
.read = fake_pib_read,
.write = fake_pib_write,
+ .fd = -1,
};
DECLARE_HW_UNIT(fake_pib);
diff --git a/libpdbg/host.c b/libpdbg/host.c
index 163b991..41ad7ea 100644
--- a/libpdbg/host.c
+++ b/libpdbg/host.c
@@ -55,7 +55,7 @@ static uint64_t xscom_mangle_addr(uint64_t addr)
static int xscom_read(struct pib *pib, uint64_t addr, uint64_t *val)
{
int rc;
- int fd = *(int *) pib->priv;
+ int fd = pib->fd;
addr = xscom_mangle_addr(addr);
lseek64(fd, addr, SEEK_SET);
@@ -69,7 +69,7 @@ static int xscom_read(struct pib *pib, uint64_t addr, uint64_t *val)
static int xscom_write(struct pib *pib, uint64_t addr, uint64_t val)
{
int rc;
- int fd = *(int *) pib->priv;
+ int fd = pib->fd;
addr = xscom_mangle_addr(addr);
lseek64(fd, addr, SEEK_SET);
@@ -83,14 +83,10 @@ static int xscom_write(struct pib *pib, uint64_t addr, uint64_t val)
static int host_pib_probe(struct pdbg_target *target)
{
struct pib *pib = target_to_pib(target);
- int *fd;
+ int fd;
char *access_fn;
uint32_t index;
- fd = malloc(sizeof(fd));
- if (!fd)
- return -1;
-
index = pdbg_target_index(target);
/* This check should probably be done earlier */
@@ -102,19 +98,16 @@ static int host_pib_probe(struct pdbg_target *target)
}
if (asprintf(&access_fn, "%s/%08x/access", XSCOM_BASE_PATH, index) < 0)
- goto out;
+ return -1;
- *fd = open(access_fn, O_RDWR);
+ fd = open(access_fn, O_RDWR);
free(access_fn);
- if (*fd < 0)
- goto out;
+ if (fd < 0)
+ return -1;
- pib->priv = fd;
+ pib->fd = fd;
return 0;
-out:
- free(fd);
- return -1;
}
static struct pib host_pib = {
@@ -126,5 +119,6 @@ static struct pib host_pib = {
},
.read = xscom_read,
.write = xscom_write,
+ .fd = -1,
};
DECLARE_HW_UNIT(host_pib);
diff --git a/libpdbg/i2c.c b/libpdbg/i2c.c
index f1c6ea9..ae07146 100644
--- a/libpdbg/i2c.c
+++ b/libpdbg/i2c.c
@@ -165,5 +165,6 @@ static struct pib p8_i2c_pib = {
},
.read = i2c_getscom,
.write = i2c_putscom,
+ .fd = -1,
};
DECLARE_HW_UNIT(p8_i2c_pib);
diff --git a/libpdbg/target.h b/libpdbg/target.h
index 04897ed..6b57142 100644
--- a/libpdbg/target.h
+++ b/libpdbg/target.h
@@ -120,6 +120,7 @@ struct pib {
int (*read)(struct pib *, uint64_t, uint64_t *);
int (*write)(struct pib *, uint64_t, uint64_t);
void *priv;
+ int fd;
};
#define target_to_pib(x) container_of(x, struct pib, target)
--
2.20.1
More information about the Pdbg
mailing list