Skip to content

Commit 49bd03c

Browse files
Christoph Hellwigkrisman-at-collabora
authored andcommitted
unicode: pass a UNICODE_AGE() tripple to utf8_load
Don't bother with pointless string parsing when the caller can just pass the version in the format that the core expects. Also remove the fallback to the latest version that none of the callers actually uses. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>
1 parent f3a9c82 commit 49bd03c

File tree

7 files changed

+65
-86
lines changed

7 files changed

+65
-86
lines changed

fs/ext4/super.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2018,9 +2018,9 @@ static const struct mount_opts {
20182018
static const struct ext4_sb_encodings {
20192019
__u16 magic;
20202020
char *name;
2021-
char *version;
2021+
unsigned int version;
20222022
} ext4_sb_encoding_map[] = {
2023-
{EXT4_ENC_UTF8_12_1, "utf8", "12.1.0"},
2023+
{EXT4_ENC_UTF8_12_1, "utf8", UNICODE_AGE(12, 1, 0)},
20242024
};
20252025

20262026
static const struct ext4_sb_encodings *
@@ -4166,15 +4166,21 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
41664166
encoding = utf8_load(encoding_info->version);
41674167
if (IS_ERR(encoding)) {
41684168
ext4_msg(sb, KERN_ERR,
4169-
"can't mount with superblock charset: %s-%s "
4169+
"can't mount with superblock charset: %s-%u.%u.%u "
41704170
"not supported by the kernel. flags: 0x%x.",
4171-
encoding_info->name, encoding_info->version,
4171+
encoding_info->name,
4172+
unicode_major(encoding_info->version),
4173+
unicode_minor(encoding_info->version),
4174+
unicode_rev(encoding_info->version),
41724175
encoding_flags);
41734176
goto failed_mount;
41744177
}
41754178
ext4_msg(sb, KERN_INFO,"Using encoding defined by superblock: "
4176-
"%s-%s with flags 0x%hx", encoding_info->name,
4177-
encoding_info->version?:"\b", encoding_flags);
4179+
"%s-%u.%u.%u with flags 0x%hx", encoding_info->name,
4180+
unicode_major(encoding_info->version),
4181+
unicode_minor(encoding_info->version),
4182+
unicode_rev(encoding_info->version),
4183+
encoding_flags);
41784184

41794185
sb->s_encoding = encoding;
41804186
sb->s_encoding_flags = encoding_flags;

fs/f2fs/super.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,9 @@ void f2fs_printk(struct f2fs_sb_info *sbi, const char *fmt, ...)
259259
static const struct f2fs_sb_encodings {
260260
__u16 magic;
261261
char *name;
262-
char *version;
262+
unsigned int version;
263263
} f2fs_sb_encoding_map[] = {
264-
{F2FS_ENC_UTF8_12_1, "utf8", "12.1.0"},
264+
{F2FS_ENC_UTF8_12_1, "utf8", UNICODE_AGE(12, 1, 0)},
265265
};
266266

267267
static const struct f2fs_sb_encodings *
@@ -3847,15 +3847,21 @@ static int f2fs_setup_casefold(struct f2fs_sb_info *sbi)
38473847
encoding = utf8_load(encoding_info->version);
38483848
if (IS_ERR(encoding)) {
38493849
f2fs_err(sbi,
3850-
"can't mount with superblock charset: %s-%s "
3850+
"can't mount with superblock charset: %s-%u.%u.%u "
38513851
"not supported by the kernel. flags: 0x%x.",
3852-
encoding_info->name, encoding_info->version,
3852+
encoding_info->name,
3853+
unicode_major(encoding_info->version),
3854+
unicode_minor(encoding_info->version),
3855+
unicode_rev(encoding_info->version),
38533856
encoding_flags);
38543857
return PTR_ERR(encoding);
38553858
}
38563859
f2fs_info(sbi, "Using encoding defined by superblock: "
3857-
"%s-%s with flags 0x%hx", encoding_info->name,
3858-
encoding_info->version?:"\b", encoding_flags);
3860+
"%s-%u.%u.%u with flags 0x%hx", encoding_info->name,
3861+
unicode_major(encoding_info->version),
3862+
unicode_minor(encoding_info->version),
3863+
unicode_rev(encoding_info->version),
3864+
encoding_flags);
38593865

