Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp751081imu; Wed, 9 Jan 2019 05:52:38 -0800 (PST) X-Google-Smtp-Source: ALg8bN5+0s6pO8d67eK46eld8x7qTzLauaa8w+FOsSaG97u7/LZ8i45brVkAp5Uofx5VqVvywTfn X-Received: by 2002:a63:504d:: with SMTP id q13mr5535204pgl.319.1547041958757; Wed, 09 Jan 2019 05:52:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547041958; cv=none; d=google.com; s=arc-20160816; b=S+aidatMArb8oWz/OWVcf6lFWiXxFlMLtAjY95ZDMFwUMz/lAcDmGFP0/fjio3Qv5d dEHza0G+6G7JRFfLcFTDGJF+gDg86sIxK9toguPeMh/ic/blWMIvvcybLKIKVqY1Yq0w e8LmgIBTeiUaQvK0CKiTJs4GYr5Pghoy8+NSadKxYfAalwEuhsbarpaGVkdzjq9yHKDx 61EFG6rdPX8c2GZ+yKQRQKJ3gmtQ9H6Go87HyNpJDGnQUt2fsqVjC3QJ/ChAo7ySknm/ u6EwJ1ZJtlxDgUPxz6oR8bsBzO/nqdtcYs0j30Ib5tEE1p578bOFHyjG5Dtm0PflclgF cuIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Sj6ddva6iFOtF3top2ruh0n1QXiQQrYhiUkE8TXk4H8=; b=V+GeJdMpuACJP8uxJ6Q/tYSkNjmc6VZIeRzWDiSoW8oSC/vhpG88p4fegFGGoLoHKh 79rrRbl+Fic4f4IGbVZ5rP3AfjKo6czvdiPKNlPk1O1BcbDm8Ucd2g/j321KzYvREGeX sOkw+yxkITll94r7Vi4NVG5Izywr1QSpe63prpjqNzYUR2H6Y99FyWQ/YEPcjKiQOonD +SgMOV9EMUGcvJDntTaLPzeqcM1jjADvHOupCoTtot4ViP5JUiK3Qzw2ST/JI0ZPbgwK MNgB98hhD+obSd93WlSU2b40kyqNyEeUiIKwum0ZWgIHRUQcEkMDeXui3w3U0R+x4ruG v1vQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=ULa2hxDU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v8si65429222plp.215.2019.01.09.05.52.23; Wed, 09 Jan 2019 05:52:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=ULa2hxDU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730478AbfAIMtD (ORCPT + 99 others); Wed, 9 Jan 2019 07:49:03 -0500 Received: from mail.skyhub.de ([5.9.137.197]:43912 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729732AbfAIMtD (ORCPT ); Wed, 9 Jan 2019 07:49:03 -0500 Received: from zn.tnic (p200300EC2BEA1000E56F05EB9FFDE1E7.dip0.t-ipconnect.de [IPv6:2003:ec:2bea:1000:e56f:5eb:9ffd:e1e7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id A905D1EC014B; Wed, 9 Jan 2019 13:49:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1547038141; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=Sj6ddva6iFOtF3top2ruh0n1QXiQQrYhiUkE8TXk4H8=; b=ULa2hxDUOie8DioGGU527C8w3pttybcdDzEvnpxAjufs5Xsh9r8+x6OesIRH6KcNg3txqN NoZWdt4PK75L0veDWDTURzmzcSUIIr4kSowUITFBx4nhb0pC0s+EoeUuX2QyvuV8eebZb2 u2mZUMMGUCAVyduN5wTZScftuNXtf04= Date: Wed, 9 Jan 2019 13:48:53 +0100 From: Borislav Petkov To: Chao Fan Cc: linux-kernel@vger.kernel.org, x86@kernel.org, tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, keescook@chromium.org, bhe@redhat.com, msys.mizuma@gmail.com, indou.takao@jp.fujitsu.com, caoj.fnst@cn.fujitsu.com Subject: Re: [PATCH v15 1/6] x86/boot: Copy kstrtoull() to boot/string.c instead of using simple_strtoull() Message-ID: <20190109124853.GD15665@zn.tnic> References: <20190107032243.25324-1-fanc.fnst@cn.fujitsu.com> <20190107032243.25324-2-fanc.fnst@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20190107032243.25324-2-fanc.fnst@cn.fujitsu.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 07, 2019 at 11:22:38AM +0800, Chao Fan wrote: > Copy kstrtoull() and necessary functions from lib/kstrtox.c to > boot/string.c so that code in boot/ can use kstrtoull() and the old > simple_strtoull() can be replaced. > > In boot/string.c, using div_u64() from math64.h directly will cause the > dividend handled as 64-bit value and bring ld error. The solution is to > separate the dividend to upper and lower in boot/string.o. So copy the > useful div_u64() and div_u64_rem() to boot/string.c also. To avoid > redefinition in i386, rename them as __div_u64() and __div_u64_rem(). > > Signed-off-by: Chao Fan > --- > arch/x86/boot/string.c | 137 +++++++++++++++++++++++++++++++++++++++++ > arch/x86/boot/string.h | 2 + > 2 files changed, 139 insertions(+) ... > +static inline char _tolower(const char c) > +{ > + return c | 0x20; > +} > + > +const char *_parse_integer_fixup_radix(const char *s, unsigned int *base) static > +{ > + if (*base == 0) { > + if (s[0] == '0') { > + if (_tolower(s[1]) == 'x' && isxdigit(s[2])) > + *base = 16; > + else > + *base = 8; > + } else > + *base = 10; > + } > + if (*base == 16 && s[0] == '0' && _tolower(s[1]) == 'x') > + s += 2; > + return s; > +} > + > +/* > + * Convert non-negative integer string representation in explicitly given radix > + * to an integer. > + * Return number of characters consumed maybe or-ed with overflow bit. > + * If overflow occurs, result integer (incorrect) is still returned. > + * > + * Don't you dare use this function. > + */ > +unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long *p) static > +{ > + unsigned long long res; > + unsigned int rv; > + > + res = 0; > + rv = 0; > + while (1) { > + unsigned int c = *s; > + unsigned int lc = c | 0x20; /* don't tolower() this line */ > + unsigned int val; > + > + if ('0' <= c && c <= '9') > + val = c - '0'; > + else if ('a' <= lc && lc <= 'f') > + val = lc - 'a' + 10; > + else > + break; > + > + if (val >= base) > + break; > + /* > + * Check for overflow only if we are within range of > + * it in the max base we support (16) > + */ > + if (unlikely(res & (~0ull << 60))) { > + if (res > __div_u64(ULLONG_MAX - val, base)) > + rv |= KSTRTOX_OVERFLOW; > + } > + res = res * base + val; > + rv++; > + s++; > + } > + *p = res; > + return rv; > +} -- Regards/Gruss, Boris. Good mailing practices for 400: avoid top-posting and trim the reply.