Skip to content

Commit 7e7742e

Browse files
author
Al Viro
committed
sanitize signedness/const for pointers to char in hpfs a bit
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 1f70713 commit 7e7742e

10 files changed

Lines changed: 97 additions & 82 deletions

File tree

‎fs/hpfs/anode.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ int hpfs_ea_read(struct super_block *s, secno a, int ano, unsigned pos,
353353
}
354354

355355
int hpfs_ea_write(struct super_block *s, secno a, int ano, unsigned pos,
356-
unsigned len, char *buf)
356+
unsigned len, const char *buf)
357357
{
358358
struct buffer_head *bh;
359359
char *data;

‎fs/hpfs/dentry.c‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ static int hpfs_hash_dentry(struct dentry *dentry, struct qstr *qstr)
2020

2121
if (l == 1) if (qstr->name[0]=='.') goto x;
2222
if (l == 2) if (qstr->name[0]=='.' || qstr->name[1]=='.') goto x;
23-
hpfs_adjust_length((char *)qstr->name, &l);
24-
/*if (hpfs_chk_name((char *)qstr->name,&l))*/
23+
hpfs_adjust_length(qstr->name, &l);
24+
/*if (hpfs_chk_name(qstr->name,&l))*/
2525
/*return -ENAMETOOLONG;*/
2626
/*return -ENOENT;*/
2727
x:
@@ -38,14 +38,16 @@ static int hpfs_compare_dentry(struct dentry *dentry, struct qstr *a, struct qst
3838
{
3939
unsigned al=a->len;
4040
unsigned bl=b->len;
41-
hpfs_adjust_length((char *)a->name, &al);
42-
/*hpfs_adjust_length((char *)b->name, &bl);*/
41+
hpfs_adjust_length(a->name, &al);
42+
/*hpfs_adjust_length(b->name, &bl);*/
4343
/* 'a' is the qstr of an already existing dentry, so the name
4444
* must be valid. 'b' must be validated first.
4545
*/
4646

47-
if (hpfs_chk_name((char *)b->name, &bl)) return 1;
48-
if (hpfs_compare_names(dentry->d_sb, (char *)a->name, al, (char *)b->name, bl, 0)) return 1;
47+
if (hpfs_chk_name(b->name, &bl))
48+
return 1;
49+
if (hpfs_compare_names(dentry->d_sb, a->name, al, b->name, bl, 0))
50+
return 1;
4951
return 0;
5052
}
5153

‎fs/hpfs/dir.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static int hpfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
5959
struct hpfs_dirent *de;
6060
int lc;
6161
long old_pos;
62-
char *tempname;
62+
unsigned char *tempname;
6363
int c1, c2 = 0;
6464
int ret = 0;
6565

@@ -158,11 +158,11 @@ static int hpfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
158158
tempname = hpfs_translate_name(inode->i_sb, de->name, de->namelen, lc, de->not_8x3);
159159
if (filldir(dirent, tempname, de->namelen, old_pos, de->fnode, DT_UNKNOWN) < 0) {
160160
filp->f_pos = old_pos;
161-
if (tempname != (char *)de->name) kfree(tempname);
161+
if (tempname != de->name) kfree(tempname);
162162
hpfs_brelse4(&qbh);
163163
goto out;
164164
}
165-
if (tempname != (char *)de->name) kfree(tempname);
165+
if (tempname != de->name) kfree(tempname);
166166
hpfs_brelse4(&qbh);
167167
}
168168
out:
@@ -187,7 +187,7 @@ static int hpfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
187187

188188
struct dentry *hpfs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
189189
{
190-
const char *name = dentry->d_name.name;
190+
const unsigned char *name = dentry->d_name.name;
191191
unsigned len = dentry->d_name.len;
192192
struct quad_buffer_head qbh;
193193
struct hpfs_dirent *de;
@@ -197,7 +197,7 @@ struct dentry *hpfs_lookup(struct inode *dir, struct dentry *dentry, struct name
197197
struct hpfs_inode_info *hpfs_result;
198198

199199
lock_kernel();
200-
if ((err = hpfs_chk_name((char *)name, &len))) {
200+
if ((err = hpfs_chk_name(name, &len))) {
201201
if (err == -ENAMETOOLONG) {
202202
unlock_kernel();
203203
return ERR_PTR(-ENAMETOOLONG);
@@ -209,7 +209,7 @@ struct dentry *hpfs_lookup(struct inode *dir, struct dentry *dentry, struct name
209209
* '.' and '..' will never be passed here.
210210
*/
211211

212-
de = map_dirent(dir, hpfs_i(dir)->i_dno, (char *) name, len, NULL, &qbh);
212+
de = map_dirent(dir, hpfs_i(dir)->i_dno, name, len, NULL, &qbh);
213213

214214
/*
215215
* This is not really a bailout, just means file not found.
@@ -250,7 +250,7 @@ struct dentry *hpfs_lookup(struct inode *dir, struct dentry *dentry, struct name
250250
hpfs_result = hpfs_i(result);
251251
if (!de->directory) hpfs_result->i_parent_dir = dir->i_ino;
252252

253-
hpfs_decide_conv(result, (char *)name, len);
253+
hpfs_decide_conv(result, name, len);
254254

255255
if (de->has_acl || de->has_xtd_perm) if (!(dir->i_sb->s_flags & MS_RDONLY)) {
256256
hpfs_error(result->i_sb, "ACLs or XPERM found. This is probably HPFS386. This driver doesn't support it now. Send me some info on these structures");

‎fs/hpfs/dnode.c‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ static void set_last_pointer(struct super_block *s, struct dnode *d, dnode_secno
158158

159159
/* Add an entry to dnode and don't care if it grows over 2048 bytes */
160160

161-
struct hpfs_dirent *hpfs_add_de(struct super_block *s, struct dnode *d, unsigned char *name,
161+
struct hpfs_dirent *hpfs_add_de(struct super_block *s, struct dnode *d,
162+
const unsigned char *name,
162163
unsigned namelen, secno down_ptr)
163164
{
164165
struct hpfs_dirent *de;
@@ -223,15 +224,15 @@ static void fix_up_ptrs(struct super_block *s, struct dnode *d)
223224
/* Add an entry to dnode and do dnode splitting if required */
224225

225226
static int hpfs_add_to_dnode(struct inode *i, dnode_secno dno,
226-
unsigned char *name, unsigned namelen,
227+
const unsigned char *name, unsigned namelen,
227228
struct hpfs_dirent *new_de, dnode_secno down_ptr)
228229
{
229230
struct quad_buffer_head qbh, qbh1, qbh2;
230231
struct dnode *d, *ad, *rd, *nd = NULL;
231232
dnode_secno adno, rdno;
232233
struct hpfs_dirent *de;
233234
struct hpfs_dirent nde;
234-
char *nname;
235+
unsigned char *nname;
235236
int h;
236237
int pos;
237238
struct buffer_head *bh;
@@ -305,7 +306,9 @@ static int hpfs_add_to_dnode(struct inode *i, dnode_secno dno,
305306
pos++;
306307
}
307308
copy_de(new_de = &nde, de);
308-
memcpy(name = nname, de->name, namelen = de->namelen);
309+
memcpy(nname, de->name, de->namelen);
310+
name = nname;
311+
namelen = de->namelen;
309312
for_all_poss(i, hpfs_pos_subst, ((loff_t)dno << 4) | pos, 4);
310313
down_ptr = adno;
311314
set_last_pointer(i->i_sb, ad, de->down ? de_down_pointer(de) : 0);
@@ -368,7 +371,8 @@ static int hpfs_add_to_dnode(struct inode *i, dnode_secno dno,
368371
* I hope, now it's finally bug-free.
369372
*/
370373

371-
int hpfs_add_dirent(struct inode *i, unsigned char *name, unsigned namelen,
374+
int hpfs_add_dirent(struct inode *i,
375+
const unsigned char *name, unsigned namelen,
372376
struct hpfs_dirent *new_de, int cdepth)
373377
{
374378
struct hpfs_inode_info *hpfs_inode = hpfs_i(i);
@@ -897,7 +901,8 @@ struct hpfs_dirent *map_pos_dirent(struct inode *inode, loff_t *posp,
897901

898902
/* Find a dirent in tree */
899903

900-
struct hpfs_dirent *map_dirent(struct inode *inode, dnode_secno dno, char *name, unsigned len,
904+
struct hpfs_dirent *map_dirent(struct inode *inode, dnode_secno dno,
905+
const unsigned char *name, unsigned len,
901906
dnode_secno *dd, struct quad_buffer_head *qbh)
902907
{
903908
struct dnode *dnode;
@@ -988,8 +993,8 @@ void hpfs_remove_dtree(struct super_block *s, dnode_secno dno)
988993
struct hpfs_dirent *map_fnode_dirent(struct super_block *s, fnode_secno fno,
989994
struct fnode *f, struct quad_buffer_head *qbh)
990995
{
991-
char *name1;
992-
char *name2;
996+
unsigned char *name1;
997+
unsigned char *name2;
993998
int name1len, name2len;
994999
struct dnode *d;
9951000
dnode_secno dno, downd;

‎fs/hpfs/ea.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ static char *get_indirect_ea(struct super_block *s, int ano, secno a, int size)
6262
return ret;
6363
}
6464

65-
static void set_indirect_ea(struct super_block *s, int ano, secno a, char *data,
66-
int size)
65+
static void set_indirect_ea(struct super_block *s, int ano, secno a,
66+
const char *data, int size)
6767
{
6868
hpfs_ea_write(s, a, ano, 0, size, data);
6969
}
@@ -186,7 +186,8 @@ char *hpfs_get_ea(struct super_block *s, struct fnode *fnode, char *key, int *si
186186
* This driver can't change sizes of eas ('cause I just don't need it).
187187
*/
188188

189-
void hpfs_set_ea(struct inode *inode, struct fnode *fnode, char *key, char *data, int size)
189+
void hpfs_set_ea(struct inode *inode, struct fnode *fnode, const char *key,
190+
const char *data, int size)
190191
{
191192
fnode_secno fno = inode->i_ino;
192193
struct super_block *s = inode->i_sb;

‎fs/hpfs/hpfs_fn.h‎

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ secno hpfs_bplus_lookup(struct super_block *, struct inode *, struct bplus_heade
215215
secno hpfs_add_sector_to_btree(struct super_block *, secno, int, unsigned);
216216
void hpfs_remove_btree(struct super_block *, struct bplus_header *);
217217
int hpfs_ea_read(struct super_block *, secno, int, unsigned, unsigned, char *);
218-
int hpfs_ea_write(struct super_block *, secno, int, unsigned, unsigned, char *);
218+
int hpfs_ea_write(struct super_block *, secno, int, unsigned, unsigned, const char *);
219219
void hpfs_ea_remove(struct super_block *, secno, int, unsigned);
220220
void hpfs_truncate_btree(struct super_block *, secno, int, unsigned);
221221
void hpfs_remove_fnode(struct super_block *, fnode_secno fno);
@@ -244,13 +244,17 @@ extern const struct file_operations hpfs_dir_ops;
244244

245245
void hpfs_add_pos(struct inode *, loff_t *);
246246
void hpfs_del_pos(struct inode *, loff_t *);
247-
struct hpfs_dirent *hpfs_add_de(struct super_block *, struct dnode *, unsigned char *, unsigned, secno);
248-
int hpfs_add_dirent(struct inode *, unsigned char *, unsigned, struct hpfs_dirent *, int);
247+
struct hpfs_dirent *hpfs_add_de(struct super_block *, struct dnode *,
248+
const unsigned char *, unsigned, secno);
249+
int hpfs_add_dirent(struct inode *, const unsigned char *, unsigned,
250+
struct hpfs_dirent *, int);
249251
int hpfs_remove_dirent(struct inode *, dnode_secno, struct hpfs_dirent *, struct quad_buffer_head *, int);
250252
void hpfs_count_dnodes(struct super_block *, dnode_secno, int *, int *, int *);
251253
dnode_secno hpfs_de_as_down_as_possible(struct super_block *, dnode_secno dno);
252254
struct hpfs_dirent *map_pos_dirent(struct inode *, loff_t *, struct quad_buffer_head *);
253-
struct hpfs_dirent *map_dirent(struct inode *, dnode_secno, char *, unsigned, dnode_secno *, struct quad_buffer_head *);
255+
struct hpfs_dirent *map_dirent(struct inode *, dnode_secno,
256+
const unsigned char *, unsigned, dnode_secno *,
257+
struct quad_buffer_head *);
254258
void hpfs_remove_dtree(struct super_block *, dnode_secno);
255259
struct hpfs_dirent *map_fnode_dirent(struct super_block *, fnode_secno, struct fnode *, struct quad_buffer_head *);
256260

@@ -259,7 +263,8 @@ struct hpfs_dirent *map_fnode_dirent(struct super_block *, fnode_secno, struct f
259263
void hpfs_ea_ext_remove(struct super_block *, secno, int, unsigned);
260264
int hpfs_read_ea(struct super_block *, struct fnode *, char *, char *, int);
261265
char *hpfs_get_ea(struct super_block *, struct fnode *, char *, int *);
262-
void hpfs_set_ea(struct inode *, struct fnode *, char *, char *, int);
266+
void hpfs_set_ea(struct inode *, struct fnode *, const char *,
267+
const char *, int);
263268

264269
/* file.c */
265270

@@ -282,7 +287,7 @@ void hpfs_delete_inode(struct inode *);
282287

283288
unsigned *hpfs_map_dnode_bitmap(struct super_block *, struct quad_buffer_head *);
284289
unsigned *hpfs_map_bitmap(struct super_block *, unsigned, struct quad_buffer_head *, char *);
285-
char *hpfs_load_code_page(struct super_block *, secno);
290+
unsigned char *hpfs_load_code_page(struct super_block *, secno);
286291
secno *hpfs_load_bitmap_directory(struct super_block *, secno bmp);
287292
struct fnode *hpfs_map_fnode(struct super_block *s, ino_t, struct buffer_head **);
288293
struct anode *hpfs_map_anode(struct super_block *s, anode_secno, struct buffer_head **);
@@ -292,12 +297,13 @@ dnode_secno hpfs_fnode_dno(struct super_block *s, ino_t ino);
292297
/* name.c */
293298

294299
unsigned char hpfs_upcase(unsigned char *, unsigned char);
295-
int hpfs_chk_name(unsigned char *, unsigned *);
296-
char *hpfs_translate_name(struct super_block *, unsigned char *, unsigned, int, int);
297-
int hpfs_compare_names(struct super_block *, unsigned char *, unsigned, unsigned char *, unsigned, int);
298-
int hpfs_is_name_long(unsigned char *, unsigned);
299-
void hpfs_adjust_length(unsigned char *, unsigned *);
300-
void hpfs_decide_conv(struct inode *, unsigned char *, unsigned);
300+
int hpfs_chk_name(const unsigned char *, unsigned *);
301+
unsigned char *hpfs_translate_name(struct super_block *, unsigned char *, unsigned, int, int);
302+
int hpfs_compare_names(struct super_block *, const unsigned char *, unsigned,
303+
const unsigned char *, unsigned, int);
304+
int hpfs_is_name_long(const unsigned char *, unsigned);
305+
void hpfs_adjust_length(const unsigned char *, unsigned *);
306+
void hpfs_decide_conv(struct inode *, const unsigned char *, unsigned);
301307

302308
/* namei.c */
303309

‎fs/hpfs/inode.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void hpfs_read_inode(struct inode *i)
4646
struct fnode *fnode;
4747
struct super_block *sb = i->i_sb;
4848
struct hpfs_inode_info *hpfs_inode = hpfs_i(i);
49-
unsigned char *ea;
49+
void *ea;
5050
int ea_size;
5151

5252
if (!(fnode = hpfs_map_fnode(sb, i->i_ino, &bh))) {
@@ -112,7 +112,7 @@ void hpfs_read_inode(struct inode *i)
112112
}
113113
}
114114
if (fnode->dirflag) {
115-
unsigned n_dnodes, n_subdirs;
115+
int n_dnodes, n_subdirs;
116116
i->i_mode |= S_IFDIR;
117117
i->i_op = &hpfs_dir_iops;
118118
i->i_fop = &hpfs_dir_ops;

‎fs/hpfs/map.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ unsigned int *hpfs_map_bitmap(struct super_block *s, unsigned bmp_block,
3535
* lowercasing table
3636
*/
3737

38-
char *hpfs_load_code_page(struct super_block *s, secno cps)
38+
unsigned char *hpfs_load_code_page(struct super_block *s, secno cps)
3939
{
4040
struct buffer_head *bh;
4141
secno cpds;
@@ -71,7 +71,7 @@ char *hpfs_load_code_page(struct super_block *s, secno cps)
7171
brelse(bh);
7272
return NULL;
7373
}
74-
ptr = (char *)cpd + cpd->offs[cpi] + 6;
74+
ptr = (unsigned char *)cpd + cpd->offs[cpi] + 6;
7575
if (!(cp_table = kmalloc(256, GFP_KERNEL))) {
7676
printk("HPFS: out of memory for code page table\n");
7777
brelse(bh);
@@ -217,7 +217,7 @@ struct dnode *hpfs_map_dnode(struct super_block *s, unsigned secno,
217217
if ((dnode = hpfs_map_4sectors(s, secno, qbh, DNODE_RD_AHEAD)))
218218
if (hpfs_sb(s)->sb_chk) {
219219
unsigned p, pp = 0;
220-
unsigned char *d = (char *)dnode;
220+
unsigned char *d = (unsigned char *)dnode;
221221
int b = 0;
222222
if (dnode->magic != DNODE_MAGIC) {
223223
hpfs_error(s, "bad magic on dnode %08x", secno);

‎fs/hpfs/name.c‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88

99
#include "hpfs_fn.h"
1010

11-
static char *text_postfix[]={
11+
static const char *text_postfix[]={
1212
".ASM", ".BAS", ".BAT", ".C", ".CC", ".CFG", ".CMD", ".CON", ".CPP", ".DEF",
1313
".DOC", ".DPR", ".ERX", ".H", ".HPP", ".HTM", ".HTML", ".JAVA", ".LOG", ".PAS",
1414
".RC", ".TEX", ".TXT", ".Y", ""};
1515

16-
static char *text_prefix[]={
16+
static const char *text_prefix[]={
1717
"AUTOEXEC.", "CHANGES", "COPYING", "CONFIG.", "CREDITS", "FAQ", "FILE_ID.DIZ",
1818
"MAKEFILE", "READ.ME", "README", "TERMCAP", ""};
1919

20-
void hpfs_decide_conv(struct inode *inode, unsigned char *name, unsigned len)
20+
void hpfs_decide_conv(struct inode *inode, const unsigned char *name, unsigned len)
2121
{
2222
struct hpfs_inode_info *hpfs_inode = hpfs_i(inode);
2323
int i;
@@ -71,7 +71,7 @@ static inline unsigned char locase(unsigned char *dir, unsigned char a)
7171
return dir[a];
7272
}
7373

74-
int hpfs_chk_name(unsigned char *name, unsigned *len)
74+
int hpfs_chk_name(const unsigned char *name, unsigned *len)
7575
{
7676
int i;
7777
if (*len > 254) return -ENAMETOOLONG;
@@ -83,10 +83,10 @@ int hpfs_chk_name(unsigned char *name, unsigned *len)
8383
return 0;
8484
}
8585

86-
char *hpfs_translate_name(struct super_block *s, unsigned char *from,
86+
unsigned char *hpfs_translate_name(struct super_block *s, unsigned char *from,
8787
unsigned len, int lc, int lng)
8888
{
89-
char *to;
89+
unsigned char *to;
9090
int i;
9191
if (hpfs_sb(s)->sb_chk >= 2) if (hpfs_is_name_long(from, len) != lng) {
9292
printk("HPFS: Long name flag mismatch - name ");
@@ -103,8 +103,9 @@ char *hpfs_translate_name(struct super_block *s, unsigned char *from,
103103
return to;
104104
}
105105

106-
int hpfs_compare_names(struct super_block *s, unsigned char *n1, unsigned l1,
107-
unsigned char *n2, unsigned l2, int last)
106+
int hpfs_compare_names(struct super_block *s,
107+
const unsigned char *n1, unsigned l1,
108+
const unsigned char *n2, unsigned l2, int last)
108109
{
109110
unsigned l = l1 < l2 ? l1 : l2;
110111
unsigned i;
@@ -120,7 +121,7 @@ int hpfs_compare_names(struct super_block *s, unsigned char *n1, unsigned l1,
120121
return 0;
121122
}
122123

123-
int hpfs_is_name_long(unsigned char *name, unsigned len)
124+
int hpfs_is_name_long(const unsigned char *name, unsigned len)
124125
{
125126
int i,j;
126127
for (i = 0; i < len && name[i] != '.'; i++)
@@ -134,7 +135,7 @@ int hpfs_is_name_long(unsigned char *name, unsigned len)
134135

135136
/* OS/2 clears dots and spaces at the end of file name, so we have to */
136137

137-
void hpfs_adjust_length(unsigned char *name, unsigned *len)
138+
void hpfs_adjust_length(const unsigned char *name, unsigned *len)
138139
{
139140
if (!*len) return;
140141
if (*len == 1 && name[0] == '.') return;

0 commit comments

Comments
 (0)