38603866
sbi->sb->s_encoding = encoding;
38613867
sbi->sb->s_encoding_flags = encoding_flags;

fs/unicode/utf8-core.c

Lines changed: 5 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -167,59 +167,19 @@ int utf8_normalize(const struct unicode_map *um, const struct qstr *str,
167167
}
168168
return -EINVAL;
169169
}
170-
171170
EXPORT_SYMBOL(utf8_normalize);
172171

173-
static int utf8_parse_version(const char *version, unsigned int *maj,
174-
unsigned int *min, unsigned int *rev)
172+
struct unicode_map *utf8_load(unsigned int version)
175173
{
176-
substring_t args[3];
177-
char version_string[12];
178-
static const struct match_token token[] = {
179-
{1, "%d.%d.%d"},
180-
{0, NULL}
181-
};
182-
183-
strncpy(version_string, version, sizeof(version_string));
184-
185-
if (match_token(version_string, token, args) != 1)
186-
return -EINVAL;
187-
188-
if (match_int(&args[0], maj) || match_int(&args[1], min) ||
189-
match_int(&args[2], rev))
190-
return -EINVAL;
174+
struct unicode_map *um;
191175

192-
return 0;
193-
}
194-
195-
struct unicode_map *utf8_load(const char *version)
196-
{
197-
struct unicode_map *um = NULL;
198-
int unicode_version;
199-
200-
if (version) {
201-
unsigned int maj, min, rev;
202-
203-
if (utf8_parse_version(version, &maj, &min, &rev) < 0)
204-
return ERR_PTR(-EINVAL);
205-
206-
if (!utf8version_is_supported(maj, min, rev))
207-
return ERR_PTR(-EINVAL);
208-
209-
unicode_version = UNICODE_AGE(maj, min, rev);
210-
} else {
211-
unicode_version = utf8version_latest();
212-
printk(KERN_WARNING"UTF-8 version not specified. "
213-
"Assuming latest supported version (%d.%d.%d).",
214-
(unicode_version >> 16) & 0xff,
215-
(unicode_version >> 8) & 0xff,
216-
(unicode_version & 0xff));
217-
}
176+
if (!utf8version_is_supported(version))
177+
return ERR_PTR(-EINVAL);
218178

219179
um = kzalloc(sizeof(struct unicode_map), GFP_KERNEL);
220180
if (!um)
221181
return ERR_PTR(-ENOMEM);
222-
um->version = unicode_version;
182+
um->version = version;
223183
return um;
224184
}
225185
EXPORT_SYMBOL(utf8_load);

