Skip to content

Commit 5b67ddd

Browse files
committed
iio-private: Update ERR_PTR / PTR_ERR
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]>
1 parent 5d5780f commit 5b67ddd

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

context.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,17 @@ static char * iio_context_create_xml(const struct iio_context *ctx)
155155

156156
len = iio_snprintf_context_xml(NULL, 0, ctx);
157157
if (len < 0)
158-
return ERR_TO_PTR(len);
158+
return ERR_PTR((int) len);
159159

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

165165
len = iio_snprintf_context_xml(str, len, ctx);
166166
if (len < 0) {
167167
free(str);
168-
return ERR_TO_PTR(len);
168+
return ERR_PTR((int) len);
169169
}
170170

171171
return str;
@@ -328,7 +328,7 @@ int iio_context_init(struct iio_context *ctx)
328328
if (!ctx->xml) {
329329
ctx->xml = iio_context_create_xml(ctx);
330330
if (IS_ERR(ctx->xml))
331-
return PTR_TO_ERR(ctx->xml);
331+
return PTR_ERR(ctx->xml);
332332
}
333333

334334
return 0;

iio-private.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,14 @@ static inline __check_ret bool IS_ERR(const void *ptr)
106106
return (uintptr_t)ptr >= (uintptr_t)-4095;
107107
}
108108

109-
static inline __check_ret intptr_t PTR_TO_ERR(const void *ptr)
109+
static inline __check_ret int PTR_ERR(const void *ptr)
110110
{
111-
return (intptr_t)ptr;
111+
return (int)(intptr_t) ptr;
112112
}
113113

114-
static inline __check_ret void * ERR_TO_PTR(intptr_t err)
114+
static inline __check_ret void * ERR_PTR(int err)
115115
{
116-
return (void *)err;
116+
return (void *)(intptr_t) err;
117117
}
118118

119119
/*

xml.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ static struct iio_channel * create_channel(struct iio_device *dev, xmlNode *n)
176176

177177
chn = zalloc(sizeof(*chn));
178178
if (!chn)
179-
return ERR_TO_PTR(-ENOMEM);
179+
return ERR_PTR(-ENOMEM);
180180

181181
chn->dev = dev;
182182

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

235235
err_free_channel:
236236
free_channel(chn);
237-
return ERR_TO_PTR(err);
237+
return ERR_PTR(err);
238238
}
239239

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

246246
dev = zalloc(sizeof(*dev));
247247
if (!dev)
248-
return ERR_TO_PTR(-ENOMEM);
248+
return ERR_PTR(-ENOMEM);
249249

250250
dev->ctx = ctx;
251251

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

329329
err_free_device:
330330
free_device(dev);
331-
return ERR_TO_PTR(err);
331+
332+
return ERR_PTR(err);
332333
}
333334

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

390391
dev = create_device(ctx, n);
391392
if (IS_ERR(dev)) {
392-
err = PTR_TO_ERR(dev);
393+
err = PTR_ERR(dev);
393394
IIO_ERROR("Unable to create device: %d\n", err);
394395
return err;
395396
}

0 commit comments

Comments
 (0)