Skip to content

Commit 293ab5a

Browse files
Merge branch 'ps2dev:master' into dev
2 parents b0eba0a + 0c36f32 commit 293ab5a

4 files changed

Lines changed: 31 additions & 14 deletions

File tree

‎ee/libcglue/src/fdman.c‎

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,28 @@ void __fdman_deinit()
8888
int __fdman_get_new_descriptor()
8989
{
9090
int i = 0;
91+
int j = 0;
92+
int k = 0;
9193

9294
WaitSema(__fdman_sema); /* lock here to make thread safe */
9395
for (i = 0; i < __FILENO_MAX; i++) {
94-
if (__descriptormap[i] == NULL) {
95-
__descriptormap[i] = &__descriptor_data_pool[i];
96-
__descriptormap[i]->ref_count++;
97-
SignalSema(__fdman_sema); /* release lock */
98-
return i;
96+
if (__descriptormap[i] != NULL) {
97+
continue;
98+
}
99+
/* The pool entry with the same index can still be used by a duplicated descriptor, so use one that nobody points to. */
100+
for (j = 0; j < __FILENO_MAX; j++) {
101+
for (k = 0; k < __FILENO_MAX; k++) {
102+
if (__descriptormap[k] == &__descriptor_data_pool[j]) {
103+
break;
104+
}
105+
}
106+
if (k == __FILENO_MAX) {
107+
memset(&__descriptor_data_pool[j], 0, sizeof(__descriptormap_type));
108+
__descriptormap[i] = &__descriptor_data_pool[j];
109+
__descriptormap[i]->ref_count = 1;
110+
SignalSema(__fdman_sema); /* release lock */
111+
return i;
112+
}
99113
}
100114
}
101115
SignalSema(__fdman_sema); /* release lock */
@@ -119,7 +133,7 @@ int __fdman_get_dup_descriptor(int fd)
119133
WaitSema(__fdman_sema); /* lock here to make thread safe */
120134
for (i = 0; i < __FILENO_MAX; i++) {
121135
if (__descriptormap[i] == NULL) {
122-
__descriptormap[i] = &__descriptor_data_pool[fd];
136+
__descriptormap[i] = __descriptormap[fd];
123137
__descriptormap[i]->ref_count++;
124138
SignalSema(__fdman_sema); /* release lock */
125139
return i;
@@ -135,13 +149,13 @@ int __fdman_get_dup_descriptor(int fd)
135149
#ifdef F___fdman_get_dup_descriptor
136150
int __fdman_get_dup2_descriptor(int fd, int newfd)
137151
{
138-
if (!__IS_FD_VALID(fd)) {
152+
if (!__IS_FD_VALID(fd) || newfd < 0 || newfd >= __FILENO_MAX) {
139153
errno = EBADF;
140154
return -1;
141155
}
142156

143157
WaitSema(__fdman_sema); /* lock here to make thread safe */
144-
__descriptormap[newfd] = &__descriptor_data_pool[fd];
158+
__descriptormap[newfd] = __descriptormap[fd];
145159
__descriptormap[newfd]->ref_count++;
146160
SignalSema(__fdman_sema); /* release lock */
147161

‎ee/libcglue/src/glue.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1602,7 +1602,7 @@ int dup2(int oldfd, int newfd)
16021602
if (oldfd == newfd) {
16031603
return oldfd;
16041604
}
1605-
if (newfd < 0) {
1605+
if (newfd < 0 || newfd >= __FILENO_MAX) {
16061606
errno = EBADF;
16071607
return -1;
16081608
}

‎iop/hdd/libpfs/src/bitmap.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,13 +366,13 @@ void pfsBitmapShow(pfs_mount_t *pfsMount)
366366
void pfsBitmapFreeInodeBlocks(pfs_cache_t *clink)
367367
{
368368
pfs_mount_t *pfsMount=clink->pfsMount;
369-
u32 i;
369+
u32 i, number_data=clink->u.inode->number_data;
370370

371371
pfsCacheUsedAdd(clink);
372-
for(i=0;i < clink->u.inode->number_data; i++)
372+
for(i=0;i < number_data; i++)
373373
{
374374
u32 index = pfsFixIndex(i);
375-
pfs_blockinfo_t *bi=&clink->u.inode->data[index];
375+
pfs_blockinfo_t *bi;
376376
int err;
377377

378378
if(i!=0) {
@@ -381,6 +381,7 @@ void pfsBitmapFreeInodeBlocks(pfs_cache_t *clink)
381381
return;
382382
}
383383

384+
bi=&clink->u.inode->data[index];
384385
pfsBitmapFreeBlockSegment(pfsMount, bi);
385386
pfsCacheMarkClean(pfsMount, (u16)bi->subpart, bi->number << pfsMount->inode_scale,
386387
(bi->number + bi->count) << pfsMount->inode_scale);

‎iop/sio/mx4sio_bd/src/spi_sdcard_driver.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,7 @@ int spisd_read(struct block_device *bd, uint64_t sector, void *buffer, uint16_t
624624
/* fail condition */
625625
if (sectors_left > 0) {
626626
buffer = (uint8_t *)buffer + (results * 512);
627+
sector += results;
627628
M_DEBUG("ERROR: failed to read all sectors, read:%i, abort:%i\n", sectors_left, cmd.abort);
628629

629630
if (cmd.abort == CMD_ABORT_NO_READ_TOKEN) {
@@ -681,7 +682,7 @@ int spisd_write(struct block_device *bd, uint64_t sector, const void *buffer, ui
681682
while (sectors_left > 0 && retries < MAX_RETRIES) {
682683

683684
/* issue CMD25 to begin transfer */
684-
results = spisd_write_multi_begin(sector, count);
685+
results = spisd_write_multi_begin((uint32_t)sector, sectors_left);
685686
if (results != SPISD_RESULT_OK) {
686687
M_DEBUG("ERROR: failed to start multi-block write\n");
687688
break;
@@ -694,6 +695,7 @@ int spisd_write(struct block_device *bd, uint64_t sector, const void *buffer, ui
694695
/* fail condition */
695696
if (sectors_left > 0) {
696697
write_buffer = (uint8_t *)write_buffer + (results * 512); /* update buffer for next attempt */
698+
sector += results;
697699
M_DEBUG("ERROR: failed to write all sectors, wrote: %i\n", results);
698700
}
699701

@@ -724,4 +726,4 @@ int spisd_stop(struct block_device *bd)
724726
{
725727
(void)bd;
726728
return 0;
727-
}
729+
}

0 commit comments

Comments
 (0)