Re: [PATCH] bsp/clock_isr: merge the FAST_IDLE clock and normal clock driver

2023-01-11 Thread Sebastian Huber

Hello Zhongjie Zhu,

could you please explain in the commit message which problem is solved 
by the patch and why the change is necessary?


--
embedded brains GmbH
Herr Sebastian HUBER
Dornierstr. 4
82178 Puchheim
Germany
email: sebastian.hu...@embedded-brains.de
phone: +49-89-18 94 741 - 16
fax:   +49-89-18 94 741 - 08

Registergericht: Amtsgericht München
Registernummer: HRB 157899
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
Unsere Datenschutzerklärung finden Sie hier:
https://embedded-brains.de/datenschutzerklaerung/
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

[PATCH] bsp/clock_isr: merge the FAST_IDLE clock and normal clock driver

2023-01-11 Thread Zhu Zhongjie
From: Zhongjie Zhu 

---
 bsps/shared/dev/clock/clockimpl.h | 105 +++---
 1 file changed, 51 insertions(+), 54 deletions(-)

diff --git a/bsps/shared/dev/clock/clockimpl.h 
b/bsps/shared/dev/clock/clockimpl.h
index ccf6d3ab60..0a7f382070 100644
--- a/bsps/shared/dev/clock/clockimpl.h
+++ b/bsps/shared/dev/clock/clockimpl.h
@@ -160,64 +160,61 @@ rtems_isr Clock_isr(
*/
   Clock_driver_ticks += 1;
 
+  /*
+   *  Do the hardware specific per-tick action.
+   *
+   *  The counter/timer may or may not be set to automatically reload.
+   */
+  Clock_driver_support_at_tick();
+
+#if CLOCK_DRIVER_ISRS_PER_TICK
+  /*
+   *  The driver is multiple ISRs per clock tick.
+   */
+  if ( !Clock_driver_isrs ) {
+Clock_driver_timecounter_tick();
+
+Clock_driver_isrs = CLOCK_DRIVER_ISRS_PER_TICK_VALUE;
+  }
+  Clock_driver_isrs--;
+#else
+  /*
+   *  The driver is one ISR per clock tick.
+   */
+
   #if CLOCK_DRIVER_USE_FAST_IDLE
-{
-  Clock_driver_timecounter_tick();
-
-  if (_SMP_Get_processor_maximum() == 1) {
-struct timecounter *tc;
-uint64_tus_per_tick;
-uint32_tinterval;
-Per_CPU_Control*cpu_self;
-
-cpu_self = _Per_CPU_Get();
-tc = _Timecounter;
-us_per_tick = rtems_configuration_get_microseconds_per_tick();
-interval = (uint32_t) ((tc->tc_frequency * us_per_tick) / 100);
-
-while (
-  cpu_self->thread_dispatch_disable_level == cpu_self->isr_nest_level
-&& cpu_self->heir == cpu_self->executing
-&& cpu_self->executing->is_idle
-) {
-  ISR_lock_Context lock_context;
-
-  _Timecounter_Acquire(_context);
-  _Timecounter_Tick_simple(
-interval,
-(*tc->tc_get_timecount)(tc),
-_context
-  );
-}
+  {
+if (_SMP_Get_processor_maximum() == 1) {
+  struct timecounter *tc;
+  uint64_tus_per_tick;
+  uint32_tinterval;
+  Per_CPU_Control*cpu_self;
+
+  cpu_self = _Per_CPU_Get();
+  tc = _Timecounter;
+  us_per_tick = rtems_configuration_get_microseconds_per_tick();
+  interval = (uint32_t) ((tc->tc_frequency * us_per_tick) / 100);
+
+  while (
+cpu_self->thread_dispatch_disable_level == cpu_self->isr_nest_level
+  && cpu_self->heir == cpu_self->executing
+  && cpu_self->executing->is_idle
+  ) {
+ISR_lock_Context lock_context;
+
+_Timecounter_Acquire(_context);
+_Timecounter_Tick_simple(
+  interval,
+  (*tc->tc_get_timecount)(tc),
+  _context
+);
   }
-
-  Clock_driver_support_at_tick();
 }
-  #else
-/*
- *  Do the hardware specific per-tick action.
- *
- *  The counter/timer may or may not be set to automatically reload.
- */
-Clock_driver_support_at_tick();
-
-#if CLOCK_DRIVER_ISRS_PER_TICK
-  /*
-   *  The driver is multiple ISRs per clock tick.
-   */
-  if ( !Clock_driver_isrs ) {
-Clock_driver_timecounter_tick();
-
-Clock_driver_isrs = CLOCK_DRIVER_ISRS_PER_TICK_VALUE;
-  }
-  Clock_driver_isrs--;
-#else
-  /*
-   *  The driver is one ISR per clock tick.
-   */
-  Clock_driver_timecounter_tick();
-#endif
+  }
   #endif
+
+  Clock_driver_timecounter_tick();
+#endif
 }
 
 void _Clock_Initialize( void )
-- 
2.34.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


Re: [PATCH] risc-v: Resurrect RISCV_ENABLE_HTIF_SUPPORT

2023-01-11 Thread Hesham Almatary
LGTM. We also need to update the docs accordingly.

On Wed, 11 Jan 2023 at 07:45, Sebastian Huber
 wrote:
>
> Low-end configurations may want to have the HTIF support removed.
> Enable the option by default.  Fix formatting.  Fix node validity
> checks.
>
> Updates #4779.
> ---
>  bsps/riscv/noel/include/bsp/riscv.h   |  2 --
>  bsps/riscv/riscv/console/console-config.c |  9 -
>  bsps/riscv/riscv/console/htif.c   |  4 
>  bsps/riscv/riscv/include/bsp/riscv.h  |  2 ++
>  bsps/riscv/riscv/irq/irq.c| 18 +++---
>  bsps/riscv/riscv/start/bsp_fatal_halt.c   |  7 +--
>  spec/build/bsps/riscv/riscv/opthtif.yml   |  4 ++--
>  7 files changed, 32 insertions(+), 14 deletions(-)
>
> diff --git a/bsps/riscv/noel/include/bsp/riscv.h 
> b/bsps/riscv/noel/include/bsp/riscv.h
> index 3ab75573f0..0fdf64747b 100644
> --- a/bsps/riscv/noel/include/bsp/riscv.h
> +++ b/bsps/riscv/noel/include/bsp/riscv.h
> @@ -50,8 +50,6 @@ extern uint32_t riscv_hart_count;
>
>  uint32_t riscv_get_hart_index_by_phandle(uint32_t phandle);
>
> -void htif_poweroff(void);
> -
>  #ifdef __cplusplus
>  }
>  #endif
> diff --git a/bsps/riscv/riscv/console/console-config.c 
> b/bsps/riscv/riscv/console/console-config.c
> index fe339c2353..4916191e0b 100644
> --- a/bsps/riscv/riscv/console/console-config.c
> +++ b/bsps/riscv/riscv/console/console-config.c
> @@ -60,7 +60,9 @@
>  static fe310_uart_context fe310_uart_instance;
>  #endif
>
> +#ifdef RISCV_ENABLE_HTIF_SUPPORT
>  static htif_console_context htif_console_instance;
> +#endif
>
>  #if RISCV_CONSOLE_MAX_NS16550_DEVICES > 0
>  static ns16550_context ns16550_instances[RISCV_CONSOLE_MAX_NS16550_DEVICES];
> @@ -163,6 +165,7 @@ static void riscv_console_probe(void)
>compat_len = 0;
>  }
>
> +#ifdef RISCV_ENABLE_HTIF_SUPPORT
>  /* Search for HTIF (eg. on Spike) and use it if found */
>  if (fdt_stringlist_contains(compat, compat_len, "ucb,htif0")) {
>htif_console_context_init(_console_instance.base, node);
> @@ -171,6 +174,7 @@ static void riscv_console_probe(void)
>riscv_console.putchar = htif_console_putchar;
>riscv_console.getchar = htif_console_getchar;
>  };
> +#endif
>
>  #if RISCV_CONSOLE_MAX_NS16550_DEVICES > 0
>  if (
> @@ -277,9 +281,10 @@ rtems_status_code console_initialize(
>void *arg
>  )
>  {
> +#ifdef RISCV_ENABLE_HTIF_SUPPORT
>rtems_termios_device_context *base;
>char htif_path[] = "/dev/ttyShtif";
> -
> +#endif
>  #if RISCV_CONSOLE_MAX_NS16550_DEVICES > 0
>char path[] = "/dev/ttyS?";
>size_t i;
> @@ -292,12 +297,14 @@ rtems_status_code console_initialize(
>
>rtems_termios_initialize();
>
> +#ifdef RISCV_ENABLE_HTIF_SUPPORT
>base = _console_instance.base;
>rtems_termios_device_install(htif_path, _console_handler, NULL, base);
>
>if (base == riscv_console.context) {
>  link(htif_path, CONSOLE_DEVICE_NAME);
>}
> +#endif
>
>  #if RISCV_CONSOLE_MAX_NS16550_DEVICES > 0
>for (i = 0; i < RISCV_CONSOLE_MAX_NS16550_DEVICES; ++i) {
> diff --git a/bsps/riscv/riscv/console/htif.c b/bsps/riscv/riscv/console/htif.c
> index 750abe6e3e..159d9d72fb 100644
> --- a/bsps/riscv/riscv/console/htif.c
> +++ b/bsps/riscv/riscv/console/htif.c
> @@ -29,6 +29,8 @@
>
>  #include 
>
> +#ifdef RISCV_ENABLE_HTIF_SUPPORT
> +
>  #include 
>
>  #include 
> @@ -137,3 +139,5 @@ const rtems_termios_device_handler htif_console_handler = 
> {
>.poll_read = htif_console_getchar,
>.mode = TERMIOS_POLLED
>  };
> +
> +#endif /* RISCV_ENABLE_HTIF_SUPPORT */
> diff --git a/bsps/riscv/riscv/include/bsp/riscv.h 
> b/bsps/riscv/riscv/include/bsp/riscv.h
> index a11ae4291e..bbaaa246c1 100644
> --- a/bsps/riscv/riscv/include/bsp/riscv.h
> +++ b/bsps/riscv/riscv/include/bsp/riscv.h
> @@ -52,7 +52,9 @@ extern uint32_t riscv_hart_count;
>
>  uint32_t riscv_get_hart_index_by_phandle(uint32_t phandle);
>
> +#ifdef RISCV_ENABLE_HTIF_SUPPORT
>  void htif_poweroff(void);
> +#endif
>
>  #ifdef __cplusplus
>  }
> diff --git a/bsps/riscv/riscv/irq/irq.c b/bsps/riscv/riscv/irq/irq.c
> index f0ccc6f5f0..e8d297052b 100644
> --- a/bsps/riscv/riscv/irq/irq.c
> +++ b/bsps/riscv/riscv/irq/irq.c
> @@ -249,14 +249,18 @@ static void riscv_plic_init(const void *fdt)
>plic = riscv_fdt_get_address(fdt, node);
>
>if (plic == NULL) {
> -  node = fdt_node_offset_by_compatible(fdt, -1, "ucb,htif0");
> +#ifdef RISCV_ENABLE_HTIF_SUPPORT
> +node = fdt_node_offset_by_compatible(fdt, -1, "ucb,htif0");
>
> -  /* Spike platform has HTIF and does not have a PLIC */
> -  if (node != -1) {
> -  return;
> -  } else {
> -  bsp_fatal(RISCV_FATAL_NO_PLIC_REG_IN_DEVICE_TREE);
> -  }
> +/* Spike platform has HTIF and does not have a PLIC */
> +if (node >= 0) {
> +  return;
> +} else {
> +  bsp_fatal(RISCV_FATAL_NO_PLIC_REG_IN_DEVICE_TREE);
> +}
> +#else
> +bsp_fatal(RISCV_FATAL_NO_PLIC_REG_IN_DEVICE_TREE);
> +#endif
>}
>
>

[PATCH 18/18] jffs2: Update baseline version to Linux v6.1

2023-01-11 Thread Sebastian Huber
---
 cpukit/libfs/src/jffs2/VERSION | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cpukit/libfs/src/jffs2/VERSION b/cpukit/libfs/src/jffs2/VERSION
index b13bed5750..b2d9e654bf 100644
--- a/cpukit/libfs/src/jffs2/VERSION
+++ b/cpukit/libfs/src/jffs2/VERSION
@@ -3,7 +3,7 @@ This directory contains a port of the JFFS2 file system from 
Linux v5.9.
 To update to a newer Linux version use this command in a Git clone of Linux to
 generate the relevant patches:
 
-  git format-patch v5.9..v9.99 --
+  git format-patch v6.1..v9.99 -- \
 include/uapi/linux/jffs2.h \
 fs/jffs2/LICENCE \
 fs/jffs2/acl.h \
-- 
2.35.3

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 17/18] treewide: uapi: Replace zero-length arrays with flexible-array members

2023-01-11 Thread Sebastian Huber
From: "Gustavo A. R. Silva" 

There is a regular need in the kernel to provide a way to declare
having a dynamically sized set of trailing elements in a structure.
Kernel code should always use “flexible array members”[1] for these
cases. The older style of one-element or zero-length arrays should
no longer be used[2].

This code was transformed with the help of Coccinelle:
(linux-5.19-rc2$ spatch --jobs $(getconf _NPROCESSORS_ONLN) --sp-file 
script.cocci --include-headers --dir . > output.patch)

@@
identifier S, member, array;
type T1, T2;
@@

struct S {
  ...
  T1 member;
  T2 array[
- 0
  ];
};

-fstrict-flex-arrays=3 is coming and we need to land these changes
to prevent issues like these in the short future:

../fs/minix/dir.c:337:3: warning: 'strcpy' will always overflow; destination 
buffer has size 0,
but the source string has length 2 (including NUL byte) [-Wfortify-source]
strcpy(de3->name, ".");
^

Since these are all [0] to [] changes, the risk to UAPI is nearly zero. If
this breaks anything, we can use a union with a new member name.

[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] 
https://www.kernel.org/doc/html/v5.16/process/deprecated.html#zero-length-and-one-element-arrays

Link: https://github.com/KSPP/linux/issues/78
Build-tested-by: kernel test robot 
Link: https://lore.kernel.org/lkml/62b675ec.wkx6aoz6cbe71vtf%25...@intel.com/
Acked-by: Dan Williams  # For ndctl.h
Signed-off-by: Gustavo A. R. Silva 
---
 cpukit/libfs/src/jffs2/include/linux/jffs2.h | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/cpukit/libfs/src/jffs2/include/linux/jffs2.h 
b/cpukit/libfs/src/jffs2/include/linux/jffs2.h
index 784ba0b969..637ee4a793 100644
--- a/cpukit/libfs/src/jffs2/include/linux/jffs2.h
+++ b/cpukit/libfs/src/jffs2/include/linux/jffs2.h
@@ -123,7 +123,7 @@ struct jffs2_raw_dirent
__u8 unused[2];
jint32_t node_crc;
jint32_t name_crc;
-   __u8 name[0];
+   __u8 name[];
 };
 
 /* The JFFS2 raw inode structure: Used for storage on physical media.  */
@@ -155,7 +155,7 @@ struct jffs2_raw_inode
jint16_t flags;  /* See JFFS2_INO_FLAG_* */
jint32_t data_crc;   /* CRC for the (compressed) data.  */
jint32_t node_crc;   /* CRC for the raw inode (excluding data)  */
-   __u8 data[0];
+   __u8 data[];
 };
 
 struct jffs2_raw_xattr {
@@ -170,7 +170,7 @@ struct jffs2_raw_xattr {
jint16_t value_len;
jint32_t data_crc;
jint32_t node_crc;
-   __u8 data[0];
+   __u8 data[];
 } __attribute__((packed));
 
 struct jffs2_raw_xref
@@ -196,7 +196,7 @@ struct jffs2_raw_summary
jint32_t padded;/* sum of the size of padding nodes */
jint32_t sum_crc;   /* summary information crc */
jint32_t node_crc;  /* node crc */
-   jint32_t sum[0];/* inode summary info */
+   jint32_t sum[]; /* inode summary info */
 };
 
 union jffs2_node_union
