Skip to content

Commit 9960d75

Browse files
committed
fdtable: remove inappropriate use of POSIX off_t and ssize_t
A shortcut was taken many years ago by "cherry-picking" the POSIX off_t and ssize_t types for use throughout Zephyr. Additionally, the POSIX header fcntl.h, as well as constants defined in that header, were being used inappropriately throughout Zephyr. Doing so created a dependency cycle: below POSIX's position in the stack, code depended on POSIX; above POSIX's position in the stack, code depends on the lower parts. Such dependency cycles usually result in fragility and instability of the software stack. Use the newly defined k_off_t and k_ssize_t types throughout Zephyr's stack, where off_t and ssize_t were previously used inappropriately. Additionally, use ZVFS-prefixed constants instead of their POSIX counterparts. Additionally, where appropriate, ensure the POSIX fcntl.h header is prefixed with <zephyr/posix/fcntl.h>. We effectively create a mutual dependency to resolve the cyclic dependency, as described in GitHub issue zephyrproject-rtos#51211. For clarification, it is inappropriate to use POSIX types or functions within the kernel, core OS, OS services, or really anywhere that is not equal to or above POSIX's position in the software stack. In other words, if a library uses POSIX, Zephyr's POSIX implementation cannot depend on that library. Similarly, if a system service uses POSIX, Zephyr's POSIX implementation cannot depend on that system service. Signed-off-by: Chris Friedt <[email protected]>
1 parent 38d2805 commit 9960d75

File tree

396 files changed

+1904
-2037
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

396 files changed

+1904
-2037
lines changed

drivers/bluetooth/hci/userchan.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ static void rx_thread(void *p1, void *p2, void *p3)
188188
struct net_buf *buf;
189189
size_t buf_tailroom;
190190
size_t buf_add_len;
191-
ssize_t len;
191+
k_ssize_t len;
192192
const uint8_t *frame_start = frame;
193193

