Skip to content

Commit

Permalink
iio-private: Update ERR_PTR / PTR_ERR
Browse files Browse the repository at this point in the history
Change ERR_TO_PTR / PTR_TO_ERR to simply ERR_PTR / PTR_ERR, since most
people are used to these macro names.

These functions now handle errors as being int-typed instead of
intptr_t, which had to be casted pretty much everywhere.

Signed-off-by: Paul Cercueil <[email protected]>
  • Loading branch information
pcercuei committed Jun 25, 2021
1 parent 5d5780f commit 5b67ddd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
8 changes: 4 additions & 4 deletions context.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,17 @@ static char * iio_context_create_xml(const struct iio_context *ctx)

len = iio_snprintf_context_xml(NULL, 0, ctx);
if (len < 0)
return ERR_TO_PTR(len);
return ERR_PTR((int) len);

len++; /* room for terminating NULL */
str = malloc(len);
if (!str)
return ERR_TO_PTR(-ENOMEM);
return ERR_PTR(-ENOMEM);

len = iio_snprintf_context_xml(str, len, ctx);
if (len < 0) {
free(str);
return ERR_TO_PTR(len);
return ERR_PTR((int) len);
}

return str;
Expand Down Expand Up @@ -328,7 +328,7 @@ int iio_context_init(struct iio_context *ctx)
if (!ctx->xml) {
ctx->xml = iio_context_create_xml(ctx);
if (IS_ERR(ctx->xml))
return PTR_TO_ERR(ctx->xml);
return PTR_ERR(ctx->xml);
}

return 0;
Expand Down
8 changes: 4 additions & 4 deletions iio-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ static inline __check_ret bool IS_ERR(const void *ptr)
return (uintptr_t)ptr >= (uintptr_t)-4095;
}

static inline __check_ret intptr_t PTR_TO_ERR(const void *ptr)
static inline __check_ret int PTR_ERR(const void *ptr)
{
return (intptr_t)ptr;
return (int)(intptr_t) ptr;
}

static inline __check_ret void * ERR_TO_PTR(intptr_t err)
static inline __check_ret void * ERR_PTR(int err)
{
return (void *)err;
return (void *)(intptr_t) err;
}

/*
Expand Down
13 changes: 7 additions & 6 deletions xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ static struct iio_channel * create_channel(struct iio_device *dev, xmlNode *n)

chn = zalloc(sizeof(*chn));
if (!chn)
return ERR_TO_PTR(-ENOMEM);
return ERR_PTR(-ENOMEM);

chn->dev = dev;

Expand Down Expand Up @@ -234,7 +234,7 @@ static struct iio_channel * create_channel(struct iio_device *dev, xmlNode *n)

err_free_channel:
free_channel(chn);
return ERR_TO_PTR(err);
return ERR_PTR(err);
}

static struct iio_device * create_device(struct iio_context *ctx, xmlNode *n)
Expand All @@ -245,7 +245,7 @@ static struct iio_device * create_device(struct iio_context *ctx, xmlNode *n)

dev = zalloc(sizeof(*dev));
if (!dev)
return ERR_TO_PTR(-ENOMEM);
return ERR_PTR(-ENOMEM);

dev->ctx = ctx;

Expand Down Expand Up @@ -280,7 +280,7 @@ static struct iio_device * create_device(struct iio_context *ctx, xmlNode *n)
struct iio_channel **chns,
*chn = create_channel(dev, n);
if (IS_ERR(chn)) {
err = PTR_TO_ERR(chn);
err = PTR_ERR(chn);
IIO_ERROR("Unable to create channel: %d\n", err);
goto err_free_device;
}
Expand Down Expand Up @@ -328,7 +328,8 @@ static struct iio_device * create_device(struct iio_context *ctx, xmlNode *n)

err_free_device:
free_device(dev);
return ERR_TO_PTR(err);

return ERR_PTR(err);
}

static struct iio_context * xml_clone(const struct iio_context *ctx)
Expand Down Expand Up @@ -389,7 +390,7 @@ static int iio_populate_xml_context_helper(struct iio_context *ctx, xmlNode *roo

dev = create_device(ctx, n);
if (IS_ERR(dev)) {
err = PTR_TO_ERR(dev);
err = PTR_ERR(dev);
IIO_ERROR("Unable to create device: %d\n", err);
return err;
}
Expand Down

0 comments on commit 5b67ddd

Please sign in to comment.