-- 
2.35.3

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

[PATCH 14/18] jffs2: Pass the file pointer to jffs2_do_readpage_unlock()

2023-01-11 Thread Sebastian Huber
From: "Matthew Wilcox (Oracle)" 

In preparation for unifying the read_cache_page() and read_folio()
implementations, make jffs2_do_readpage_unlock() get the inode
from the page instead of passing it in from read_cache_page().

Signed-off-by: Matthew Wilcox (Oracle) 
Reviewed-by: Christoph Hellwig 
---
 cpukit/libfs/src/jffs2/src/gc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cpukit/libfs/src/jffs2/src/gc.c b/cpukit/libfs/src/jffs2/src/gc.c
index 04ec073d2b..a8b742c899 100644
--- a/cpukit/libfs/src/jffs2/src/gc.c
+++ b/cpukit/libfs/src/jffs2/src/gc.c
@@ -1340,7 +1340,7 @@ static int jffs2_garbage_collect_dnode(struct 
jffs2_sb_info *c, struct jffs2_era
mutex_unlock(>sem);
 #ifndef __rtems__
page = read_cache_page(inode->i_mapping, start >> PAGE_SHIFT,
-  jffs2_do_readpage_unlock, inode);
+  jffs2_do_readpage_unlock, NULL);
if (IS_ERR(page)) {
pr_warn("read_cache_page() returned error: %ld\n",
PTR_ERR(page));
-- 
2.35.3

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 13/18] jffs2: fix memory leak in jffs2_scan_medium

