Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755048AbbDIIgP (ORCPT ); Thu, 9 Apr 2015 04:36:15 -0400 Received: from cantor2.suse.de ([195.135.220.15]:57742 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751914AbbDIIgN (ORCPT ); Thu, 9 Apr 2015 04:36:13 -0400 Date: Thu, 9 Apr 2015 10:36:07 +0200 From: Jan Kara To: Fabian Frederick Cc: linux-kernel@vger.kernel.org, Jan Kara Subject: Re: [PATCH V2 4/9 linux-next] udf: improve error management in udf_CS0toUTF8() Message-ID: <20150409083607.GD18044@quack.suse.cz> References: <1428521039-18491-1-git-send-email-fabf@skynet.be> <1428521039-18491-5-git-send-email-fabf@skynet.be> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1428521039-18491-5-git-send-email-fabf@skynet.be> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3644 Lines: 106 On Wed 08-04-15 21:23:54, Fabian Frederick wrote: > udf_CS0toUTF8() now returns -EINVAL on error. > udf_load_pvoldesc() and udf_get_filename() do the same. > > Suggested-by: Jan Kara > Signed-off-by: Fabian Frederick After some thought it's probably better API that udf_CS0toUTF8() simply returns 0 when 0-lenght string is provided as an input (there's nothing invalid in that from the point of view of that conversion functions). We cannot actually ever call udf_CS0toUTF8() with such string currently but I think it's better for future. So I've changed this and merged the patch. Honza > --- > fs/udf/super.c | 23 ++++++++++++++--------- > fs/udf/unicode.c | 9 +++++---- > 2 files changed, 19 insertions(+), 13 deletions(-) > > diff --git a/fs/udf/super.c b/fs/udf/super.c > index 6299f34..c6a8f5f 100644 > --- a/fs/udf/super.c > +++ b/fs/udf/super.c > @@ -927,17 +927,22 @@ static int udf_load_pvoldesc(struct super_block *sb, sector_t block) > #endif > } > > - if (!udf_build_ustr(instr, pvoldesc->volIdent, 32)) > - if (udf_CS0toUTF8(outstr, instr)) { > - strncpy(UDF_SB(sb)->s_volume_ident, outstr->u_name, > - outstr->u_len > 31 ? 31 : outstr->u_len); > - udf_debug("volIdent[] = '%s'\n", > - UDF_SB(sb)->s_volume_ident); > - } > + if (!udf_build_ustr(instr, pvoldesc->volIdent, 32)) { > + ret = udf_CS0toUTF8(outstr, instr); > + if (ret < 0) > + goto out_bh; > + > + strncpy(UDF_SB(sb)->s_volume_ident, outstr->u_name, > + outstr->u_len > 31 ? 31 : outstr->u_len); > + udf_debug("volIdent[] = '%s'\n", UDF_SB(sb)->s_volume_ident); > + } > > if (!udf_build_ustr(instr, pvoldesc->volSetIdent, 128)) > - if (udf_CS0toUTF8(outstr, instr)) > - udf_debug("volSetIdent[] = '%s'\n", outstr->u_name); > + ret = udf_CS0toUTF8(outstr, instr); > + if (ret < 0) > + goto out_bh; > + > + udf_debug("volSetIdent[] = '%s'\n", outstr->u_name); > > ret = 0; > out_bh: > diff --git a/fs/udf/unicode.c b/fs/udf/unicode.c > index 41c3bef..9008a36 100644 > --- a/fs/udf/unicode.c > +++ b/fs/udf/unicode.c > @@ -89,7 +89,7 @@ static void udf_build_ustr_exact(struct ustr *dest, dstring *ptr, int exactsize) > * both of type "struct ustr *" > * > * POST-CONDITIONS > - * Zero on success. > + * >= 0 on success. > * > * HISTORY > * November 12, 1997 - Andrew E. Mileski > @@ -104,7 +104,7 @@ int udf_CS0toUTF8(struct ustr *utf_o, const struct ustr *ocu_i) > ocu_len = ocu_i->u_len; > if (ocu_len == 0) { > memset(utf_o, 0, sizeof(struct ustr)); > - return 0; > + return -EINVAL; > } > > cmp_id = ocu_i->u_cmpID; > @@ -112,7 +112,7 @@ int udf_CS0toUTF8(struct ustr *utf_o, const struct ustr *ocu_i) > memset(utf_o, 0, sizeof(struct ustr)); > pr_err("unknown compression code (%d) stri=%s\n", > cmp_id, ocu_i->u_name); > - return 0; > + return -EINVAL; > } > > ocu = ocu_i->u_name; > @@ -350,7 +350,8 @@ int udf_get_filename(struct super_block *sb, uint8_t *sname, int slen, > > udf_build_ustr_exact(unifilename, sname, slen); > if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) { > - if (!udf_CS0toUTF8(filename, unifilename)) { > + ret = udf_CS0toUTF8(filename, unifilename); > + if (ret < 0) { > udf_debug("Failed in udf_get_filename: sname = %s\n", > sname); > goto out2; > -- > 1.9.1 > -- Jan Kara SUSE Labs, CR -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/