diff options
Diffstat (limited to 'fs')
-rw-r--r-- | fs/squashfs/cache.c | 29 | ||||
-rw-r--r-- | fs/squashfs/export.c | 19 | ||||
-rw-r--r-- | fs/squashfs/fragment.c | 19 | ||||
-rw-r--r-- | fs/squashfs/id.c | 18 | ||||
-rw-r--r-- | fs/squashfs/squashfs.h | 2 | ||||
-rw-r--r-- | fs/squashfs/super.c | 21 | ||||
-rw-r--r-- | fs/squashfs/xattr_id.c | 34 |
7 files changed, 44 insertions, 98 deletions
diff --git a/fs/squashfs/cache.c b/fs/squashfs/cache.c index 26b15ae34d6f..20c8df1b7efc 100644 --- a/fs/squashfs/cache.c +++ b/fs/squashfs/cache.c | |||
@@ -393,19 +393,36 @@ struct squashfs_cache_entry *squashfs_get_datablock(struct super_block *sb, | |||
393 | /* | 393 | /* |
394 | * Read a filesystem table (uncompressed sequence of bytes) from disk | 394 | * Read a filesystem table (uncompressed sequence of bytes) from disk |
395 | */ | 395 | */ |
396 | int squashfs_read_table(struct super_block *sb, void *buffer, u64 block, | 396 | void *squashfs_read_table(struct super_block *sb, u64 block, int length) |
397 | int length) | ||
398 | { | 397 | { |
399 | int pages = (length + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; | 398 | int pages = (length + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; |
400 | int i, res; | 399 | int i, res; |
401 | void **data = kcalloc(pages, sizeof(void *), GFP_KERNEL); | 400 | void *table, *buffer, **data; |
402 | if (data == NULL) | 401 | |
403 | return -ENOMEM; | 402 | table = buffer = kmalloc(length, GFP_KERNEL); |
403 | if (table == NULL) | ||
404 | return ERR_PTR(-ENOMEM); | ||
405 | |||
406 | data = kcalloc(pages, sizeof(void *), GFP_KERNEL); | ||
407 | if (data == NULL) { | ||
408 | res = -ENOMEM; | ||
409 | goto failed; | ||
410 | } | ||
404 | 411 | ||
405 | for (i = 0; i < pages; i++, buffer += PAGE_CACHE_SIZE) | 412 | for (i = 0; i < pages; i++, buffer += PAGE_CACHE_SIZE) |
406 | data[i] = buffer; | 413 | data[i] = buffer; |
414 | |||
407 | res = squashfs_read_data(sb, data, block, length | | 415 | res = squashfs_read_data(sb, data, block, length | |
408 | SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length, pages); | 416 | SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length, pages); |
417 | |||
409 | kfree(data); | 418 | kfree(data); |
410 | return res; | 419 | |
420 | if (res < 0) | ||
421 | goto failed; | ||
422 | |||
423 | return table; | ||
424 | |||
425 | failed: | ||
426 | kfree(table); | ||
427 | return ERR_PTR(res); | ||
411 | } | 428 | } |
diff --git a/fs/squashfs/export.c b/fs/squashfs/export.c index 7f93d5a9ee05..cc6dd90cee6a 100644 --- a/fs/squashfs/export.c +++ b/fs/squashfs/export.c | |||
@@ -124,27 +124,10 @@ __le64 *squashfs_read_inode_lookup_table(struct super_block *sb, | |||
124 | u64 lookup_table_start, unsigned int inodes) | 124 | u64 lookup_table_start, unsigned int inodes) |
125 | { | 125 | { |
126 | unsigned int length = SQUASHFS_LOOKUP_BLOCK_BYTES(inodes); | 126 | unsigned int length = SQUASHFS_LOOKUP_BLOCK_BYTES(inodes); |
127 | __le64 *inode_lookup_table; | ||
128 | int err; | ||
129 | 127 | ||
130 | TRACE("In read_inode_lookup_table, length %d\n", length); | 128 | TRACE("In read_inode_lookup_table, length %d\n", length); |
131 | 129 | ||
132 | /* Allocate inode lookup table indexes */ | 130 | return squashfs_read_table(sb, lookup_table_start, length); |
133 | inode_lookup_table = kmalloc(length, GFP_KERNEL); | ||
134 | if (inode_lookup_table == NULL) { | ||
135 | ERROR("Failed to allocate inode lookup table\n"); | ||
136 | return ERR_PTR(-ENOMEM); | ||
137 | } | ||
138 | |||
139 | err = squashfs_read_table(sb, inode_lookup_table, lookup_table_start, | ||
140 | length); | ||
141 | if (err < 0) { | ||
142 | ERROR("unable to read inode lookup table\n"); | ||
143 | kfree(inode_lookup_table); | ||
144 | return ERR_PTR(err); | ||
145 | } | ||
146 | |||
147 | return inode_lookup_table; | ||
148 | } | 131 | } |
149 | 132 | ||
150 | 133 | ||
diff --git a/fs/squashfs/fragment.c b/fs/squashfs/fragment.c index 7eef571443c6..567093db5870 100644 --- a/fs/squashfs/fragment.c +++ b/fs/squashfs/fragment.c | |||
@@ -74,23 +74,6 @@ __le64 *squashfs_read_fragment_index_table(struct super_block *sb, | |||
74 | u64 fragment_table_start, unsigned int fragments) | 74 | u64 fragment_table_start, unsigned int fragments) |
75 | { | 75 | { |
76 | unsigned int length = SQUASHFS_FRAGMENT_INDEX_BYTES(fragments); | 76 | unsigned int length = SQUASHFS_FRAGMENT_INDEX_BYTES(fragments); |
77 | __le64 *fragment_index; | ||
78 | int err; | ||
79 | 77 | ||
80 | /* Allocate fragment lookup table indexes */ | 78 | return squashfs_read_table(sb, fragment_table_start, length); |
81 | fragment_index = kmalloc(length, GFP_KERNEL); | ||
82 | if (fragment_index == NULL) { | ||
83 | ERROR("Failed to allocate fragment index table\n"); | ||
84 | return ERR_PTR(-ENOMEM); | ||
85 | } | ||
86 | |||
87 | err = squashfs_read_table(sb, fragment_index, fragment_table_start, | ||
88 | length); | ||
89 | if (err < 0) { | ||
90 | ERROR("unable to read fragment index table\n"); | ||
91 | kfree(fragment_index); | ||
92 | return ERR_PTR(err); | ||
93 | } | ||
94 | |||
95 | return fragment_index; | ||
96 | } | 79 | } |
diff --git a/fs/squashfs/id.c b/fs/squashfs/id.c index d8f32452638e..2fdac6703b48 100644 --- a/fs/squashfs/id.c +++ b/fs/squashfs/id.c | |||
@@ -69,24 +69,8 @@ __le64 *squashfs_read_id_index_table(struct super_block *sb, | |||
69 | u64 id_table_start, unsigned short no_ids) | 69 | u64 id_table_start, unsigned short no_ids) |
70 | { | 70 | { |
71 | unsigned int length = SQUASHFS_ID_BLOCK_BYTES(no_ids); | 71 | unsigned int length = SQUASHFS_ID_BLOCK_BYTES(no_ids); |
72 | __le64 *id_table; | ||
73 | int err; | ||
74 | 72 | ||
75 | TRACE("In read_id_index_table, length %d\n", length); | 73 | TRACE("In read_id_index_table, length %d\n", length); |
76 | 74 | ||
77 | /* Allocate id lookup table indexes */ | 75 | return squashfs_read_table(sb, id_table_start, length); |
78 | id_table = kmalloc(length, GFP_KERNEL); | ||
79 | if (id_table == NULL) { | ||
80 | ERROR("Failed to allocate id index table\n"); | ||
81 | return ERR_PTR(-ENOMEM); | ||
82 | } | ||
83 | |||
84 | err = squashfs_read_table(sb, id_table, id_table_start, length); | ||
85 | if (err < 0) { | ||
86 | ERROR("unable to read id index table\n"); | ||
87 | kfree(id_table); | ||
88 | return ERR_PTR(err); | ||
89 | } | ||
90 | |||
91 | return id_table; | ||
92 | } | 76 | } |
diff --git a/fs/squashfs/squashfs.h b/fs/squashfs/squashfs.h index 1f2e608b8785..d622e849a451 100644 --- a/fs/squashfs/squashfs.h +++ b/fs/squashfs/squashfs.h | |||
@@ -44,7 +44,7 @@ extern struct squashfs_cache_entry *squashfs_get_fragment(struct super_block *, | |||
44 | u64, int); | 44 | u64, int); |
45 | extern struct squashfs_cache_entry *squashfs_get_datablock(struct super_block *, | 45 | extern struct squashfs_cache_entry *squashfs_get_datablock(struct super_block *, |
46 | u64, int); | 46 | u64, int); |
47 | extern int squashfs_read_table(struct super_block *, void *, u64, int); | 47 | extern void *squashfs_read_table(struct super_block *, u64, int); |
48 | 48 | ||
49 | /* decompressor.c */ | 49 | /* decompressor.c */ |
50 | extern const struct squashfs_decompressor *squashfs_lookup_decompressor(int); | 50 | extern const struct squashfs_decompressor *squashfs_lookup_decompressor(int); |
diff --git a/fs/squashfs/super.c b/fs/squashfs/super.c index 5c8184c061a4..d16c39263f39 100644 --- a/fs/squashfs/super.c +++ b/fs/squashfs/super.c | |||
@@ -95,12 +95,6 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent) | |||
95 | } | 95 | } |
96 | msblk = sb->s_fs_info; | 96 | msblk = sb->s_fs_info; |
97 | 97 | ||
98 | sblk = kzalloc(sizeof(*sblk), GFP_KERNEL); | ||
99 | if (sblk == NULL) { | ||
100 | ERROR("Failed to allocate squashfs_super_block\n"); | ||
101 | goto failure; | ||
102 | } | ||
103 | |||
104 | msblk->devblksize = sb_min_blocksize(sb, BLOCK_SIZE); | 98 | msblk->devblksize = sb_min_blocksize(sb, BLOCK_SIZE); |
105 | msblk->devblksize_log2 = ffz(~msblk->devblksize); | 99 | msblk->devblksize_log2 = ffz(~msblk->devblksize); |
106 | 100 | ||
@@ -114,10 +108,12 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent) | |||
114 | * of bytes_used) we need to set it to an initial sensible dummy value | 108 | * of bytes_used) we need to set it to an initial sensible dummy value |
115 | */ | 109 | */ |
116 | msblk->bytes_used = sizeof(*sblk); | 110 | msblk->bytes_used = sizeof(*sblk); |
117 | err = squashfs_read_table(sb, sblk, SQUASHFS_START, sizeof(*sblk)); | 111 | sblk = squashfs_read_table(sb, SQUASHFS_START, sizeof(*sblk)); |
118 | 112 | ||
119 | if (err < 0) { | 113 | if (IS_ERR(sblk)) { |
120 | ERROR("unable to read squashfs_super_block\n"); | 114 | ERROR("unable to read squashfs_super_block\n"); |
115 | err = PTR_ERR(sblk); | ||
116 | sblk = NULL; | ||
121 | goto failed_mount; | 117 | goto failed_mount; |
122 | } | 118 | } |
123 | 119 | ||
@@ -222,6 +218,7 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent) | |||
222 | msblk->id_table = squashfs_read_id_index_table(sb, | 218 | msblk->id_table = squashfs_read_id_index_table(sb, |
223 | le64_to_cpu(sblk->id_table_start), le16_to_cpu(sblk->no_ids)); | 219 | le64_to_cpu(sblk->id_table_start), le16_to_cpu(sblk->no_ids)); |
224 | if (IS_ERR(msblk->id_table)) { | 220 | if (IS_ERR(msblk->id_table)) { |
221 | ERROR("unable to read id index table\n"); | ||
225 | err = PTR_ERR(msblk->id_table); | 222 | err = PTR_ERR(msblk->id_table); |
226 | msblk->id_table = NULL; | 223 | msblk->id_table = NULL; |
227 | goto failed_mount; | 224 | goto failed_mount; |
@@ -242,6 +239,7 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent) | |||
242 | msblk->fragment_index = squashfs_read_fragment_index_table(sb, | 239 | msblk->fragment_index = squashfs_read_fragment_index_table(sb, |
243 | le64_to_cpu(sblk->fragment_table_start), fragments); | 240 | le64_to_cpu(sblk->fragment_table_start), fragments); |
244 | if (IS_ERR(msblk->fragment_index)) { | 241 | if (IS_ERR(msblk->fragment_index)) { |
242 | ERROR("unable to read fragment index table\n"); | ||
245 | err = PTR_ERR(msblk->fragment_index); | 243 | err = PTR_ERR(msblk->fragment_index); |
246 | msblk->fragment_index = NULL; | 244 | msblk->fragment_index = NULL; |
247 | goto failed_mount; | 245 | goto failed_mount; |
@@ -256,6 +254,7 @@ allocate_lookup_table: | |||
256 | msblk->inode_lookup_table = squashfs_read_inode_lookup_table(sb, | 254 | msblk->inode_lookup_table = squashfs_read_inode_lookup_table(sb, |
257 | lookup_table_start, msblk->inodes); | 255 | lookup_table_start, msblk->inodes); |
258 | if (IS_ERR(msblk->inode_lookup_table)) { | 256 | if (IS_ERR(msblk->inode_lookup_table)) { |
257 | ERROR("unable to read inode lookup table\n"); | ||
259 | err = PTR_ERR(msblk->inode_lookup_table); | 258 | err = PTR_ERR(msblk->inode_lookup_table); |
260 | msblk->inode_lookup_table = NULL; | 259 | msblk->inode_lookup_table = NULL; |
261 | goto failed_mount; | 260 | goto failed_mount; |
@@ -273,6 +272,7 @@ allocate_xattr_table: | |||
273 | msblk->xattr_id_table = squashfs_read_xattr_id_table(sb, | 272 | msblk->xattr_id_table = squashfs_read_xattr_id_table(sb, |
274 | xattr_id_table_start, &msblk->xattr_table, &msblk->xattr_ids); | 273 | xattr_id_table_start, &msblk->xattr_table, &msblk->xattr_ids); |
275 | if (IS_ERR(msblk->xattr_id_table)) { | 274 | if (IS_ERR(msblk->xattr_id_table)) { |
275 | ERROR("unable to read xattr id index table\n"); | ||
276 | err = PTR_ERR(msblk->xattr_id_table); | 276 | err = PTR_ERR(msblk->xattr_id_table); |
277 | msblk->xattr_id_table = NULL; | 277 | msblk->xattr_id_table = NULL; |
278 | if (err != -ENOTSUPP) | 278 | if (err != -ENOTSUPP) |
@@ -318,11 +318,6 @@ failed_mount: | |||
318 | sb->s_fs_info = NULL; | 318 | sb->s_fs_info = NULL; |
319 | kfree(sblk); | 319 | kfree(sblk); |
320 | return err; | 320 | return err; |
321 | |||
322 | failure: | ||
323 | kfree(sb->s_fs_info); | ||
324 | sb->s_fs_info = NULL; | ||
325 | return -ENOMEM; | ||
326 | } | 321 | } |
327 | 322 | ||
328 | 323 | ||
diff --git a/fs/squashfs/xattr_id.c b/fs/squashfs/xattr_id.c index 05385dbe1465..51a7bd0cc449 100644 --- a/fs/squashfs/xattr_id.c +++ b/fs/squashfs/xattr_id.c | |||
@@ -67,34 +67,18 @@ __le64 *squashfs_read_xattr_id_table(struct super_block *sb, u64 start, | |||
67 | u64 *xattr_table_start, int *xattr_ids) | 67 | u64 *xattr_table_start, int *xattr_ids) |
68 | { | 68 | { |
69 | unsigned int len; | 69 | unsigned int len; |
70 | __le64 *xid_table; | 70 | struct squashfs_xattr_id_table *id_table; |
71 | struct squashfs_xattr_id_table id_table; | 71 | |
72 | int err; | 72 | id_table = squashfs_read_table(sb, start, sizeof(*id_table)); |
73 | if (IS_ERR(id_table)) | ||
74 | return (__le64 *) id_table; | ||
73 | 75 | ||
74 | err = squashfs_read_table(sb, &id_table, start, sizeof(id_table)); | 76 | *xattr_table_start = le64_to_cpu(id_table->xattr_table_start); |
75 | if (err < 0) { | 77 | *xattr_ids = le32_to_cpu(id_table->xattr_ids); |
76 | ERROR("unable to read xattr id table\n"); | 78 | kfree(id_table); |
77 | return ERR_PTR(err); | ||
78 | } | ||
79 | *xattr_table_start = le64_to_cpu(id_table.xattr_table_start); | ||
80 | *xattr_ids = le32_to_cpu(id_table.xattr_ids); | ||
81 | len = SQUASHFS_XATTR_BLOCK_BYTES(*xattr_ids); | 79 | len = SQUASHFS_XATTR_BLOCK_BYTES(*xattr_ids); |
82 | 80 | ||
83 | TRACE("In read_xattr_index_table, length %d\n", len); | 81 | TRACE("In read_xattr_index_table, length %d\n", len); |
84 | 82 | ||
85 | /* Allocate xattr id lookup table indexes */ | 83 | return squashfs_read_table(sb, start + sizeof(*id_table), len); |
86 | xid_table = kmalloc(len, GFP_KERNEL); | ||
87 | if (xid_table == NULL) { | ||
88 | ERROR("Failed to allocate xattr id index table\n"); | ||
89 | return ERR_PTR(-ENOMEM); | ||
90 | } | ||
91 | |||
92 | err = squashfs_read_table(sb, xid_table, start + sizeof(id_table), len); | ||
93 | if (err < 0) { | ||
94 | ERROR("unable to read xattr id index table\n"); | ||
95 | kfree(xid_table); | ||
96 | return ERR_PTR(err); | ||
97 | } | ||
98 | |||
99 | return xid_table; | ||
100 | } | 84 | } |