2023-01-11 Thread Sebastian Huber
From: Baokun Li 

If an error is returned in jffs2_scan_eraseblock() and some memory
has been added to the jffs2_summary *s, we can observe the following
kmemleak report:


unreferenced object 0x88812b889c40 (size 64):
  comm "mount", pid 692, jiffies 4294838325 (age 34.288s)
  hex dump (first 32 bytes):
40 48 b5 14 81 88 ff ff 01 e0 31 00 00 00 50 00  @H1...P.
00 00 01 00 00 00 01 00 00 00 02 00 00 00 09 08  
  backtrace:
[] __kmalloc+0x613/0x910
[] jffs2_sum_add_dirent_mem+0x5c/0xa0
[] jffs2_scan_medium.cold+0x36e5/0x4794
[] jffs2_do_mount_fs.cold+0xa7/0x2267
[] jffs2_do_fill_super+0x383/0xc30
[] jffs2_fill_super+0x2ea/0x4c0
[] mtd_get_sb+0x254/0x400
[] mtd_get_sb_by_nr+0x4f/0xd0
[] get_tree_mtd+0x498/0x840
[] jffs2_get_tree+0x25/0x30
[] vfs_get_tree+0x8d/0x2e0
[] path_mount+0x50f/0x1e50
[] do_mount+0x107/0x130
[] __se_sys_mount+0x1c5/0x2f0
[] __x64_sys_mount+0xc7/0x160
[] do_syscall_64+0x45/0x70
unreferenced object 0x888114b54840 (size 32):
  comm "mount", pid 692, jiffies 4294838325 (age 34.288s)
  hex dump (first 32 bytes):
c0 75 b5 14 81 88 ff ff 02 e0 02 00 00 00 02 00  .u..
00 00 84 00 00 00 44 00 00 00 6b 6b 6b 6b 6b a5  ..D...k.
  backtrace:
[] kmem_cache_alloc_trace+0x584/0x880
[] jffs2_sum_add_inode_mem+0x54/0x90
[] jffs2_scan_medium.cold+0x4481/0x4794
[...]
unreferenced object 0x888114b57280 (size 32):
  comm "mount", pid 692, jiffies 4294838393 (age 34.357s)
  hex dump (first 32 bytes):