fs/unicode/utf8-norm.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,19 @@ struct utf8data {
1515
#include "utf8data.h"
1616
#undef __INCLUDED_FROM_UTF8NORM_C__
1717

18-
int utf8version_is_supported(u8 maj, u8 min, u8 rev)
18+
int utf8version_is_supported(unsigned int version)
1919
{
2020
int i = ARRAY_SIZE(utf8agetab) - 1;
21-
unsigned int sb_utf8version = UNICODE_AGE(maj, min, rev);
2221

2322
while (i >= 0 && utf8agetab[i] != 0) {
24-
if (sb_utf8version == utf8agetab[i])
23+
if (version == utf8agetab[i])
2524
return 1;
2625
i--;
2726
}
2827
return 0;
2928
}
3029
EXPORT_SYMBOL(utf8version_is_supported);
3130

32-
int utf8version_latest(void)
33-
{
34-
return utf8vers;
35-
}
36-
EXPORT_SYMBOL(utf8version_latest);
37-
3831
/*
3932
* UTF-8 valid ranges.
4033
*

fs/unicode/utf8-selftest.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ static void check_utf8_nfdicf(void)
235235
static void check_utf8_comparisons(void)
236236
{
237237
int i;
238-
struct unicode_map *table = utf8_load("12.1.0");
238+
struct unicode_map *table = utf8_load(UNICODE_AGE(12, 1, 0));
239239

240240
if (IS_ERR(table)) {
241241
pr_err("%s: Unable to load utf8 %d.%d.%d. Skipping.\n",
@@ -269,18 +269,19 @@ static void check_utf8_comparisons(void)
269269
static void check_supported_versions(void)
270270
{
271271
/* Unicode 7.0.0 should be supported. */
272-
test(utf8version_is_supported(7, 0, 0));
272+
test(utf8version_is_supported(UNICODE_AGE(7, 0, 0)));
273273

274274
/* Unicode 9.0.0 should be supported. */
275-
test(utf8version_is_supported(9, 0, 0));
275+
test(utf8version_is_supported(UNICODE_AGE(9, 0, 0)));
276276

277277
/* Unicode 1x.0.0 (the latest version) should be supported. */
278-
test(utf8version_is_supported(latest_maj, latest_min, latest_rev));
278+
test(utf8version_is_supported(
279+
UNICODE_AGE(latest_maj, latest_min, latest_rev)));
279280

280281
/* Next versions don't exist. */
281-
test(!utf8version_is_supported(13, 0, 0));
282-
test(!utf8version_is_supported(0, 0, 0));
283-
test(!utf8version_is_supported(-1, -1, -1));
282+
test(!utf8version_is_supported(UNICODE_AGE(13, 0, 0)));
283+
test(!utf8version_is_supported(UNICODE_AGE(0, 0, 0)));
284+
test(!utf8version_is_supported(UNICODE_AGE(-1, -1, -1)));
284285
}
285286

286287
static int __init init_test_ucd(void)

fs/unicode/utf8n.h

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,9 @@
1111
#include <linux/export.h>
1212
#include <linux/string.h>
1313
#include <linux/module.h>
14+
#include <linux/unicode.h>
1415

15-
/* Encoding a unicode version number as a single unsigned int. */
16-
#define UNICODE_MAJ_SHIFT (16)
17-
#define UNICODE_MIN_SHIFT (8)
18-
19-
#define UNICODE_AGE(MAJ, MIN, REV) \
20-
(((unsigned int)(MAJ) << UNICODE_MAJ_SHIFT) | \
21-
((unsigned int)(MIN) << UNICODE_MIN_SHIFT) | \
22-
((unsigned int)(REV)))
23-
24-
/* Highest unicode version supported by the data tables. */
25-
extern int utf8version_is_supported(u8 maj, u8 min, u8 rev);
26-
extern int utf8version_latest(void);
16+
int utf8version_is_supported(unsigned int version);
2717

2818
/*
2919
* Look for the correct const struct utf8data for a unicode version.

include/linux/unicode.h

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,29 @@
55
#include <linux/init.h>
66
#include <linux/dcache.h>
77

8+
#define UNICODE_MAJ_SHIFT 16
9+
#define UNICODE_MIN_SHIFT 8
10+
11+
#define UNICODE_AGE(MAJ, MIN, REV) \
12+
(((unsigned int)(MAJ) << UNICODE_MAJ_SHIFT) | \
13+
((unsigned int)(MIN) << UNICODE_MIN_SHIFT) | \
14+
((unsigned int)(REV)))
15+
16+
static inline u8 unicode_major(unsigned int age)
17+
{
18+
return (age >> UNICODE_MAJ_SHIFT) & 0xff;
19+
}
20+
21+
static inline u8 unicode_minor(unsigned int age)
22+
{
23+
return (age >> UNICODE_MIN_SHIFT) & 0xff;
24+
}
25+
26+
static inline u8 unicode_rev(unsigned int age)
27+
{
28+
return age & 0xff;
29+
}
30+
831
struct unicode_map {
932
unsigned int version;
1033
};
@@ -29,7 +52,7 @@ int utf8_casefold(const struct unicode_map *um, const struct qstr *str,
2952
int utf8_casefold_hash(const struct unicode_map *um, const void *salt,
3053
struct qstr *str);
3154

32-
struct unicode_map *utf8_load(const char *version);
55+
struct unicode_map *utf8_load(unsigned int version);
3356
void utf8_unload(struct unicode_map *um);
3457

3558
#endif /* _LINUX_UNICODE_H */

0 commit comments

Comments
 (0)