aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2015-06-24 23:07:10 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2015-06-24 23:07:10 -0400
commita7296b49fb40525a5c42f650617749def3d25bcc (patch)
tree2f7e0623ab09187b62732952a092ef0114cab844
parent1e467e68e51b116e026247d0defc806b462c095e (diff)
parent792352cb160e654f0b64182550ee702a790fe4d0 (diff)
Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs
Pull UDF fixes and cleanups from Jan Kara: "The contains some small fixes and improvements in error handling for UDF. Bundled is also one ext3 coding style fix and a fix in quota documentation" * 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs: udf: fix udf_load_pvoldesc() udf: remove double err declaration in udf_file_write_iter() UDF: support NFSv2 export fs: ext3: super: fixed a space coding style issue quota: Update documentation udf: Return error from udf_find_entry() udf: Make udf_get_filename() return error instead of 0 length file name udf: bug on exotic flag in udf_get_filename() udf: improve error management in udf_CS0toNLS() udf: improve error management in udf_CS0toUTF8() udf: unicode: update function name in comments udf: remove unnecessary test in udf_build_ustr_exact() udf: Return -ENOMEM when allocation fails in udf_get_filename()
-rw-r--r--Documentation/filesystems/quota.txt5
-rw-r--r--fs/ext3/super.c2
-rw-r--r--fs/udf/dir.c2
-rw-r--r--fs/udf/file.c2
-rw-r--r--fs/udf/namei.c95
-rw-r--r--fs/udf/super.c26
-rw-r--r--fs/udf/symlink.c3
-rw-r--r--fs/udf/unicode.c49
8 files changed, 124 insertions, 60 deletions
diff --git a/Documentation/filesystems/quota.txt b/Documentation/filesystems/quota.txt
index 5e8de25bf0f1..29fc01552646 100644
--- a/Documentation/filesystems/quota.txt
+++ b/Documentation/filesystems/quota.txt
@@ -32,7 +32,10 @@ The interface uses generic netlink framework (see
32http://lwn.net/Articles/208755/ and http://people.suug.ch/~tgr/libnl/ for more 32http://lwn.net/Articles/208755/ and http://people.suug.ch/~tgr/libnl/ for more
33details about this layer). The name of the quota generic netlink interface 33details about this layer). The name of the quota generic netlink interface
34is "VFS_DQUOT". Definitions of constants below are in <linux/quota.h>. 34is "VFS_DQUOT". Definitions of constants below are in <linux/quota.h>.
35 Currently, the interface supports only one message type QUOTA_NL_C_WARNING. 35Since the quota netlink protocol is not namespace aware, quota netlink messages
36are sent only in initial network namespace.
37
38Currently, the interface supports only one message type QUOTA_NL_C_WARNING.
36This command is used to send a notification about any of the above mentioned 39This command is used to send a notification about any of the above mentioned
37events. Each message has six attributes. These are (type of the argument is 40events. Each message has six attributes. These are (type of the argument is
38in parentheses): 41in parentheses):
diff --git a/fs/ext3/super.c b/fs/ext3/super.c
index a9312f0a54e5..5ed0044fbb37 100644
--- a/fs/ext3/super.c
+++ b/fs/ext3/super.c
@@ -1908,7 +1908,7 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
1908 sbi->s_mount_state = le16_to_cpu(es->s_state); 1908 sbi->s_mount_state = le16_to_cpu(es->s_state);
1909 sbi->s_addr_per_block_bits = ilog2(EXT3_ADDR_PER_BLOCK(sb)); 1909 sbi->s_addr_per_block_bits = ilog2(EXT3_ADDR_PER_BLOCK(sb));
1910 sbi->s_desc_per_block_bits = ilog2(EXT3_DESC_PER_BLOCK(sb)); 1910 sbi->s_desc_per_block_bits = ilog2(EXT3_DESC_PER_BLOCK(sb));
1911 for (i=0; i < 4; i++) 1911 for (i = 0; i < 4; i++)
1912 sbi->s_hash_seed[i] = le32_to_cpu(es->s_hash_seed[i]); 1912 sbi->s_hash_seed[i] = le32_to_cpu(es->s_hash_seed[i]);
1913 sbi->s_def_hash_version = es->s_def_hash_version; 1913 sbi->s_def_hash_version = es->s_def_hash_version;
1914 i = le32_to_cpu(es->s_flags); 1914 i = le32_to_cpu(es->s_flags);
diff --git a/fs/udf/dir.c b/fs/udf/dir.c
index 541a12b5792d..541d9c65014d 100644
--- a/fs/udf/dir.c
+++ b/fs/udf/dir.c
@@ -168,7 +168,7 @@ static int udf_readdir(struct file *file, struct dir_context *ctx)
168 } 168 }
169 169
170 flen = udf_get_filename(sb, nameptr, lfi, fname, UDF_NAME_LEN); 170 flen = udf_get_filename(sb, nameptr, lfi, fname, UDF_NAME_LEN);
171 if (!flen) 171 if (flen < 0)
172 continue; 172 continue;
173 173
174 tloc = lelb_to_cpu(cfi.icb.extLocation); 174 tloc = lelb_to_cpu(cfi.icb.extLocation);
diff --git a/fs/udf/file.c b/fs/udf/file.c
index 7a95b8fed302..bddf3d071dae 100644
--- a/fs/udf/file.c
+++ b/fs/udf/file.c
@@ -152,8 +152,6 @@ out:
152 mutex_unlock(&inode->i_mutex); 152 mutex_unlock(&inode->i_mutex);
153 153
154 if (retval > 0) { 154 if (retval > 0) {
155 ssize_t err;
156
157 mark_inode_dirty(inode); 155 mark_inode_dirty(inode);
158 err = generic_write_sync(file, iocb->ki_pos - retval, retval); 156 err = generic_write_sync(file, iocb->ki_pos - retval, retval);
159 if (err < 0) 157 if (err < 0)
diff --git a/fs/udf/namei.c b/fs/udf/namei.c
index 5c03f0dfb98b..c97b5a8d1e24 100644
--- a/fs/udf/namei.c
+++ b/fs/udf/namei.c
@@ -138,6 +138,25 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi,
138 return 0; 138 return 0;
139} 139}
140 140
141/**
142 * udf_find_entry - find entry in given directory.
143 *
144 * @dir: directory inode to search in
145 * @child: qstr of the name
146 * @fibh: buffer head / inode with file identifier descriptor we found
147 * @cfi: found file identifier descriptor with given name
148 *
149 * This function searches in the directory @dir for a file name @child. When
150 * found, @fibh points to the buffer head(s) (bh is NULL for in ICB
151 * directories) containing the file identifier descriptor (FID). In that case
152 * the function returns pointer to the FID in the buffer or inode - but note
153 * that FID may be split among two buffers (blocks) so accessing it via that
154 * pointer isn't easily possible. This pointer can be used only as an iterator
155 * for other directory manipulation functions. For inspection of the FID @cfi
156 * can be used - the found FID is copied there.
157 *
158 * Returns pointer to FID, NULL when nothing found, or error code.
159 */
141static struct fileIdentDesc *udf_find_entry(struct inode *dir, 160static struct fileIdentDesc *udf_find_entry(struct inode *dir,
142 const struct qstr *child, 161 const struct qstr *child,
143 struct udf_fileident_bh *fibh, 162 struct udf_fileident_bh *fibh,
@@ -167,8 +186,11 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir,
167 fibh->soffset = fibh->eoffset = f_pos & (sb->s_blocksize - 1); 186 fibh->soffset = fibh->eoffset = f_pos & (sb->s_blocksize - 1);
168 if (dinfo->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) { 187 if (dinfo->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) {
169 if (inode_bmap(dir, f_pos >> sb->s_blocksize_bits, &epos, 188 if (inode_bmap(dir, f_pos >> sb->s_blocksize_bits, &epos,
170 &eloc, &elen, &offset) != (EXT_RECORDED_ALLOCATED >> 30)) 189 &eloc, &elen, &offset) != (EXT_RECORDED_ALLOCATED >> 30)) {
190 fi = ERR_PTR(-EIO);
171 goto out_err; 191 goto out_err;
192 }
193
172 block = udf_get_lb_pblock(sb, &eloc, offset); 194 block = udf_get_lb_pblock(sb, &eloc, offset);
173 if ((++offset << sb->s_blocksize_bits) < elen) { 195 if ((++offset << sb->s_blocksize_bits) < elen) {
174 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT) 196 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
@@ -179,19 +201,25 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir,
179 offset = 0; 201 offset = 0;
180 202
181 fibh->sbh = fibh->ebh = udf_tread(sb, block); 203 fibh->sbh = fibh->ebh = udf_tread(sb, block);
182 if (!fibh->sbh) 204 if (!fibh->sbh) {
205 fi = ERR_PTR(-EIO);
183 goto out_err; 206 goto out_err;
207 }
184 } 208 }
185 209
186 fname = kmalloc(UDF_NAME_LEN, GFP_NOFS); 210 fname = kmalloc(UDF_NAME_LEN, GFP_NOFS);
187 if (!fname) 211 if (!fname) {
212 fi = ERR_PTR(-ENOMEM);
188 goto out_err; 213 goto out_err;
214 }
189 215
190 while (f_pos < size) { 216 while (f_pos < size) {
191 fi = udf_fileident_read(dir, &f_pos, fibh, cfi, &epos, &eloc, 217 fi = udf_fileident_read(dir, &f_pos, fibh, cfi, &epos, &eloc,
192 &elen, &offset); 218 &elen, &offset);
193 if (!fi) 219 if (!fi) {
220 fi = ERR_PTR(-EIO);
194 goto out_err; 221 goto out_err;
222 }
195 223
196 liu = le16_to_cpu(cfi->lengthOfImpUse); 224 liu = le16_to_cpu(cfi->lengthOfImpUse);
197 lfi = cfi->lengthFileIdent; 225 lfi = cfi->lengthFileIdent;
@@ -234,12 +262,17 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir,
234 continue; 262 continue;
235 263
236 flen = udf_get_filename(sb, nameptr, lfi, fname, UDF_NAME_LEN); 264 flen = udf_get_filename(sb, nameptr, lfi, fname, UDF_NAME_LEN);
237 if (flen && udf_match(flen, fname, child->len, child->name)) 265 if (flen < 0) {
266 fi = ERR_PTR(flen);
267 goto out_err;
268 }
269
270 if (udf_match(flen, fname, child->len, child->name))
238 goto out_ok; 271 goto out_ok;
239 } 272 }
240 273
241out_err:
242 fi = NULL; 274 fi = NULL;
275out_err:
243 if (fibh->sbh != fibh->ebh) 276 if (fibh->sbh != fibh->ebh)
244 brelse(fibh->ebh); 277 brelse(fibh->ebh);
245 brelse(fibh->sbh); 278 brelse(fibh->sbh);
@@ -256,6 +289,7 @@ static struct dentry *udf_lookup(struct inode *dir, struct dentry *dentry,
256 struct inode *inode = NULL; 289 struct inode *inode = NULL;
257 struct fileIdentDesc cfi; 290 struct fileIdentDesc cfi;
258 struct udf_fileident_bh fibh; 291 struct udf_fileident_bh fibh;
292 struct fileIdentDesc *fi;
259 293
260 if (dentry->d_name.len > UDF_NAME_LEN - 2) 294 if (dentry->d_name.len > UDF_NAME_LEN - 2)
261 return ERR_PTR(-ENAMETOOLONG); 295 return ERR_PTR(-ENAMETOOLONG);
@@ -275,7 +309,11 @@ static struct dentry *udf_lookup(struct inode *dir, struct dentry *dentry,
275 } else 309 } else
276#endif /* UDF_RECOVERY */ 310#endif /* UDF_RECOVERY */
277 311
278 if (udf_find_entry(dir, &dentry->d_name, &fibh, &cfi)) { 312 fi = udf_find_entry(dir, &dentry->d_name, &fibh, &cfi);
313 if (IS_ERR(fi))
314 return ERR_CAST(fi);
315
316 if (fi) {
279 struct kernel_lb_addr loc; 317 struct kernel_lb_addr loc;
280 318
281 if (fibh.sbh != fibh.ebh) 319 if (fibh.sbh != fibh.ebh)
@@ -774,8 +812,11 @@ static int udf_rmdir(struct inode *dir, struct dentry *dentry)
774 812
775 retval = -ENOENT; 813 retval = -ENOENT;
776 fi = udf_find_entry(dir, &dentry->d_name, &fibh, &cfi); 814 fi = udf_find_entry(dir, &dentry->d_name, &fibh, &cfi);
777 if (!fi) 815 if (IS_ERR_OR_NULL(fi)) {
816 if (fi)
817 retval = PTR_ERR(fi);
778 goto out; 818 goto out;
819 }
779 820
780 retval = -EIO; 821 retval = -EIO;
781 tloc = lelb_to_cpu(cfi.icb.extLocation); 822 tloc = lelb_to_cpu(cfi.icb.extLocation);
@@ -817,8 +858,12 @@ static int udf_unlink(struct inode *dir, struct dentry *dentry)
817 858
818 retval = -ENOENT; 859 retval = -ENOENT;
819 fi = udf_find_entry(dir, &dentry->d_name, &fibh, &cfi); 860 fi = udf_find_entry(dir, &dentry->d_name, &fibh, &cfi);
820 if (!fi) 861
862 if (IS_ERR_OR_NULL(fi)) {
863 if (fi)
864 retval = PTR_ERR(fi);
821 goto out; 865 goto out;
866 }
822 867
823 retval = -EIO; 868 retval = -EIO;
824 tloc = lelb_to_cpu(cfi.icb.extLocation); 869 tloc = lelb_to_cpu(cfi.icb.extLocation);
@@ -1049,24 +1094,30 @@ static int udf_rename(struct inode *old_dir, struct dentry *old_dentry,
1049 struct udf_inode_info *old_iinfo = UDF_I(old_inode); 1094 struct udf_inode_info *old_iinfo = UDF_I(old_inode);
1050 1095
1051 ofi = udf_find_entry(old_dir, &old_dentry->d_name, &ofibh, &ocfi); 1096 ofi = udf_find_entry(old_dir, &old_dentry->d_name, &ofibh, &ocfi);
1052 if (ofi) { 1097 if (IS_ERR(ofi)) {
1053 if (ofibh.sbh != ofibh.ebh) 1098 retval = PTR_ERR(ofi);
1054 brelse(ofibh.ebh); 1099 goto end_rename;
1055 brelse(ofibh.sbh);
1056 } 1100 }
1101
1102 if (ofibh.sbh != ofibh.ebh)
1103 brelse(ofibh.ebh);
1104
1105 brelse(ofibh.sbh);
1057 tloc = lelb_to_cpu(ocfi.icb.extLocation); 1106 tloc = lelb_to_cpu(ocfi.icb.extLocation);
1058 if (!ofi || udf_get_lb_pblock(old_dir->i_sb, &tloc, 0) 1107 if (!ofi || udf_get_lb_pblock(old_dir->i_sb, &tloc, 0)
1059 != old_inode->i_ino) 1108 != old_inode->i_ino)
1060 goto end_rename; 1109 goto end_rename;
1061 1110
1062 nfi = udf_find_entry(new_dir, &new_dentry->d_name, &nfibh, &ncfi); 1111 nfi = udf_find_entry(new_dir, &new_dentry->d_name, &nfibh, &ncfi);
1063 if (nfi) { 1112 if (IS_ERR(nfi)) {
1064 if (!new_inode) { 1113 retval = PTR_ERR(nfi);
1065 if (nfibh.sbh != nfibh.ebh) 1114 goto end_rename;
1066 brelse(nfibh.ebh); 1115 }
1067 brelse(nfibh.sbh); 1116 if (nfi && !new_inode) {
1068 nfi = NULL; 1117 if (nfibh.sbh != nfibh.ebh)
1069 } 1118 brelse(nfibh.ebh);
1119 brelse(nfibh.sbh);
1120 nfi = NULL;
1070 } 1121 }
1071 if (S_ISDIR(old_inode->i_mode)) { 1122 if (S_ISDIR(old_inode->i_mode)) {
1072 int offset = udf_ext0_offset(old_inode); 1123 int offset = udf_ext0_offset(old_inode);
@@ -1221,7 +1272,7 @@ static struct dentry *udf_nfs_get_inode(struct super_block *sb, u32 block,
1221static struct dentry *udf_fh_to_dentry(struct super_block *sb, 1272static struct dentry *udf_fh_to_dentry(struct super_block *sb,
1222 struct fid *fid, int fh_len, int fh_type) 1273 struct fid *fid, int fh_len, int fh_type)
1223{ 1274{
1224 if ((fh_len != 3 && fh_len != 5) || 1275 if (fh_len < 3 ||
1225 (fh_type != FILEID_UDF_WITH_PARENT && 1276 (fh_type != FILEID_UDF_WITH_PARENT &&
1226 fh_type != FILEID_UDF_WITHOUT_PARENT)) 1277 fh_type != FILEID_UDF_WITHOUT_PARENT))
1227 return NULL; 1278 return NULL;
@@ -1233,7 +1284,7 @@ static struct dentry *udf_fh_to_dentry(struct super_block *sb,
1233static struct dentry *udf_fh_to_parent(struct super_block *sb, 1284static struct dentry *udf_fh_to_parent(struct super_block *sb,
1234 struct fid *fid, int fh_len, int fh_type) 1285 struct fid *fid, int fh_len, int fh_type)
1235{ 1286{
1236 if (fh_len != 5 || fh_type != FILEID_UDF_WITH_PARENT) 1287 if (fh_len < 5 || fh_type != FILEID_UDF_WITH_PARENT)
1237 return NULL; 1288 return NULL;
1238 1289
1239 return udf_nfs_get_inode(sb, fid->udf.parent_block, 1290 return udf_nfs_get_inode(sb, fid->udf.parent_block,
diff --git a/fs/udf/super.c b/fs/udf/super.c
index 6299f341967b..b96f190bc567 100644
--- a/fs/udf/super.c
+++ b/fs/udf/super.c
@@ -927,17 +927,23 @@ static int udf_load_pvoldesc(struct super_block *sb, sector_t block)
927#endif 927#endif
928 } 928 }
929 929
930 if (!udf_build_ustr(instr, pvoldesc->volIdent, 32)) 930 if (!udf_build_ustr(instr, pvoldesc->volIdent, 32)) {
931 if (udf_CS0toUTF8(outstr, instr)) { 931 ret = udf_CS0toUTF8(outstr, instr);
932 strncpy(UDF_SB(sb)->s_volume_ident, outstr->u_name, 932 if (ret < 0)
933 outstr->u_len > 31 ? 31 : outstr->u_len); 933 goto out_bh;
934 udf_debug("volIdent[] = '%s'\n", 934
935 UDF_SB(sb)->s_volume_ident); 935 strncpy(UDF_SB(sb)->s_volume_ident, outstr->u_name,
936 } 936 outstr->u_len > 31 ? 31 : outstr->u_len);
937 udf_debug("volIdent[] = '%s'\n", UDF_SB(sb)->s_volume_ident);
938 }
937 939
938 if (!udf_build_ustr(instr, pvoldesc->volSetIdent, 128)) 940 if (!udf_build_ustr(instr, pvoldesc->volSetIdent, 128)) {
939 if (udf_CS0toUTF8(outstr, instr)) 941 ret = udf_CS0toUTF8(outstr, instr);
940 udf_debug("volSetIdent[] = '%s'\n", outstr->u_name); 942 if (ret < 0)
943 goto out_bh;
944
945 udf_debug("volSetIdent[] = '%s'\n", outstr->u_name);
946 }
941 947
942 ret = 0; 948 ret = 0;
943out_bh: 949out_bh:
diff --git a/fs/udf/symlink.c b/fs/udf/symlink.c
index 8dfbc4025e2f..862535b3ba58 100644
--- a/fs/udf/symlink.c
+++ b/fs/udf/symlink.c
@@ -82,6 +82,9 @@ static int udf_pc_to_char(struct super_block *sb, unsigned char *from,
82 comp_len = udf_get_filename(sb, pc->componentIdent, 82 comp_len = udf_get_filename(sb, pc->componentIdent,
83 pc->lengthComponentIdent, 83 pc->lengthComponentIdent,
84 p, tolen); 84 p, tolen);
85 if (comp_len < 0)
86 return comp_len;
87
85 p += comp_len; 88 p += comp_len;
86 tolen -= comp_len; 89 tolen -= comp_len;
87 if (tolen == 0) 90 if (tolen == 0)
diff --git a/fs/udf/unicode.c b/fs/udf/unicode.c
index b84fee372734..ab478e62baae 100644
--- a/fs/udf/unicode.c
+++ b/fs/udf/unicode.c
@@ -68,21 +68,16 @@ int udf_build_ustr(struct ustr *dest, dstring *ptr, int size)
68/* 68/*
69 * udf_build_ustr_exact 69 * udf_build_ustr_exact
70 */ 70 */
71static int udf_build_ustr_exact(struct ustr *dest, dstring *ptr, int exactsize) 71static void udf_build_ustr_exact(struct ustr *dest, dstring *ptr, int exactsize)
72{ 72{
73 if ((!dest) || (!ptr) || (!exactsize))
74 return -1;
75
76 memset(dest, 0, sizeof(struct ustr)); 73 memset(dest, 0, sizeof(struct ustr));
77 dest->u_cmpID = ptr[0]; 74 dest->u_cmpID = ptr[0];
78 dest->u_len = exactsize - 1; 75 dest->u_len = exactsize - 1;
79 memcpy(dest->u_name, ptr + 1, exactsize - 1); 76 memcpy(dest->u_name, ptr + 1, exactsize - 1);
80
81 return 0;
82} 77}
83 78
84/* 79/*
85 * udf_ocu_to_utf8 80 * udf_CS0toUTF8
86 * 81 *
87 * PURPOSE 82 * PURPOSE
88 * Convert OSTA Compressed Unicode to the UTF-8 equivalent. 83 * Convert OSTA Compressed Unicode to the UTF-8 equivalent.
@@ -94,7 +89,7 @@ static int udf_build_ustr_exact(struct ustr *dest, dstring *ptr, int exactsize)
94 * both of type "struct ustr *" 89 * both of type "struct ustr *"
95 * 90 *
96 * POST-CONDITIONS 91 * POST-CONDITIONS
97 * <return> Zero on success. 92 * <return> >= 0 on success.
98 * 93 *
99 * HISTORY 94 * HISTORY
100 * November 12, 1997 - Andrew E. Mileski 95 * November 12, 1997 - Andrew E. Mileski
@@ -117,7 +112,7 @@ int udf_CS0toUTF8(struct ustr *utf_o, const struct ustr *ocu_i)
117 memset(utf_o, 0, sizeof(struct ustr)); 112 memset(utf_o, 0, sizeof(struct ustr));
118 pr_err("unknown compression code (%d) stri=%s\n", 113 pr_err("unknown compression code (%d) stri=%s\n",
119 cmp_id, ocu_i->u_name); 114 cmp_id, ocu_i->u_name);
120 return 0; 115 return -EINVAL;
121 } 116 }
122 117
123 ocu = ocu_i->u_name; 118 ocu = ocu_i->u_name;
@@ -154,7 +149,7 @@ int udf_CS0toUTF8(struct ustr *utf_o, const struct ustr *ocu_i)
154 149
155/* 150/*
156 * 151 *
157 * udf_utf8_to_ocu 152 * udf_UTF8toCS0
158 * 153 *
159 * PURPOSE 154 * PURPOSE
160 * Convert UTF-8 to the OSTA Compressed Unicode equivalent. 155 * Convert UTF-8 to the OSTA Compressed Unicode equivalent.
@@ -270,7 +265,7 @@ static int udf_CS0toNLS(struct nls_table *nls, struct ustr *utf_o,
270 memset(utf_o, 0, sizeof(struct ustr)); 265 memset(utf_o, 0, sizeof(struct ustr));
271 pr_err("unknown compression code (%d) stri=%s\n", 266 pr_err("unknown compression code (%d) stri=%s\n",
272 cmp_id, ocu_i->u_name); 267 cmp_id, ocu_i->u_name);
273 return 0; 268 return -EINVAL;
274 } 269 }
275 270
276 ocu = ocu_i->u_name; 271 ocu = ocu_i->u_name;
@@ -338,43 +333,51 @@ int udf_get_filename(struct super_block *sb, uint8_t *sname, int slen,
338 uint8_t *dname, int dlen) 333 uint8_t *dname, int dlen)
339{ 334{
340 struct ustr *filename, *unifilename; 335 struct ustr *filename, *unifilename;
341 int len = 0; 336 int ret;
337
338 if (!slen)
339 return -EIO;
342 340
343 filename = kmalloc(sizeof(struct ustr), GFP_NOFS); 341 filename = kmalloc(sizeof(struct ustr), GFP_NOFS);
344 if (!filename) 342 if (!filename)
345 return 0; 343 return -ENOMEM;
346 344
347 unifilename = kmalloc(sizeof(struct ustr), GFP_NOFS); 345 unifilename = kmalloc(sizeof(struct ustr), GFP_NOFS);
348 if (!unifilename) 346 if (!unifilename) {
347 ret = -ENOMEM;
349 goto out1; 348 goto out1;
349 }
350 350
351 if (udf_build_ustr_exact(unifilename, sname, slen)) 351 udf_build_ustr_exact(unifilename, sname, slen);
352 goto out2;
353
354 if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) { 352 if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) {
355 if (!udf_CS0toUTF8(filename, unifilename)) { 353 ret = udf_CS0toUTF8(filename, unifilename);
354 if (ret < 0) {
356 udf_debug("Failed in udf_get_filename: sname = %s\n", 355 udf_debug("Failed in udf_get_filename: sname = %s\n",
357 sname); 356 sname);
358 goto out2; 357 goto out2;
359 } 358 }
360 } else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) { 359 } else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) {
361 if (!udf_CS0toNLS(UDF_SB(sb)->s_nls_map, filename, 360 ret = udf_CS0toNLS(UDF_SB(sb)->s_nls_map, filename,
362 unifilename)) { 361 unifilename);
362 if (ret < 0) {
363 udf_debug("Failed in udf_get_filename: sname = %s\n", 363 udf_debug("Failed in udf_get_filename: sname = %s\n",
364 sname); 364 sname);
365 goto out2; 365 goto out2;
366 } 366 }
367 } else 367 } else
368 goto out2; 368 BUG();
369 369
370 len = udf_translate_to_linux(dname, dlen, 370 ret = udf_translate_to_linux(dname, dlen,
371 filename->u_name, filename->u_len, 371 filename->u_name, filename->u_len,
372 unifilename->u_name, unifilename->u_len); 372 unifilename->u_name, unifilename->u_len);
373 /* Zero length filename isn't valid... */
374 if (ret == 0)
375 ret = -EINVAL;
373out2: 376out2:
374 kfree(unifilename); 377 kfree(unifilename);
375out1: 378out1:
376 kfree(filename); 379 kfree(filename);
377 return len; 380 return ret;
378} 381}
379 382
380int udf_put_filename(struct super_block *sb, const uint8_t *sname, 383int udf_put_filename(struct super_block *sb, const uint8_t *sname,