194194
if (!uc_ready(uc->fd)) {

drivers/disk/flashdisk.c

+12-11
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ struct flashdisk_data {
2828
struct disk_info info;
2929
struct k_mutex lock;
3030
const unsigned int area_id;
31-
const off_t offset;
31+
const k_off_t offset;
3232
uint8_t *const cache;
3333
const size_t cache_size;
3434
const size_t size;
3535
const size_t sector_size;
3636
size_t page_size;
37-
off_t cached_addr;
37+
k_off_t cached_addr;
3838
bool cache_valid;
3939
bool cache_dirty;
4040
bool erase_required;
@@ -89,7 +89,7 @@ static int flashdisk_init_runtime(struct flashdisk_data *ctx,
8989
{
9090
int rc;
9191
struct flash_pages_info page;
92-
off_t offset;
92+
k_off_t offset;
9393

9494
flashdisk_probe_erase(ctx);
9595

@@ -126,7 +126,8 @@ static int flashdisk_init_runtime(struct flashdisk_data *ctx,
126126
while (offset < ctx->offset + ctx->size) {
127127
rc = flash_get_page_info_by_offs(ctx->info.dev, offset, &page);
128128
if (rc < 0) {
129-
LOG_ERR("Error %d getting page info at offset %lx", rc, offset);
129+
LOG_ERR("Error %d getting page info at offset %lx", rc,
130+
(long)offset);
130131
return rc;
131132
}
132133
if (page.size != ctx->page_size) {
@@ -200,7 +201,7 @@ static int disk_flash_access_read(struct disk_info *disk, uint8_t *buff,
200201
uint32_t start_sector, uint32_t sector_count)
201202
{
202203
struct flashdisk_data *ctx;
203-
off_t fl_addr;
204+
k_off_t fl_addr;
204205
uint32_t remaining;
205206
uint32_t offset;
206207
uint32_t len;
@@ -272,7 +273,7 @@ static int flashdisk_cache_commit(struct flashdisk_data *ctx)
272273
return 0;
273274
}
274275

275-
static int flashdisk_cache_load(struct flashdisk_data *ctx, off_t fl_addr)
276+
static int flashdisk_cache_load(struct flashdisk_data *ctx, k_off_t fl_addr)
276277
{
277278
int rc;
278279

@@ -308,11 +309,11 @@ static int flashdisk_cache_load(struct flashdisk_data *ctx, off_t fl_addr)
308309
/* input size is either less or equal to a block size (ctx->page_size)
309310
* and write data never spans across adjacent blocks.
310311
*/
311-
static int flashdisk_cache_write(struct flashdisk_data *ctx, off_t start_addr,
312-
uint32_t size, const void *buff)
312+
static int flashdisk_cache_write(struct flashdisk_data *ctx, k_off_t start_addr, uint32_t size,
313+
const void *buff)
313314
{
314315
int rc;
315-
off_t fl_addr;
316+
k_off_t fl_addr;
316317
uint32_t offset;
317318

318319
/* adjust offset if starting address is not erase-aligned address */
@@ -347,7 +348,7 @@ static int disk_flash_access_write(struct disk_info *disk, const uint8_t *buff,
347348
uint32_t start_sector, uint32_t sector_count)
348349
{
349350
struct flashdisk_data *ctx;
350-
off_t fl_addr;
351+
k_off_t fl_addr;
351352
uint32_t remaining;
352353
uint32_t size;
353354
int rc = 0;
@@ -369,7 +370,7 @@ static int disk_flash_access_write(struct disk_info *disk, const uint8_t *buff,
369370

370371
/* check if start address is erased-aligned address */
371372
if (fl_addr & (ctx->page_size - 1)) {
372-
off_t block_bnd;
373+
k_off_t block_bnd;
373374

374375
/* not aligned */
375376
/* check if the size goes over flash block boundary */

drivers/display/display_hx8394.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ const uint8_t hx8394_cmd3[] = {0xC6U, 0xEDU};
406406

407407
const uint8_t tear_config[] = {HX8394_SET_TEAR, HX8394_TEAR_VBLANK};
408408

409-
static ssize_t hx8394_mipi_tx(const struct device *mipi_dev, uint8_t channel,
409+
static k_ssize_t hx8394_mipi_tx(const struct device *mipi_dev, uint8_t channel,
410410
const void *buf, size_t len)
411411
{
412412
/* Send MIPI transfers using low power mode */

drivers/eeprom/eeprom_at2x.c

+10-21
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ static inline int eeprom_at2x_write_enable(const struct device *dev)
8888
}
8989
#endif /* ANY_INST_HAS_WP_GPIOS */
9090

91-
static int eeprom_at2x_read(const struct device *dev, off_t offset, void *buf,
92-
size_t len)
91+
static int eeprom_at2x_read(const struct device *dev, k_off_t offset, void *buf, size_t len)
9392
{
9493
const struct eeprom_at2x_config *config = dev->config;
9594
struct eeprom_at2x_data *data = dev->data;
@@ -124,13 +123,11 @@ static int eeprom_at2x_read(const struct device *dev, off_t offset, void *buf,
124123
return 0;
125124
}
126125

127-
static size_t eeprom_at2x_limit_write_count(const struct device *dev,
128-
off_t offset,
129-
size_t len)
126+
static size_t eeprom_at2x_limit_write_count(const struct device *dev, k_off_t offset, size_t len)
130127
{
131128
const struct eeprom_at2x_config *config = dev->config;
132129
size_t count = len;
133-
off_t page_boundary;
130+
k_off_t page_boundary;
134131

135132
/* We can at most write one page at a time */
136133
if (count > config->pagesize) {
@@ -146,9 +143,7 @@ static size_t eeprom_at2x_limit_write_count(const struct device *dev,
146143
return count;
147144
}
148145

149-
static int eeprom_at2x_write(const struct device *dev, off_t offset,
150-
const void *buf,
151-
size_t len)
146+
static int eeprom_at2x_write(const struct device *dev, k_off_t offset, const void *buf, size_t len)
152147
{
153148
const struct eeprom_at2x_config *config = dev->config;
154149
struct eeprom_at2x_data *data = dev->data;
@@ -233,8 +228,7 @@ static bool eeprom_at24_bus_is_ready(const struct device *dev)
233228
* but also to address higher part of eeprom for chips
234229
* with more than 2^(addr_width) adressable word.
235230
*/
236-
static uint16_t eeprom_at24_translate_offset(const struct device *dev,
237-
off_t *offset)
231+
static uint16_t eeprom_at24_translate_offset(const struct device *dev, k_off_t *offset)
238232
{
239233
const struct eeprom_at2x_config *config = dev->config;
240234

@@ -244,8 +238,7 @@ static uint16_t eeprom_at24_translate_offset(const struct device *dev,
244238
return config->bus.i2c.addr + addr_incr;
245239
}
246240

247-
static size_t eeprom_at24_adjust_read_count(const struct device *dev,
248-
off_t offset, size_t len)
241+
static size_t eeprom_at24_adjust_read_count(const struct device *dev, k_off_t offset, size_t len)
249242
{
250243
const struct eeprom_at2x_config *config = dev->config;
251244
const size_t remainder = BIT(config->addr_width) - offset;
@@ -257,8 +250,7 @@ static size_t eeprom_at24_adjust_read_count(const struct device *dev,
257250
return len;
258251
}
259252

260-
static int eeprom_at24_read(const struct device *dev, off_t offset, void *buf,
261-
size_t len)
253+
static int eeprom_at24_read(const struct device *dev, k_off_t offset, void *buf, size_t len)
262254
{
263255
const struct eeprom_at2x_config *config = dev->config;
264256
int64_t timeout;
@@ -299,8 +291,7 @@ static int eeprom_at24_read(const struct device *dev, off_t offset, void *buf,
299291
return len;
300292
}
301293

302-
static int eeprom_at24_write(const struct device *dev, off_t offset,
303-
const void *buf, size_t len)
294+
static int eeprom_at24_write(const struct device *dev, k_off_t offset, const void *buf, size_t len)
304295
{
305296
const struct eeprom_at2x_config *config = dev->config;
306297
int count = eeprom_at2x_limit_write_count(dev, offset, len);
@@ -415,8 +406,7 @@ static int eeprom_at25_wait_for_idle(const struct device *dev)
415406
return -EBUSY;
416407
}
417408

418-
static int eeprom_at25_read(const struct device *dev, off_t offset, void *buf,
419-
size_t len)
409+
static int eeprom_at25_read(const struct device *dev, k_off_t offset, void *buf, size_t len)
420410
{
421411
const struct eeprom_at2x_config *config = dev->config;
422412
struct eeprom_at2x_data *data = dev->data;
@@ -502,8 +492,7 @@ static int eeprom_at25_wren(const struct device *dev)
502492
return spi_write_dt(&config->bus.spi, &tx);
503493
}
504494

505-
static int eeprom_at25_write(const struct device *dev, off_t offset,
506-
const void *buf, size_t len)
495+
static int eeprom_at25_write(const struct device *dev, k_off_t offset, const void *buf, size_t len)
507496
{
508497
const struct eeprom_at2x_config *config = dev->config;
509498
int count = eeprom_at2x_limit_write_count(dev, offset, len);

drivers/eeprom/eeprom_emulator.c

+24-24
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ struct eeprom_emu_config {
7474
*/
7575
size_t page_size;
7676
/* Offset of the flash partition used to emulate the EEPROM */
77-
off_t flash_offset;
77+
k_off_t flash_offset;
7878
/* Size of the flash partition to emulate the EEPROM */
7979
size_t flash_size;
8080
/* Delay the erase of EEPROM pages until the complete partition is used.
@@ -89,24 +89,24 @@ struct eeprom_emu_config {
8989

9090
struct eeprom_emu_data {
9191
/* Offset in current (EEPROM) page where next change is written */
92-
off_t write_offset;
92+
k_off_t write_offset;
9393
/* Offset of the current (EEPROM) page */
94-
off_t page_offset;
94+
k_off_t page_offset;
9595
struct k_mutex lock;
9696
};
9797

9898
/* read/write context */
9999
struct eeprom_emu_ctx {
100100
const void *data; /* pointer to data */
101101
const size_t len; /* data length */
102-
const off_t address; /* eeprom address */
102+
const k_off_t address; /* eeprom address */
103103
size_t rlen; /* data remaining (unprocessed) length */
104104
};
105105

106106
/*
107107
* basic flash read, only used with offset aligned to flash write block size
108108
*/
109-
static inline int eeprom_emu_flash_read(const struct device *dev, off_t offset,
109+
static inline int eeprom_emu_flash_read(const struct device *dev, k_off_t offset,
110110
uint8_t *blk, size_t len)
111111
{
112112
const struct eeprom_emu_config *dev_config = dev->config;
@@ -118,7 +118,7 @@ static inline int eeprom_emu_flash_read(const struct device *dev, off_t offset,
118118
/*
119119
* basic flash write, only used with offset aligned to flash write block size
120120
*/
121-
static inline int eeprom_emu_flash_write(const struct device *dev, off_t offset,
121+
static inline int eeprom_emu_flash_write(const struct device *dev, k_off_t offset,
122122
const uint8_t *blk, size_t len)
123123
{
124124
const struct eeprom_emu_config *dev_config = dev->config;
@@ -133,7 +133,7 @@ static inline int eeprom_emu_flash_write(const struct device *dev, off_t offset,
133133
* basic flash erase, only used with offset aligned to flash page and len a
134134
* multiple of the flash page size
135135
*/
136-
static inline int eeprom_emu_flash_erase(const struct device *dev, off_t offset,
136+
static inline int eeprom_emu_flash_erase(const struct device *dev, k_off_t offset,
137137
size_t len)
138138
{
139139
const struct eeprom_emu_config *dev_config = dev->config;
@@ -147,7 +147,7 @@ static inline int eeprom_emu_flash_erase(const struct device *dev, off_t offset,
147147
/*
148148
* eeprom_emu_page_invalidate: invalidate a page by writing all zeros at the end
149149
*/
150-
static int eeprom_emu_page_invalidate(const struct device *dev, off_t offset)
150+
static int eeprom_emu_page_invalidate(const struct device *dev, k_off_t offset)
151151
{
152152
const struct eeprom_emu_config *dev_config = dev->config;
153153
uint8_t buf[dev_config->flash_cbs];
@@ -227,13 +227,13 @@ static int eeprom_emu_is_word_used(const struct device *dev, const uint8_t *blk)
227227
* eeprom_emu_word_read: read basic word (cbs byte of data) item from
228228
* address directly from flash.
229229
*/
230-
static int eeprom_emu_word_read(const struct device *dev, off_t address,
230+
static int eeprom_emu_word_read(const struct device *dev, k_off_t address,
231231
uint8_t *data)
232232
{
233233
const struct eeprom_emu_config *dev_config = dev->config;
234234
const struct eeprom_emu_data *dev_data = dev->data;
235235
uint8_t buf[dev_config->flash_cbs];
236-
off_t direct_address;
236+
k_off_t direct_address;
237237
int rc;
238238

239239
direct_address = dev_data->page_offset + address;
@@ -245,7 +245,7 @@ static int eeprom_emu_word_read(const struct device *dev, off_t address,
245245
}
246246

247247
/* Process changes written to flash */
248-
off_t offset, ch_address;
248+
k_off_t offset, ch_address;
249249
bool mc1 = false, mc2 = false;
250250

251251
offset = dev_data->write_offset;
@@ -280,10 +280,10 @@ static int eeprom_emu_flash_get(const struct device *dev,
280280
struct eeprom_emu_ctx *ctx)
281281
{
282282
const struct eeprom_emu_config *dev_config = dev->config;
283-
off_t address = ctx->address + ctx->len - ctx->rlen;
283+
k_off_t address = ctx->address + ctx->len - ctx->rlen;
284284
uint8_t *data8 = (uint8_t *)(ctx->data);
285285
uint8_t buf[dev_config->flash_cbs];
286-
const off_t addr_jmp = address & (sizeof(buf) - 1);
286+
const k_off_t addr_jmp = address & (sizeof(buf) - 1);
287287
size_t len;
288288
int rc;
289289

@@ -310,7 +310,7 @@ static int eeprom_emu_compactor(const struct device *dev,
310310
{
311311
const struct eeprom_emu_config *dev_config = dev->config;
312312
struct eeprom_emu_data *dev_data = dev->data;
313-
off_t next_page_offset;
313+
k_off_t next_page_offset;
314314
int rc = 0;
315315

316316
LOG_DBG("Compactor called for page at [0x%tx]",
@@ -347,7 +347,7 @@ static int eeprom_emu_compactor(const struct device *dev,
347347

348348
ctx->rlen = 0;
349349
} else {
350-
off_t rd_offset = 0;
350+
k_off_t rd_offset = 0;
351351
uint8_t buf[dev_config->flash_cbs];
352352

353353
/* reset the context if available */
@@ -367,7 +367,7 @@ static int eeprom_emu_compactor(const struct device *dev,
367367
(rd_offset > (ctx->address - sizeof(buf)))) {
368368
/* overwrite buf data with context data */
369369
uint8_t *data8 = (uint8_t *)(ctx->data);
370-
off_t address, addr_jmp;
370+
k_off_t address, addr_jmp;
371371
size_t len;
372372

373373
address = ctx->address + ctx->len - ctx->rlen;
@@ -412,14 +412,14 @@ static int eeprom_emu_compactor(const struct device *dev,
412412
/*
413413
* eeprom_emu_word_write: write basic word (cbs bytes of data) item to address,
414414
*/
415-
static int eeprom_emu_word_write(const struct device *dev, off_t address,
415+
static int eeprom_emu_word_write(const struct device *dev, k_off_t address,
416416
const uint8_t *data,
417417
struct eeprom_emu_ctx *ctx)
418418
{
419419
const struct eeprom_emu_config *dev_config = dev->config;
420420
struct eeprom_emu_data *dev_data = dev->data;
421421
uint8_t buf[dev_config->flash_cbs], tmp[dev_config->flash_cbs];
422-
off_t direct_address, wraddr;
422+
k_off_t direct_address, wraddr;
423423
int rc;
424424

425425
direct_address = dev_data->page_offset + address;
@@ -482,10 +482,10 @@ static int eeprom_emu_flash_set(const struct device *dev,
482482
struct eeprom_emu_ctx *ctx)
483483
{
484484
const struct eeprom_emu_config *dev_config = dev->config;
485-
off_t address = ctx->address + ctx->len - ctx->rlen;
485+
k_off_t address = ctx->address + ctx->len - ctx->rlen;
486486
uint8_t *data8 = (uint8_t *)(ctx->data);
487487
uint8_t buf[dev_config->flash_cbs];
488-
const off_t addr_jmp = address & (sizeof(buf) - 1);
488+
const k_off_t addr_jmp = address & (sizeof(buf) - 1);
489489
size_t len;
490490
int rc;
491491

@@ -509,7 +509,7 @@ static int eeprom_emu_flash_set(const struct device *dev,
509509
return rc;
510510
}
511511

512-
static int eeprom_emu_range_is_valid(const struct device *dev, off_t address,
512+
static int eeprom_emu_range_is_valid(const struct device *dev, k_off_t address,
513513
size_t len)
514514
{
515515
const struct eeprom_emu_config *dev_config = dev->config;
@@ -521,7 +521,7 @@ static int eeprom_emu_range_is_valid(const struct device *dev, off_t address,
521521
return 0;
522522
}
523523

524-
static int eeprom_emu_read(const struct device *dev, off_t address, void *data,
524+
static int eeprom_emu_read(const struct device *dev, k_off_t address, void *data,
525525
size_t len)
526526
{
527527
const struct eeprom_emu_config *dev_config = dev->config;
@@ -572,7 +572,7 @@ static int eeprom_emu_read(const struct device *dev, off_t address, void *data,
572572
return rc;
573573
}
574574

575-
static int eeprom_emu_write(const struct device *dev, off_t address,
575+
static int eeprom_emu_write(const struct device *dev, k_off_t address,
576576
const void *data, size_t len)
577577
{
578578
const struct eeprom_emu_config *dev_config = dev->config;
@@ -640,7 +640,7 @@ static int eeprom_emu_init(const struct device *dev)
640640
{
641641
const struct eeprom_emu_config *dev_config = dev->config;
642642
struct eeprom_emu_data *dev_data = dev->data;
643-
off_t offset;
643+
k_off_t offset;
644644
uint8_t buf[dev_config->flash_cbs];
645645
int rc = 0;
646646

0 commit comments

Comments
 (0)