All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kelvin Zhang via Linux-erofs <linux-erofs@lists.ozlabs.org>
To: linux-erofs mailing list <linux-erofs@lists.ozlabs.org>,
	Li Guifu <bluce.liguifu@huawei.com>,
	 Miao Xie <miaoxie@huawei.com>, Fang Wei <fangwei1@huawei.com>
Cc: Kelvin Zhang <zhangkelvin@google.com>, Chao Yu <yuchao0@huawei.com>
Subject: [PATCH v1 2/4] Mark certain callback function pointers as const
Date: Sat, 20 Nov 2021 21:39:19 -0800	[thread overview]
Message-ID: <20211121053920.2580751-3-zhangkelvin@google.com> (raw)
In-Reply-To: <20211121053920.2580751-1-zhangkelvin@google.com>

Global variables aren't bad, until you start mutating them in multiple
places.

Signed-off-by: Kelvin Zhang <zhangkelvin@google.com>
---
 include/erofs/cache.h    | 8 ++++----
 lib/cache.c              | 6 +++---
 lib/compressor.c         | 2 +-
 lib/compressor.h         | 8 ++++----
 lib/compressor_liblzma.c | 2 +-
 lib/compressor_lz4.c     | 2 +-
 lib/compressor_lz4hc.c   | 2 +-
 7 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/include/erofs/cache.h b/include/erofs/cache.h
index 051c696..fd13614 100644
--- a/include/erofs/cache.h
+++ b/include/erofs/cache.h
@@ -31,7 +31,7 @@ struct erofs_buffer_head {
 	struct erofs_buffer_block *block;
 
 	erofs_off_t off;
-	struct erofs_bhops *op;
+	const struct erofs_bhops *op;
 
 	void *fsprivate;
 };
@@ -64,9 +64,9 @@ static inline const int get_alignsize(int type, int *type_ret)
 	return -EINVAL;
 }
 