10 d5 6c 11 81 88 ff ff 08 e0 05 00 00 00 01 00  ..l.
00 00 38 02 00 00 28 00 00 00 6b 6b 6b 6b 6b a5  ..8...(...k.
  backtrace:
[] kmem_cache_alloc_trace+0x584/0x880
[] jffs2_sum_add_xattr_mem+0x54/0x90
[] jffs2_scan_medium.cold+0x298c/0x4794
[...]
unreferenced object 0x8881116cd510 (size 16):
  comm "mount", pid 692, jiffies 4294838395 (age 34.355s)
  hex dump (first 16 bytes):
00 00 00 00 00 00 00 00 09 e0 60 02 00 00 6b a5  ..`...k.
  backtrace:
[] kmem_cache_alloc_trace+0x584/0x880
[] jffs2_sum_add_xref_mem+0x54/0x90
[] jffs2_scan_medium.cold+0x3a20/0x4794
[...]


Therefore, we should call jffs2_sum_reset_collected(s) on exit to
release the memory added in s. In addition, a new tag "out_buf" is
added to prevent the NULL pointer reference caused by s being NULL.
(thanks to Zhang Yi for this analysis)

Fixes: e631ddba5887 ("[JFFS2] Add erase block summary support (mount time 
improvement)")
Cc: sta...@vger.kernel.org
Co-developed-with: Zhihao Cheng 
Signed-off-by: Baokun Li 
Signed-off-by: Richard Weinberger 
---
 cpukit/libfs/src/jffs2/src/scan.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/cpukit/libfs/src/jffs2/src/scan.c 
b/cpukit/libfs/src/jffs2/src/scan.c
index fc33faffbe..10663feb1f 100644
--- a/cpukit/libfs/src/jffs2/src/scan.c
+++ b/cpukit/libfs/src/jffs2/src/scan.c
@@ -139,7 +139,7 @@ int jffs2_scan_medium(struct jffs2_sb_info *c)
if (!s) {
JFFS2_WARNING("Can't allocate memory for summary\n");
ret = -ENOMEM;
-   goto out;
+   goto out_buf;
}
}
 
@@ -278,13 +278,15 @@ int jffs2_scan_medium(struct jffs2_sb_info *c)
}
ret = 0;
  out:
+   jffs2_sum_reset_collected(s);
+   kfree(s);
+ out_buf:
if (buf_size)
kfree(flashbuf);
 #ifndef __ECOS
else
mtd_unpoint(c->mtd, 0, c->mtd->size);
 #endif
-   kfree(s);
return ret;
 }
 
-- 
2.35.3

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 08/18] jffs2: Fix kasan slab-out-of-bounds problem

2023-01-11 Thread Sebastian Huber
From: lizhe 

KASAN report a slab-out-of-bounds problem. The logs are listed below.
It is because in function jffs2_scan_dirent_node, we alloc "checkedlen+1"
bytes for fd->name and we check crc with length rd->nsize. If checkedlen
is less than rd->nsize, it will cause the slab-out-of-bounds problem.

jffs2: Dirent at *** has zeroes in name. Truncating to %d char
==
BUG: KASAN: slab-out-of-bounds in crc32_le+0x1ce/0x260 at addr 8800842cf2d1
Read of size 1 by task test_JFFS2/915
=
BUG kmalloc-64 (Tainted: GB  O   ): kasan: bad access detected
-
INFO: Allocated in jffs2_alloc_full_dirent+0x2a/0x40 age=0 cpu=1 pid=915
___slab_alloc+0x580/0x5f0
__slab_alloc.isra.24+0x4e/0x64
__kmalloc+0x170/0x300
jffs2_alloc_full_dirent+0x2a/0x40
jffs2_scan_eraseblock+0x1ca4/0x3b64
jffs2_scan_medium+0x285/0xfe0
jffs2_do_mount_fs+0x5fb/0x1bbc
jffs2_do_fill_super+0x245/0x6f0
jffs2_fill_super+0x287/0x2e0
mount_mtd_aux.isra.0+0x9a/0x144
mount_mtd+0x222/0x2f0
jffs2_mount+0x41/0x60
mount_fs+0x63/0x230
vfs_kern_mount.part.6+0x6c/0x1f4
do_mount+0xae8/0x1940
SyS_mount+0x105/0x1d0
INFO: Freed in jffs2_free_full_dirent+0x22/0x40 age=27 cpu=1 pid=915
__slab_free+0x372/0x4e4
kfree+0x1d4/0x20c
jffs2_free_full_dirent+0x22/0x40
jffs2_build_remove_unlinked_inode+0x17a/0x1e4
jffs2_do_mount_fs+0x1646/0x1bbc
jffs2_do_fill_super+0x245/0x6f0
jffs2_fill_super+0x287/0x2e0
mount_mtd_aux.isra.0+0x9a/0x144
mount_mtd+0x222/0x2f0
jffs2_mount+0x41/0x60
mount_fs+0x63/0x230
vfs_kern_mount.part.6+0x6c/0x1f4
do_mount+0xae8/0x1940
SyS_mount+0x105/0x1d0
entry_SYSCALL_64_fastpath+0x1e/0x97
Call Trace:
 [] dump_stack+0x59/0x7e
 [] print_trailer+0x125/0x1b0
 [] object_err+0x34/0x40
 [] kasan_report.part.1+0x21f/0x534
 [] ? vprintk+0x2d/0x40
 [] ? crc32_le+0x1ce/0x260
 [] kasan_report+0x26/0x30
 [] __asan_load1+0x3d/0x50
 [] crc32_le+0x1ce/0x260
 [] ? jffs2_alloc_full_dirent+0x2a/0x40
 [] jffs2_scan_eraseblock+0x1d0c/0x3b64
 [] ? jffs2_scan_medium+0xccf/0xfe0
 [] ? jffs2_scan_make_ino_cache+0x14c/0x14c
 [] ? kasan_unpoison_shadow+0x35/0x50
 [] ? kasan_unpoison_shadow+0x35/0x50
 [] ? kasan_kmalloc+0x5e/0x70
 [] ? kmem_cache_alloc_trace+0x10c/0x2cc
 [] ? mtd_point+0xf7/0x130
 [] jffs2_scan_medium+0x285/0xfe0
 [] ? jffs2_scan_eraseblock+0x3b64/0x3b64
 [] ? kasan_unpoison_shadow+0x35/0x50
 [] ? kasan_unpoison_shadow+0x35/0x50
 [] ? kasan_kmalloc+0x5e/0x70
 [] ? __kmalloc+0x12b/0x300
 [] ? kasan_kmalloc+0x5e/0x70
 [] ? jffs2_sum_init+0x9f/0x240
 [] jffs2_do_mount_fs+0x5fb/0x1bbc
 [] ? jffs2_del_noinode_dirent+0x640/0x640
 [] ? kasan_kmalloc+0x5e/0x70
 [] ? __init_rwsem+0x97/0xac
 [] jffs2_do_fill_super+0x245/0x6f0
 [] jffs2_fill_super+0x287/0x2e0
 [] ? jffs2_parse_options+0x594/0x594
 [] mount_mtd_aux.isra.0+0x9a/0x144
 [] mount_mtd+0x222/0x2f0
 [] ? jffs2_parse_options+0x594/0x594
 [] ? mount_mtd_aux.isra.0+0x144/0x144
 [] ? free_pages+0x13/0x1c
 [] ? selinux_sb_copy_data+0x278/0x2e0
 [] jffs2_mount+0x41/0x60
 [] mount_fs+0x63/0x230
 [] ? alloc_vfsmnt+0x32f/0x3b0
 [] vfs_kern_mount.part.6+0x6c/0x1f4
 [] do_mount+0xae8/0x1940
 [] ? audit_filter_rules.constprop.6+0x1d10/0x1d10
 [] ? copy_mount_string+0x40/0x40
 [] ? alloc_pages_current+0xa4/0x1bc
 [] ? __get_free_pages+0x25/0x50
 [] ? copy_mount_options.part.17+0x183/0x264
 [] SyS_mount+0x105/0x1d0
 [] ? copy_mnt_ns+0x560/0x560
 [] ? msa_space_switch_handler+0x13d/0x190
 [] entry_SYSCALL_64_fastpath+0x1e/0x97
 [] ? msa_space_switch+0xb0/0xe0
Memory state around the buggy address:
 8800842cf180: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
 8800842cf200: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>8800842cf280: fc fc fc fc fc fc 00 00 00 00 01 fc fc fc fc fc
 ^
 8800842cf300: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
 8800842cf380: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
==

Cc: sta...@vger.kernel.org
Reported-by: Kunkun Xu 
Signed-off-by: lizhe 
Signed-off-by: Richard Weinberger 
---
 cpukit/libfs/src/jffs2/src/scan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cpukit/libfs/src/jffs2/src/scan.c 
b/cpukit/libfs/src/jffs2/src/scan.c
index 765bf55478..fc33faffbe 100644
--- a/cpukit/libfs/src/jffs2/src/scan.c
+++ b/cpukit/libfs/src/jffs2/src/scan.c
@@ -1082,7 +1082,7 @@ static int jffs2_scan_dirent_node(struct jffs2_sb_info 
*c, struct jffs2_eraseblo
memcpy(>name, rd->name, checkedlen);
fd->name[checkedlen] = 0;
 
-   crc = crc32(0, fd->name, rd->nsize);
+   

[PATCH 15/18] fs: Change the type of filler_t

2023-01-11 Thread Sebastian Huber
From: "Matthew Wilcox (Oracle)" 

By making filler_t the same as read_folio, we can use the same function
for both in gfs2.  We can push the use of folios down one more level
in jffs2 and nfs.  We also increase type safety for future users of the
various read_cache_page() family of functions by forcing the parameter
to be a pointer to struct file (or NULL).

Signed-off-by: Matthew Wilcox (Oracle) 
Reviewed-by: Christoph Hellwig 
Reviewed-by: Andreas Gruenbacher 
---
 cpukit/libfs/src/jffs2/src/gc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cpukit/libfs/src/jffs2/src/gc.c b/cpukit/libfs/src/jffs2/src/gc.c
index a8b742c899..3d0d8c56d9 100644
--- a/cpukit/libfs/src/jffs2/src/gc.c
+++ b/cpukit/libfs/src/jffs2/src/gc.c
@@ -1340,7 +1340,7 @@ static int jffs2_garbage_collect_dnode(struct 
jffs2_sb_info *c, struct jffs2_era
mutex_unlock(>sem);
 #ifndef __rtems__
page = read_cache_page(inode->i_mapping, start >> PAGE_SHIFT,
-  jffs2_do_readpage_unlock, NULL);
+  __jffs2_read_folio, NULL);
if (IS_ERR(page)) {
pr_warn("read_cache_page() returned error: %ld\n",
PTR_ERR(page));
-- 
2.35.3

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 16/18] jffs2: Use kzalloc instead of kmalloc/memset

2023-01-11 Thread Sebastian Huber
From: Haowen Bai 

Use kzalloc rather than duplicating its implementation, which
makes code simple and easy to understand.

Signed-off-by: Haowen Bai 
[rw: Fixed printk string]
Signed-off-by: Richard Weinberger 
---
 cpukit/libfs/src/jffs2/src/erase.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/cpukit/libfs/src/jffs2/src/erase.c 
b/cpukit/libfs/src/jffs2/src/erase.c
index e8ab569462..6966ed9b0a 100644
--- a/cpukit/libfs/src/jffs2/src/erase.c
+++ b/cpukit/libfs/src/jffs2/src/erase.c
@@ -45,9 +45,9 @@ static void jffs2_erase_block(struct jffs2_sb_info *c,
jffs2_dbg(1, "%s(): erase block %#08x (range %#08x-%#08x)\n",
  __func__,
  jeb->offset, jeb->offset, jeb->offset + c->sector_size);
-   instr = kmalloc(sizeof(struct erase_info), GFP_KERNEL);
+   instr = kzalloc(sizeof(struct erase_info), GFP_KERNEL);
if (!instr) {
-   pr_warn("kmalloc for struct erase_info in jffs2_erase_block 
failed. Refiling block for later\n");
+   pr_warn("kzalloc for struct erase_info in jffs2_erase_block 
failed. Refiling block for later\n");
mutex_lock(>erase_free_sem);
spin_lock(>erase_completion_lock);
list_move(>list, >erase_pending_list);
@@ -59,8 +59,6 @@ static void jffs2_erase_block(struct jffs2_sb_info *c,
return;
}
 
-   memset(instr, 0, sizeof(*instr));
-
instr->addr = jeb->offset;
instr->len = c->sector_size;
 
-- 
2.35.3

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 07/18] jffs2: check the validity of dstlen in jffs2_zlib_compress()

2023-01-11 Thread Sebastian Huber
From: Yang Yang 

KASAN reports a BUG when download file in jffs2 filesystem.It is
because when dstlen == 1, cpage_out will write array out of bounds.
Actually, data will not be compressed in jffs2_zlib_compress() if
data's length less than 4.

[  393.799778] BUG: KASAN: slab-out-of-bounds in 
jffs2_rtime_compress+0x214/0x2f0 at addr 800062e3b281
[  393.809166] Write of size 1 by task tftp/2918
[  393.813526] CPU: 3 PID: 2918 Comm: tftp Tainted: GB   
4.9.115-rt93-EMBSYS-CGEL-6.1.R6-dirty #1
[  393.823173] Hardware name: LS1043A RDB Board (DT)
[  393.827870] Call trace:
[  393.830322] [] dump_backtrace+0x0/0x2f0
[  393.835721] [] show_stack+0x14/0x20
[  393.840774] [] dump_stack+0x90/0xb0
[  393.845829] [] kasan_object_err+0x24/0x80
[  393.851402] [] kasan_report_error+0x1b4/0x4d8
[  393.857323] [] kasan_report+0x38/0x40
[  393.862548] [] __asan_store1+0x4c/0x58
[  393.867859] [] jffs2_rtime_compress+0x214/0x2f0
[  393.873955] [] jffs2_selected_compress+0x178/0x2a0
[  393.880308] [] jffs2_compress+0x58/0x478
[  393.885796] [] jffs2_write_inode_range+0x13c/0x450
[  393.892150] [] jffs2_write_end+0x2a8/0x4a0
[  393.897811] [] generic_perform_write+0x1c0/0x280
[  393.903990] [] __generic_file_write_iter+0x1c4/0x228
[  393.910517] [] generic_file_write_iter+0x138/0x288
[  393.916870] [] __vfs_write+0x1b4/0x238
[  393.922181] [] vfs_write+0xd0/0x238
[  393.927232] [] SyS_write+0xa0/0x110
[  393.932283] [] __sys_trace_return+0x0/0x4
[  393.937851] Object at 800062e3b280, in cache kmalloc-64 size: 64
[  393.944197] Allocated:
[  393.946552] PID = 2918
[  393.948913]  save_stack_trace_tsk+0x0/0x220
[  393.953096]  save_stack_trace+0x18/0x20
[  393.956932]  kasan_kmalloc+0xd8/0x188
[  393.960594]  __kmalloc+0x144/0x238
[  393.963994]  jffs2_selected_compress+0x48/0x2a0
[  393.968524]  jffs2_compress+0x58/0x478
[  393.972273]  jffs2_write_inode_range+0x13c/0x450
[  393.976889]  jffs2_write_end+0x2a8/0x4a0
[  393.980810]  generic_perform_write+0x1c0/0x280
[  393.985251]  __generic_file_write_iter+0x1c4/0x228
[  393.990040]  generic_file_write_iter+0x138/0x288
[  393.994655]  __vfs_write+0x1b4/0x238
[  393.998228]  vfs_write+0xd0/0x238
[  394.001543]  SyS_write+0xa0/0x110
[  394.004856]  __sys_trace_return+0x0/0x4
[  394.008684] Freed:
[  394.010691] PID = 2918
[  394.013051]  save_stack_trace_tsk+0x0/0x220
[  394.017233]  save_stack_trace+0x18/0x20
[  394.021069]  kasan_slab_free+0x88/0x188
[  394.024902]  kfree+0x6c/0x1d8
[  394.027868]  jffs2_sum_write_sumnode+0x2c4/0x880
[  394.032486]  jffs2_do_reserve_space+0x198/0x598
[  394.037016]  jffs2_reserve_space+0x3f8/0x4d8
[  394.041286]  jffs2_write_inode_range+0xf0/0x450
[  394.045816]  jffs2_write_end+0x2a8/0x4a0
[  394.049737]  generic_perform_write+0x1c0/0x280
[  394.054179]  __generic_file_write_iter+0x1c4/0x228
[  394.058968]  generic_file_write_iter+0x138/0x288
[  394.063583]  __vfs_write+0x1b4/0x238
[  394.067157]  vfs_write+0xd0/0x238
[  394.070470]  SyS_write+0xa0/0x110
[  394.073783]  __sys_trace_return+0x0/0x4
[  394.077612] Memory state around the buggy address:
[  394.082404]  800062e3b180: 00 00 00 00 00 00 00 00 fc fc fc fc fc fc fc 
fc
[  394.089623]  800062e3b200: 00 00 00 00 00 00 00 00 fc fc fc fc fc fc fc 
fc
[  394.096842] >800062e3b280: 01 fc fc fc fc fc fc fc fc fc fc fc fc fc fc 
fc
[  394.104056]^
[  394.107283]  800062e3b300: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc 
fc
[  394.114502]  800062e3b380: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc 
fc
[  394.121718] 
==

Signed-off-by: Yang Yang 
Signed-off-by: Richard Weinberger 
---
 cpukit/libfs/src/jffs2/src/compr_rtime.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/cpukit/libfs/src/jffs2/src/compr_rtime.c 
b/cpukit/libfs/src/jffs2/src/compr_rtime.c
index c8313ed234..35fe2cd2a5 100644
--- a/cpukit/libfs/src/jffs2/src/compr_rtime.c
+++ b/cpukit/libfs/src/jffs2/src/compr_rtime.c
@@ -44,6 +44,9 @@ uint16_t rtems_jffs2_compressor_rtime_compress(
 
(void) self;
 
+   if (*dstlen <= 3)
+   return -1;
+
memset(positions,0,sizeof(positions));
 
while (pos < (*sourcelen) && outpos <= (*dstlen)-2) {
-- 
2.35.3

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 06/18] fs: make helpers idmap mount aware

2023-01-11 Thread Sebastian Huber
From: Christian Brauner 

Extend some inode methods with an additional user namespace argument. A
filesystem that is aware of idmapped mounts will receive the user
namespace the mount has been marked with. This can be used for
additional permission checking and also to enable filesystems to
translate between uids and gids if they need to. We have implemented all
relevant helpers in earlier patches.

As requested we simply extend the exisiting inode method instead of
introducing new ones. This is a little more code churn but it's mostly
mechanical and doesnt't leave us with additional inode methods.

Link: 
https://lore.kernel.org/r/20210121131959.646623-25-christian.brau...@ubuntu.com
Cc: Christoph Hellwig 
Cc: David Howells 
Cc: Al Viro 
Cc: linux-fsde...@vger.kernel.org
Reviewed-by: Christoph Hellwig 
Signed-off-by: Christian Brauner 
---
 cpukit/libfs/src/jffs2/src/acl.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/cpukit/libfs/src/jffs2/src/acl.h b/cpukit/libfs/src/jffs2/src/acl.h
index 12d0271bdd..62c50da9d4 100644
--- a/cpukit/libfs/src/jffs2/src/acl.h
+++ b/cpukit/libfs/src/jffs2/src/acl.h
@@ -28,7 +28,8 @@ struct jffs2_acl_header {
 #ifdef CONFIG_JFFS2_FS_POSIX_ACL
 
 struct posix_acl *jffs2_get_acl(struct inode *inode, int type);
-int jffs2_set_acl(struct inode *inode, struct posix_acl *acl, int type);
+int jffs2_set_acl(struct user_namespace *mnt_userns, struct inode *inode,
+ struct posix_acl *acl, int type);
 extern int jffs2_init_acl_pre(struct inode *, struct inode *, umode_t *);
 extern int jffs2_init_acl_post(struct inode *);
 
-- 
2.35.3

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 09/18] jffs2: avoid Wempty-body warnings

2023-01-11 Thread Sebastian Huber
From: Arnd Bergmann 

Building with W=1 shows a few warnings for empty macros:

fs/jffs2/scan.c: In function 'jffs2_scan_xattr_node':
fs/jffs2/scan.c:378:66: error: suggest braces around empty body in an 'if' 
statement [-Werror=empty-body]
  378 | jffs2_sum_add_xattr_mem(s, rx, ofs - jeb->offset);
  |  ^
fs/jffs2/scan.c: In function 'jffs2_scan_xref_node':
fs/jffs2/scan.c:434:65: error: suggest braces around empty body in an 'if' 
statement [-Werror=empty-body]
  434 | jffs2_sum_add_xref_mem(s, rr, ofs - jeb->offset);
  | ^
fs/jffs2/scan.c: In function 'jffs2_scan_eraseblock':
fs/jffs2/scan.c:893:88: error: suggest braces around empty body in an 'if' 
statement [-Werror=empty-body]
  893 | jffs2_sum_add_padding_mem(s, 
je32_to_cpu(node->totlen));
  | 
   ^

Change all these macros to 'do { } while (0)' statements to avoid the
warnings and make the code a little more robust.

Signed-off-by: Arnd Bergmann 
Signed-off-by: Richard Weinberger 
---
 cpukit/libfs/src/jffs2/src/summary.h | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/cpukit/libfs/src/jffs2/src/summary.h 
b/cpukit/libfs/src/jffs2/src/summary.h
index e4131cb1f1..36d9a12807 100644
--- a/cpukit/libfs/src/jffs2/src/summary.h
+++ b/cpukit/libfs/src/jffs2/src/summary.h
@@ -194,18 +194,18 @@ int jffs2_sum_scan_sumnode(struct jffs2_sb_info *c, 
struct jffs2_eraseblock *jeb
 
 #define jffs2_sum_active() (0)
 #define jffs2_sum_init(a) (0)
-#define jffs2_sum_exit(a)
+#define jffs2_sum_exit(a) do { } while (0)
 #define jffs2_sum_disable_collecting(a)
 #define jffs2_sum_is_disabled(a) (0)
-#define jffs2_sum_reset_collected(a)
+#define jffs2_sum_reset_collected(a) do { } while (0)
 #define jffs2_sum_add_kvec(a,b,c,d) (0)
-#define jffs2_sum_move_collected(a,b)
+#define jffs2_sum_move_collected(a,b) do { } while (0)
 #define jffs2_sum_write_sumnode(a) (0)
-#define jffs2_sum_add_padding_mem(a,b)
-#define jffs2_sum_add_inode_mem(a,b,c)
-#define jffs2_sum_add_dirent_mem(a,b,c)
-#define jffs2_sum_add_xattr_mem(a,b,c)
-#define jffs2_sum_add_xref_mem(a,b,c)
+#define jffs2_sum_add_padding_mem(a,b) do { } while (0)
+#define jffs2_sum_add_inode_mem(a,b,c) do { } while (0)
+#define jffs2_sum_add_dirent_mem(a,b,c) do { } while (0)
+#define jffs2_sum_add_xattr_mem(a,b,c) do { } while (0)
+#define jffs2_sum_add_xref_mem(a,b,c) do { } while (0)
 #define jffs2_sum_scan_sumnode(a,b,c,d,e) (0)
 
 #endif /* CONFIG_JFFS2_SUMMARY */
-- 
2.35.3

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 11/18] fs/jffs2: fix comments mentioning i_mutex

2023-01-11 Thread Sebastian Huber
From: hongnanli 

inode->i_mutex has been replaced with inode->i_rwsem long ago. Fix
comments still mentioning i_mutex.

Signed-off-by: hongnanli 
Signed-off-by: Richard Weinberger 
---
 cpukit/libfs/src/jffs2/src/jffs2_fs_i.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/cpukit/libfs/src/jffs2/src/jffs2_fs_i.h 
b/cpukit/libfs/src/jffs2/src/jffs2_fs_i.h
index 6b6050e9eb..64ff8abc01 100644
--- a/cpukit/libfs/src/jffs2/src/jffs2_fs_i.h
+++ b/cpukit/libfs/src/jffs2/src/jffs2_fs_i.h
@@ -18,11 +18,11 @@
 #include 
 
 struct jffs2_inode_info {
-   /* We need an internal mutex similar to inode->i_mutex.
+   /* We need an internal mutex similar to inode->i_rwsem.
   Unfortunately, we can't used the existing one, because
   either the GC would deadlock, or we'd have to release it
   before letting GC proceed. Or we'd have to put ugliness
-  into the GC code so it didn't attempt to obtain the i_mutex
+  into the GC code so it didn't attempt to obtain the i_rwsem
   for the inode(s) which are already locked */
struct mutex sem;
 
-- 
2.35.3

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 12/18] jffs2: fix memory leak in jffs2_do_mount_fs

2023-01-11 Thread Sebastian Huber
From: Baokun Li 

If jffs2_build_filesystem() in jffs2_do_mount_fs() returns an error,
we can observe the following kmemleak report:


unreferenced object 0x88811b25a640 (size 64):
  comm "mount", pid 691, jiffies 4294957728 (age 71.952s)
  hex dump (first 32 bytes):
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  
  backtrace:
[] kmem_cache_alloc_trace+0x584/0x880
[] jffs2_sum_init+0x86/0x130
[] jffs2_do_mount_fs+0x798/0xac0
[] jffs2_do_fill_super+0x383/0xc30
[] jffs2_fill_super+0x2ea/0x4c0
[...]
unreferenced object 0x88812c76 (size 65536):
  comm "mount", pid 691, jiffies 4294957728 (age 71.952s)
  hex dump (first 32 bytes):
bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb  
bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb  
  backtrace:
[] __kmalloc+0x6b9/0x910
[] jffs2_sum_init+0xd7/0x130
[] jffs2_do_mount_fs+0x798/0xac0
[] jffs2_do_fill_super+0x383/0xc30
[] jffs2_fill_super+0x2ea/0x4c0
[...]


This is because the resources allocated in jffs2_sum_init() are not
released. Call jffs2_sum_exit() to release these resources to solve
the problem.

Fixes: e631ddba5887 ("[JFFS2] Add erase block summary support (mount time 
improvement)")
Cc: sta...@vger.kernel.org
Signed-off-by: Baokun Li 
Signed-off-by: Richard Weinberger 
---
 cpukit/libfs/src/jffs2/src/build.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/cpukit/libfs/src/jffs2/src/build.c 
b/cpukit/libfs/src/jffs2/src/build.c
index d35bc83bbb..12e2ef820b 100644
--- a/cpukit/libfs/src/jffs2/src/build.c
+++ b/cpukit/libfs/src/jffs2/src/build.c
@@ -417,13 +417,15 @@ int jffs2_do_mount_fs(struct jffs2_sb_info *c)
jffs2_free_ino_caches(c);
jffs2_free_raw_node_refs(c);
ret = -EIO;
-   goto out_free;
+   goto out_sum_exit;
}
 
jffs2_calc_trigger_levels(c);
 
return 0;
 
+ out_sum_exit:
+   jffs2_sum_exit(c);
  out_free:
kvfree(c->blocks);
 
-- 
2.35.3

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 05/18] jffs2: remove trailing semicolon in macro definition

2023-01-11 Thread Sebastian Huber
From: Tom Rix 

The macro use will already have a semicolon.

Signed-off-by: Tom Rix 
Signed-off-by: Richard Weinberger 
---
 cpukit/libfs/src/jffs2/src/nodelist.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/cpukit/libfs/src/jffs2/src/nodelist.h 
b/cpukit/libfs/src/jffs2/src/nodelist.h
index 4eee0ac8ff..b30aa5bbf6 100644
--- a/cpukit/libfs/src/jffs2/src/nodelist.h
+++ b/cpukit/libfs/src/jffs2/src/nodelist.h
@@ -351,14 +351,14 @@ static inline struct jffs2_node_frag *frag_last(struct 
rb_root *root)
 #define frag_parent(frag) rb_entry(rb_parent(&(frag)->rb), struct 
jffs2_node_frag, rb)
 #define frag_left(frag) rb_entry((frag)->rb.rb_left, struct jffs2_node_frag, 
rb)
 #define frag_right(frag) rb_entry((frag)->rb.rb_right, struct jffs2_node_frag, 
rb)
-#define frag_erase(frag, list) rb_erase(>rb, list);
+#define frag_erase(frag, list) rb_erase(>rb, list)
 
 #define tn_next(tn) rb_entry(rb_next(&(tn)->rb), struct jffs2_tmp_dnode_info, 
rb)
 #define tn_prev(tn) rb_entry(rb_prev(&(tn)->rb), struct jffs2_tmp_dnode_info, 
rb)
 #define tn_parent(tn) rb_entry(rb_parent(&(tn)->rb), struct 
jffs2_tmp_dnode_info, rb)
 #define tn_left(tn) rb_entry((tn)->rb.rb_left, struct jffs2_tmp_dnode_info, rb)
 #define tn_right(tn) rb_entry((tn)->rb.rb_right, struct jffs2_tmp_dnode_info, 
rb)
-#define tn_erase(tn, list) rb_erase(>rb, list);
+#define tn_erase(tn, list) rb_erase(>rb, list)
 #define tn_last(list) rb_entry(rb_last(list), struct jffs2_tmp_dnode_info, rb)
 #define tn_first(list) rb_entry(rb_first(list), struct jffs2_tmp_dnode_info, 
rb)
 
-- 
2.35.3

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 10/18] vfs: add rcu argument to ->get_acl() callback

2023-01-11 Thread Sebastian Huber
From: Miklos Szeredi 

Add a rcu argument to the ->get_acl() callback to allow
get_cached_acl_rcu() to call the ->get_acl() method in the next patch.

Signed-off-by: Miklos Szeredi 
---
 cpukit/libfs/src/jffs2/src/acl.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cpukit/libfs/src/jffs2/src/acl.h b/cpukit/libfs/src/jffs2/src/acl.h
index 62c50da9d4..9d9fb7cf09 100644
--- a/cpukit/libfs/src/jffs2/src/acl.h
+++ b/cpukit/libfs/src/jffs2/src/acl.h
@@ -27,7 +27,7 @@ struct jffs2_acl_header {
 
 #ifdef CONFIG_JFFS2_FS_POSIX_ACL
 
-struct posix_acl *jffs2_get_acl(struct inode *inode, int type);
+struct posix_acl *jffs2_get_acl(struct inode *inode, int type, bool rcu);
 int jffs2_set_acl(struct user_namespace *mnt_userns, struct inode *inode,
  struct posix_acl *acl, int type);
 extern int jffs2_init_acl_pre(struct inode *, struct inode *, umode_t *);
-- 
2.35.3

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 02/18] jffs2: Fix if/else empty body warnings

2023-01-11 Thread Sebastian Huber
From: Randy Dunlap 

When debug (print) macros are not enabled, change them to use the
no_printk() macro instead of . This fixes gcc warnings when
-Wextra is used:

../cpukit/libfs/src/jffs2/src/nodelist.c:255:37: warning: suggest braces around 
empty body in an ‘else’ statement [-Wempty-body]
../cpukit/libfs/src/jffs2/src/nodelist.c:278:38: warning: suggest braces around 
empty body in an ‘else’ statement [-Wempty-body]
../cpukit/libfs/src/jffs2/src/nodelist.c:558:52: warning: suggest braces around 
empty body in an ‘else’ statement [-Wempty-body]
../cpukit/libfs/src/jffs2/src/xattr.c:1247:58: warning: suggest braces around 
empty body in an ‘if’ statement [-Wempty-body]
../cpukit/libfs/src/jffs2/src/xattr.c:1281:65: warning: suggest braces around 
empty body in an ‘if’ statement [-Wempty-body]

Builds without warnings on all 3 levels of CONFIG_JFFS2_FS_DEBUG.

Signed-off-by: Randy Dunlap 
Cc: David Woodhouse 
Cc: Richard Weinberger 
Cc: linux-...@lists.infradead.org
Signed-off-by: Richard Weinberger 
---
 cpukit/libfs/src/jffs2/src/debug.h | 23 ---
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/cpukit/libfs/src/jffs2/src/debug.h 
b/cpukit/libfs/src/jffs2/src/debug.h
index 6c905b3854..6b4afd4e75 100644
--- a/cpukit/libfs/src/jffs2/src/debug.h
+++ b/cpukit/libfs/src/jffs2/src/debug.h
@@ -13,6 +13,7 @@
 #ifndef _JFFS2_DEBUG_H_
 #define _JFFS2_DEBUG_H_
 
+#include 
 #include 
 
 #ifndef CONFIG_JFFS2_FS_DEBUG
@@ -117,73 +118,73 @@ do {  \
 #ifdef JFFS2_DBG_READINODE_MESSAGES
 #define dbg_readinode(fmt, ...)JFFS2_DEBUG(fmt, ##__VA_ARGS__)
 #else
-#define dbg_readinode(fmt, ...)
+#define dbg_readinode(fmt, ...)no_printk(fmt, ##__VA_ARGS__)
 #endif
 #ifdef JFFS2_DBG_READINODE2_MESSAGES
 #define dbg_readinode2(fmt, ...)   JFFS2_DEBUG(fmt, ##__VA_ARGS__)
 #else
-#define dbg_readinode2(fmt, ...)
+#define dbg_readinode2(fmt, ...)   no_printk(fmt, ##__VA_ARGS__)
 #endif
 
 /* Fragtree build debugging messages */
 #ifdef JFFS2_DBG_FRAGTREE_MESSAGES
 #define dbg_fragtree(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
 #else
-#define dbg_fragtree(fmt, ...)
+#define dbg_fragtree(fmt, ...) no_printk(fmt, ##__VA_ARGS__)
 #endif
 #ifdef JFFS2_DBG_FRAGTREE2_MESSAGES
 #define dbg_fragtree2(fmt, ...)JFFS2_DEBUG(fmt, ##__VA_ARGS__)
 #else
-#define dbg_fragtree2(fmt, ...)
+#define dbg_fragtree2(fmt, ...)no_printk(fmt, ##__VA_ARGS__)
 #endif
 
 /* Directory entry list manilulation debugging messages */
 #ifdef JFFS2_DBG_DENTLIST_MESSAGES
 #define dbg_dentlist(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
 #else
-#define dbg_dentlist(fmt, ...)
+#define dbg_dentlist(fmt, ...) no_printk(fmt, ##__VA_ARGS__)
 #endif
 
 /* Print the messages about manipulating node_refs */
 #ifdef JFFS2_DBG_NODEREF_MESSAGES
 #define dbg_noderef(fmt, ...)  JFFS2_DEBUG(fmt, ##__VA_ARGS__)
 #else
-#define dbg_noderef(fmt, ...)
+#define dbg_noderef(fmt, ...)  no_printk(fmt, ##__VA_ARGS__)
 #endif
 
 /* Manipulations with the list of inodes (JFFS2 inocache) */
 #ifdef JFFS2_DBG_INOCACHE_MESSAGES
 #define dbg_inocache(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
 #else
-#define dbg_inocache(fmt, ...)
+#define dbg_inocache(fmt, ...) no_printk(fmt, ##__VA_ARGS__)
 #endif
 
 /* Summary debugging messages */
 #ifdef JFFS2_DBG_SUMMARY_MESSAGES
 #define dbg_summary(fmt, ...)  JFFS2_DEBUG(fmt, ##__VA_ARGS__)
 #else
-#define dbg_summary(fmt, ...)
+#define dbg_summary(fmt, ...)  no_printk(fmt, ##__VA_ARGS__)
 #endif
 
 /* File system build messages */
 #ifdef JFFS2_DBG_FSBUILD_MESSAGES
 #define dbg_fsbuild(fmt, ...)  JFFS2_DEBUG(fmt, ##__VA_ARGS__)
 #else
-#define dbg_fsbuild(fmt, ...)
+#define dbg_fsbuild(fmt, ...)  no_printk(fmt, ##__VA_ARGS__)
 #endif
 
 /* Watch the object allocations */
 #ifdef JFFS2_DBG_MEMALLOC_MESSAGES
 #define dbg_memalloc(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
 #else
-#define dbg_memalloc(fmt, ...)
+#define dbg_memalloc(fmt, ...) no_printk(fmt, ##__VA_ARGS__)
 #endif
 
 /* Watch the XATTR subsystem */
 #ifdef JFFS2_DBG_XATTR_MESSAGES
 #define dbg_xattr(fmt, ...)  JFFS2_DEBUG(fmt, ##__VA_ARGS__)
 #else
-#define dbg_xattr(fmt, ...)
+#define dbg_xattr(fmt, ...)  no_printk(fmt, ##__VA_ARGS__)
 #endif 
 
 /* "Sanity" checks */
-- 
2.35.3

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

[PATCH 04/18] jffs2: Allow setting rp_size to zero during remounting

2023-01-11 Thread Sebastian Huber
From: lizhe 

Set rp_size to zero will be ignore during remounting.

The method to identify whether we input a remounting option of
rp_size is to check if the rp_size input is zero. It can not work
well if we pass "rp_size=0".

This patch add a bool variable "set_rp_size" to fix this problem.

Reported-by: Jubin Zhong 
Signed-off-by: lizhe 
Signed-off-by: Richard Weinberger 
---
 cpukit/libfs/src/jffs2/src/jffs2_fs_sb.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/cpukit/libfs/src/jffs2/src/jffs2_fs_sb.h 
b/cpukit/libfs/src/jffs2/src/jffs2_fs_sb.h
index 778275f48a..5a7091746f 100644
--- a/cpukit/libfs/src/jffs2/src/jffs2_fs_sb.h
+++ b/cpukit/libfs/src/jffs2/src/jffs2_fs_sb.h
@@ -38,6 +38,7 @@ struct jffs2_mount_opts {
 * users. This is implemented simply by means of not allowing the
 * latter users to write to the file system if the amount if the
 * available space is less then 'rp_size'. */
+   bool set_rp_size;
unsigned int rp_size;
 };
 
-- 
2.35.3

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 03/18] jffs2: Fix GC exit abnormally

2023-01-11 Thread Sebastian Huber
From: Zhe Li 

The log of this problem is:
jffs2: Error garbage collecting node at 0x***!
jffs2: No space for garbage collection. Aborting GC thread

This is because GC believe that it do nothing, so it abort.

After going over the image of jffs2, I find a scene that
can trigger this problem stably.
The scene is: there is a normal dirent node at summary-area,
but abnormal at corresponding not-summary-area with error
name_crc.

The reason that GC exit abnormally is because it find that
abnormal dirent node to GC, but when it goes to function
jffs2_add_fd_to_list, it cannot meet the condition listed
below:

if ((*prev)->nhash == new->nhash && !strcmp((*prev)->name, new->name))

So no node is marked obsolete, statistical information of
erase_block do not change, which cause GC exit abnormally.

The root cause of this problem is: we do not check the
name_crc of the abnormal dirent node with summary is enabled.

Noticed that in function jffs2_scan_dirent_node, we use
function jffs2_scan_dirty_space to deal with the dirent
node with error name_crc. So this patch add a checking
code in function read_direntry to ensure the correctness
of dirent node. If checked failed, the dirent node will
be marked obsolete so GC will pass this node and this
problem will be fixed.

Cc: 
Signed-off-by: Zhe Li 
Signed-off-by: Richard Weinberger 
---
 cpukit/libfs/src/jffs2/src/readinode.c | 16 
 1 file changed, 16 insertions(+)

diff --git a/cpukit/libfs/src/jffs2/src/readinode.c 
b/cpukit/libfs/src/jffs2/src/readinode.c
index 831fb8f3f9..9f554f8644 100644
--- a/cpukit/libfs/src/jffs2/src/readinode.c
+++ b/cpukit/libfs/src/jffs2/src/readinode.c
@@ -693,6 +693,22 @@ static inline int read_direntry(struct jffs2_sb_info *c, 
struct jffs2_raw_node_r
jffs2_free_full_dirent(fd);
return -EIO;
}
+
+#ifdef CONFIG_JFFS2_SUMMARY
+   /*
+* we use CONFIG_JFFS2_SUMMARY because without it, we
+* have checked it while mounting
+*/
+   crc = crc32(0, fd->name, rd->nsize);
+   if (unlikely(crc != je32_to_cpu(rd->name_crc))) {
+   JFFS2_NOTICE("name CRC failed on dirent node at"
+  "%#08x: read %#08x,calculated %#08x\n",
+  ref_offset(ref), je32_to_cpu(rd->node_crc), crc);
+   jffs2_mark_node_obsolete(c, ref);
+   jffs2_free_full_dirent(fd);
+   return 0;
+   }
+#endif
}
 
fd->nhash = full_name_hash(NULL, fd->name, rd->nsize);
-- 
2.35.3

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 00/18] jffs2: Update baseline version to Linux v6.1

2023-01-11 Thread Sebastian Huber
Arnd Bergmann (1):
  jffs2: avoid Wempty-body warnings

Baokun Li (2):
  jffs2: fix memory leak in jffs2_do_mount_fs
  jffs2: fix memory leak in jffs2_scan_medium

Christian Brauner (1):
  fs: make helpers idmap mount aware

Gustavo A. R. Silva (1):
  treewide: uapi: Replace zero-length arrays with flexible-array members

Haowen Bai (1):
  jffs2: Use kzalloc instead of kmalloc/memset

Matthew Wilcox (Oracle) (2):
  jffs2: Pass the file pointer to jffs2_do_readpage_unlock()
  fs: Change the type of filler_t

Miklos Szeredi (1):
  vfs: add rcu argument to ->get_acl() callback

Randy Dunlap (1):
  jffs2: Fix if/else empty body warnings

Sebastian Huber (2):
  jffs2: Add 
  jffs2: Update baseline version to Linux v6.1

Tom Rix (1):
  jffs2: remove trailing semicolon in macro definition

Yang Yang (1):
  jffs2: check the validity of dstlen in jffs2_zlib_compress()

Zhe Li (1):
  jffs2: Fix GC exit abnormally

hongnanli (1):
  fs/jffs2: fix comments mentioning i_mutex

lizhe (2):
  jffs2: Allow setting rp_size to zero during remounting
  jffs2: Fix kasan slab-out-of-bounds problem

 cpukit/libfs/src/jffs2/VERSION|  2 +-
 cpukit/libfs/src/jffs2/include/linux/jffs2.h  |  8 +++
 cpukit/libfs/src/jffs2/include/linux/printk.h |  6 +
 cpukit/libfs/src/jffs2/src/acl.h  |  5 ++--
 cpukit/libfs/src/jffs2/src/build.c|  4 +++-
 cpukit/libfs/src/jffs2/src/compr_rtime.c  |  3 +++
 cpukit/libfs/src/jffs2/src/debug.h| 23 ++-
 cpukit/libfs/src/jffs2/src/erase.c|  6 ++---
 cpukit/libfs/src/jffs2/src/gc.c   |  2 +-
 cpukit/libfs/src/jffs2/src/jffs2_fs_i.h   |  4 ++--
 cpukit/libfs/src/jffs2/src/jffs2_fs_sb.h  |  1 +
 cpukit/libfs/src/jffs2/src/nodelist.h |  4 ++--
 cpukit/libfs/src/jffs2/src/readinode.c| 16 +
 cpukit/libfs/src/jffs2/src/scan.c |  8 ---
 cpukit/libfs/src/jffs2/src/summary.h  | 16 ++---
 15 files changed, 69 insertions(+), 39 deletions(-)
 create mode 100644 cpukit/libfs/src/jffs2/include/linux/printk.h

-- 
2.35.3

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 01/18] jffs2: Add

2023-01-11 Thread Sebastian Huber
A follow up patch uses no_printk().
---
 cpukit/libfs/src/jffs2/include/linux/printk.h | 6 ++
 1 file changed, 6 insertions(+)
 create mode 100644 cpukit/libfs/src/jffs2/include/linux/printk.h

diff --git a/cpukit/libfs/src/jffs2/include/linux/printk.h 
b/cpukit/libfs/src/jffs2/include/linux/printk.h
new file mode 100644
index 00..515188faa1
--- /dev/null
+++ b/cpukit/libfs/src/jffs2/include/linux/printk.h
@@ -0,0 +1,6 @@
+#ifndef __LINUX_PRINTK_H__
+#define __LINUX_PRINTK_H__
+
+#define no_printk(fmt, ...) do { } while (0)
+
+#endif /* __LINUX_PRINTK_H__ */
-- 
2.35.3

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


Re: [PATCH 1/4] cpukit/include/dev/can: Added debug print configuration under RTEMS_CAN_DEBUG macro.

2023-01-11 Thread Prashanth S
Hi All,

This is a reminder for review requests for the patches to CAN Framework
changes based on review comments.

Regards
Prashanth S

On Fri, 16 Dec 2022 at 18:58, Prashanth S  wrote:

> ---
>  cpukit/include/dev/can/can.h | 27 +--
>  1 file changed, 21 insertions(+), 6 deletions(-)
>
> diff --git a/cpukit/include/dev/can/can.h b/cpukit/include/dev/can/can.h
> index 9e55395039..4ee51ebc9d 100644
> --- a/cpukit/include/dev/can/can.h
> +++ b/cpukit/include/dev/can/can.h
> @@ -53,13 +53,28 @@
>printf(str, ##__VA_ARGS__);
>  \
>  } while (false);
>
> +#ifdef RTEMS_CAN_DEBUG
> +
>  #define CAN_DEBUG(str, ...) DEBUG(str, ##__VA_ARGS__)
> -#define CAN_DEBUG_BUF(str, ...) CAN_DEBUG(str, ##__VA_ARGS__)
> -#define CAN_DEBUG_ISR(str, ...) CAN_DEBUG(str, ##__VA_ARGS__)
> -#define CAN_DEBUG_LOCK(str, ...) CAN_DEBUG(str, ##__VA_ARGS__)
> -#define CAN_DEBUG_RX(str, ...) CAN_DEBUG(str, ##__VA_ARGS__)
> -#define CAN_DEBUG_TX(str, ...) CAN_DEBUG(str, ##__VA_ARGS__)
> -#define CAN_DEBUG_REG(str, ...) //CAN_DEBUG(str, ##__VA_ARGS__)
> +#define CAN_DEBUG_BUF(str, ...) DEBUG(str, ##__VA_ARGS__)
> +#define CAN_DEBUG_ISR(str, ...) DEBUG(str, ##__VA_ARGS__)
> +#define CAN_DEBUG_LOCK(str, ...) DEBUG(str, ##__VA_ARGS__)
> +#define CAN_DEBUG_RX(str, ...) DEBUG(str, ##__VA_ARGS__)
> +#define CAN_DEBUG_TX(str, ...) DEBUG(str, ##__VA_ARGS__)
> +#define CAN_DEBUG_REG(str, ...) /* CAN_DEBUG(str, ##__VA_ARGS__) */
> +
> +#else /* RTEMS_CAN_DEBUG */
> +
> +#define CAN_DEBUG(str, ...)
> +#define CAN_DEBUG_BUF(str, ...)
> +#define CAN_DEBUG_ISR(str, ...)
> +#define CAN_DEBUG_LOCK(str, ...)
> +#define CAN_DEBUG_RX(str, ...)
> +#define CAN_DEBUG_TX(str, ...)
> +#define CAN_DEBUG_REG(str, ...)
> +
> +#endif /* RTEMS_CAN_DEBUG */
> +
>  #define CAN_ERR(str, ...) DEBUG(str, ##__VA_ARGS__)
>
>  #define CAN_MSG_LEN(msg) ((char *)(&((struct can_msg
> *)msg)->data[(uint16_t)((struct can_msg *)msg)->len]) - (char *)(msg))
> --
> 2.25.1
>
>
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel