Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH] bcachefs: Add error handling for zlib_deflateInit2()
@ 2025-04-02 13:45 Wentao Liang
  2025-04-02 14:15 ` Kent Overstreet
  0 siblings, 1 reply; 5+ messages in thread
From: Wentao Liang @ 2025-04-02 13:45 UTC (permalink / raw)
  To: kent.overstreet; +Cc: linux-bcachefs, linux-kernel, Wentao Liang, stable

In attempt_compress(), the return value of zlib_deflateInit2() needs to be
checked. A proper implementation can be found in  pstore_compress().

Add an error check and return 0 immediately if the initialzation fails.

Fixes: 986e9842fb68 ("bcachefs: Compression levels")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 fs/bcachefs/compress.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/fs/bcachefs/compress.c b/fs/bcachefs/compress.c
index f99ff1819597..5af37c40cef0 100644
--- a/fs/bcachefs/compress.c
+++ b/fs/bcachefs/compress.c
@@ -365,13 +365,14 @@ static int attempt_compress(struct bch_fs *c,
 		};
 
 		zlib_set_workspace(&strm, workspace);
-		zlib_deflateInit2(&strm,
+		if (zlib_deflateInit2(&strm,
 				  compression.level
 				  ? clamp_t(unsigned, compression.level,
 					    Z_BEST_SPEED, Z_BEST_COMPRESSION)
 				  : Z_DEFAULT_COMPRESSION,
 				  Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL,
-				  Z_DEFAULT_STRATEGY);
+				  Z_DEFAULT_STRATEGY) != Z_OK)
+			return 0;
 
 		if (zlib_deflate(&strm, Z_FINISH) != Z_STREAM_END)
 			return 0;
-- 
2.42.0.windows.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] bcachefs: Add error handling for zlib_deflateInit2()
  2025-04-02 13:45 [PATCH] bcachefs: Add error handling for zlib_deflateInit2() Wentao Liang
@ 2025-04-02 14:15 ` Kent Overstreet
  2025-04-04 14:20   ` Markus Elfring
  0 siblings, 1 reply; 5+ messages in thread
From: Kent Overstreet @ 2025-04-02 14:15 UTC (permalink / raw)
  To: Wentao Liang; +Cc: linux-bcachefs, linux-kernel, stable

On Wed, Apr 02, 2025 at 09:45:44PM +0800, Wentao Liang wrote:
> In attempt_compress(), the return value of zlib_deflateInit2() needs to be
> checked. A proper implementation can be found in  pstore_compress().
> 
> Add an error check and return 0 immediately if the initialzation fails.
> 
> Fixes: 986e9842fb68 ("bcachefs: Compression levels")
> Cc: stable@vger.kernel.org
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>

Applied

> ---
>  fs/bcachefs/compress.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/bcachefs/compress.c b/fs/bcachefs/compress.c
> index f99ff1819597..5af37c40cef0 100644
> --- a/fs/bcachefs/compress.c
> +++ b/fs/bcachefs/compress.c
> @@ -365,13 +365,14 @@ static int attempt_compress(struct bch_fs *c,
>  		};
>  
>  		zlib_set_workspace(&strm, workspace);
> -		zlib_deflateInit2(&strm,
> +		if (zlib_deflateInit2(&strm,
>  				  compression.level
>  				  ? clamp_t(unsigned, compression.level,
>  					    Z_BEST_SPEED, Z_BEST_COMPRESSION)
>  				  : Z_DEFAULT_COMPRESSION,
>  				  Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL,
> -				  Z_DEFAULT_STRATEGY);
> +				  Z_DEFAULT_STRATEGY) != Z_OK)
> +			return 0;
>  
>  		if (zlib_deflate(&strm, Z_FINISH) != Z_STREAM_END)
>  			return 0;
> -- 
> 2.42.0.windows.2
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] bcachefs: Add error handling for zlib_deflateInit2()
  2025-04-02 14:15 ` Kent Overstreet
@ 2025-04-04 14:20   ` Markus Elfring
  2025-04-04 14:53     ` Kent Overstreet
  0 siblings, 1 reply; 5+ messages in thread
From: Markus Elfring @ 2025-04-04 14:20 UTC (permalink / raw)
  To: Kent Overstreet, linux-bcachefs, vulab; +Cc: stable, LKML> > Add an error check and return 0 immediately if the initialzation fails.
>
> Applied

Did you try to avoid a typo in such a change description?

Regards,
Markus

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] bcachefs: Add error handling for zlib_deflateInit2()
  2025-04-04 14:20   ` Markus Elfring
@ 2025-04-04 14:53     ` Kent Overstreet
  2025-04-04 16:30       ` Jonathan Corbet
  0 siblings, 1 reply; 5+ messages in thread
From: Kent Overstreet @ 2025-04-04 14:53 UTC (permalink / raw)
  To: Markus Elfring; +Cc: linux-bcachefs, vulab, stable, LKML

On Fri, Apr 04, 2025 at 04:20:18PM +0200, Markus Elfring wrote:
> …
> > > Add an error check and return 0 immediately if the initialzation fails.
> >
> > Applied
> 
> Did you try to avoid a typo in such a change description?

Typos add character :)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] bcachefs: Add error handling for zlib_deflateInit2()
  2025-04-04 14:53     ` Kent Overstreet
@ 2025-04-04 16:30       ` Jonathan Corbet
  0 siblings, 0 replies; 5+ messages in thread
From: Jonathan Corbet @ 2025-04-04 16:30 UTC (permalink / raw)
  To: Kent Overstreet, Markus Elfring; +Cc: linux-bcachefs, vulab, stable, LKML

Kent Overstreet <kent.overstreet@linux.dev> writes:

> On Fri, Apr 04, 2025 at 04:20:18PM +0200, Markus Elfring wrote:
>> …
>> > > Add an error check and return 0 immediately if the initialzation fails.
>> >
>> > Applied
>> 
>> Did you try to avoid a typo in such a change description?
>
> Typos add character :)

Actually, that one *took away* a character ...

(couldn't resist)

jon

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-04-04 16:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-02 13:45 [PATCH] bcachefs: Add error handling for zlib_deflateInit2() Wentao Liang
2025-04-02 14:15 ` Kent Overstreet
2025-04-04 14:20   ` Markus Elfring
2025-04-04 14:53     ` Kent Overstreet
2025-04-04 16:30       ` Jonathan Corbet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox