[Pdbg] [PATCH 2/3] target: Store "fd" for struct pib
Joel Stanley
joel at jms.id.au
Tue May 22 16:06:27 AEST 2018
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>
Signed-off-by: Joel Stanley <joel at jms.id.au>
---
libpdbg/host.c | 25 +++++++++----------------
libpdbg/target.h | 1 +
2 files changed, 10 insertions(+), 16 deletions(-)
diff --git a/libpdbg/host.c b/libpdbg/host.c
index 5e0e08fc330e..44ab6c1933f1 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,32 +83,25 @@ 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 chip_id;
- fd = malloc(sizeof(fd));
- if (!fd)
- return -1;
-
chip_id = dt_get_chip_id(target);
if (chip_id == -1)
- goto out;
+ return -1;
if (asprintf(&access_fn, "%s/%08d/access", XSCOM_BASE_PATH, chip_id) < 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 = {
diff --git a/libpdbg/target.h b/libpdbg/target.h
index db420c742ae5..4a126c83ee60 100644
--- a/libpdbg/target.h
+++ b/libpdbg/target.h
@@ -116,6 +116,7 @@ struct pib {
int (*read)(struct pib *, uint64_t, uint64_t *);
int (*write)(struct pib *, uint64_t, uint64_t);
void *priv;
+ int fd; /* For kernel backend */
};
#define target_to_pib(x) container_of(x, struct pib, target)
--
2.17.0
More information about the Pdbg
mailing list