-extern struct erofs_bhops erofs_drop_directly_bhops;
-extern struct erofs_bhops erofs_skip_write_bhops;
-extern struct erofs_bhops erofs_buf_write_bhops;
+extern const struct erofs_bhops erofs_drop_directly_bhops;
+extern const struct erofs_bhops erofs_skip_write_bhops;
+extern const struct erofs_bhops erofs_buf_write_bhops;
 
 static inline erofs_off_t erofs_btell(struct erofs_buffer_head *bh, bool end)
 {
diff --git a/lib/cache.c b/lib/cache.c
index bae172c..afb29d0 100644
--- a/lib/cache.c
+++ b/lib/cache.c
@@ -28,7 +28,7 @@ static bool erofs_bh_flush_drop_directly(
 	return erofs_bh_flush_generic_end(bh);
 }
 
-struct erofs_bhops erofs_drop_directly_bhops = {
+const struct erofs_bhops erofs_drop_directly_bhops = {
 	.flush = erofs_bh_flush_drop_directly,
 };
 
@@ -39,7 +39,7 @@ static bool erofs_bh_flush_skip_write(
 	return false;
 }
 
-struct erofs_bhops erofs_skip_write_bhops = {
+const struct erofs_bhops erofs_skip_write_bhops = {
 	.flush = erofs_bh_flush_skip_write,
 };
 
@@ -65,7 +65,7 @@ static bool erofs_bh_flush_buf_write(
 }
 
 
-struct erofs_bhops erofs_buf_write_bhops = {
+const struct erofs_bhops erofs_buf_write_bhops = {
 	.flush = erofs_bh_flush_buf_write,
 };
 
diff --git a/lib/compressor.c b/lib/compressor.c
index ad12cdf..6362825 100644
--- a/lib/compressor.c
+++ b/lib/compressor.c
@@ -10,7 +10,7 @@
 
 #define EROFS_CONFIG_COMPR_DEF_BOUNDARY		(128)
 
-static struct erofs_compressor *compressors[] = {
+static const struct erofs_compressor *compressors[] = {
 #if LZ4_ENABLED
 #if LZ4HC_ENABLED
 		&erofs_compressor_lz4hc,
diff --git a/lib/compressor.h b/lib/compressor.h
index aa85ae0..1ea2724 100644
--- a/lib/compressor.h
+++ b/lib/compressor.h
@@ -27,7 +27,7 @@ struct erofs_compressor {
 };
 
 struct erofs_compress {
-	struct erofs_compressor *alg;
+	const struct erofs_compressor *alg;
 
 	unsigned int compress_threshold;
 	unsigned int compression_level;
@@ -41,9 +41,9 @@ struct erofs_compress {
 };
 
 /* list of compression algorithms */
-extern struct erofs_compressor erofs_compressor_lz4;
-extern struct erofs_compressor erofs_compressor_lz4hc;
-extern struct erofs_compressor erofs_compressor_lzma;
+extern const struct erofs_compressor erofs_compressor_lz4;
+extern const struct erofs_compressor erofs_compressor_lz4hc;
+extern const struct erofs_compressor erofs_compressor_lzma;
 
 int erofs_compress_destsize(struct erofs_compress *c,
 			    void *src, unsigned int *srcsize,
diff --git a/lib/compressor_liblzma.c b/lib/compressor_liblzma.c
index 576cdae..3229841 100644
--- a/lib/compressor_liblzma.c
+++ b/lib/compressor_liblzma.c
@@ -96,7 +96,7 @@ static int erofs_compressor_liblzma_init(struct erofs_compress *c)
 	return 0;
 }
 
-struct erofs_compressor erofs_compressor_lzma = {
+const struct erofs_compressor erofs_compressor_lzma = {
 	.name = "lzma",
 	.default_level = LZMA_PRESET_DEFAULT,
 	.best_level = LZMA_PRESET_EXTREME,
diff --git a/lib/compressor_lz4.c b/lib/compressor_lz4.c
index f6832be..fc8c23c 100644
--- a/lib/compressor_lz4.c
+++ b/lib/compressor_lz4.c
@@ -37,7 +37,7 @@ static int compressor_lz4_init(struct erofs_compress *c)
 	return 0;
 }
 
-struct erofs_compressor erofs_compressor_lz4 = {
+const struct erofs_compressor erofs_compressor_lz4 = {
 	.name = "lz4",
 	.default_level = 0,
 	.best_level = 0,
diff --git a/lib/compressor_lz4hc.c b/lib/compressor_lz4hc.c
index fd801ab..3f68b00 100644
--- a/lib/compressor_lz4hc.c
+++ b/lib/compressor_lz4hc.c
@@ -59,7 +59,7 @@ static int compressor_lz4hc_setlevel(struct erofs_compress *c,
 	return 0;
 }
 
-struct erofs_compressor erofs_compressor_lz4hc = {
+const struct erofs_compressor erofs_compressor_lz4hc = {
 	.name = "lz4hc",
 	.default_level = LZ4HC_CLEVEL_DEFAULT,
 	.best_level = LZ4HC_CLEVEL_MAX,
-- 
2.34.0.rc2.393.gf8c9666880-goog


  parent reply	other threads:[~2021-11-21  5:40 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-21  5:39 [PATCH v1 0/3] Make erofs-utils more library friendly Kelvin Zhang via Linux-erofs
2021-11-21  5:39 ` [PATCH v1 1/4] Make erofs_devfd a parameter for most functions Kelvin Zhang via Linux-erofs
2021-11-23  7:49   ` Gao Xiang
2021-11-21  5:39 ` Kelvin Zhang via Linux-erofs [this message]
2021-11-21  5:39 ` [PATCH v1 3/4] Make super block info struct a paramater instead of globals Kelvin Zhang via Linux-erofs
2021-11-23  7:54   ` Gao Xiang
2021-11-21 10:31 ` [PATCH v1 0/3] Make erofs-utils more library friendly Gao Xiang
2021-11-23  7:39   ` Kelvin Zhang via Linux-erofs

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211121053920.2580751-3-zhangkelvin@google.com \
    --to=linux-erofs@lists.ozlabs.org \
    --cc=bluce.liguifu@huawei.com \
    --cc=fangwei1@huawei.com \
    --cc=miaoxie@huawei.com \
    --cc=yuchao0@huawei.com \
    --cc=zhangkelvin@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.