Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1040254imu; Tue, 11 Dec 2018 11:39:36 -0800 (PST) X-Google-Smtp-Source: AFSGD/UGq1klcIh9FxE007+RunHORDekBPNu+Ag9raSpWqj8mBEl+pKZhU3U2dsL7RKIxiC9FEDD X-Received: by 2002:a17:902:680f:: with SMTP id h15mr16852002plk.40.1544557176553; Tue, 11 Dec 2018 11:39:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544557176; cv=none; d=google.com; s=arc-20160816; b=YUw1juu2fTYEAsjAugZsMvmjGKTzPrlW9NAcfxa7/8DogvIf0bxSVH7SprIwI8HsuZ W46J58g/GNFtQ1U4HhM9fr4gj6LYOcvvHAafWuRiod3vSp5qGDcgABElzqwt4DNjca9H SdfoiwPTbhOdNLYjHM7/DiBqjhfw6TBiYVgaXMJEbGVPgmh4C5m1R9lzULMaMuMBcYbV a5l4LPRcCjtrR8zgiWzMgcf4MrHby+fmdkRTQ7hdpKajrwzsY01P409muXXshnnKRoro RqPiJiZ+4Kewn3uogYslYXyyoUFZE5ZD6sksGFDNK8S7Nu3bby4lEe9MsdlQcwQsArlW zTZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Lj0p4F+Wqt8o2/eaaV6cPeKTzG8Y+EbESwMhilDDlF8=; b=V3oz6naerfyqN94iOaoCXlfHI5j3glHdJuh4iqVj9+MP3b7g6StpFjft1Kxc7R0idB MLxktBz+S1wUBdbvz1OpjYGiYnT5KlTrF9E/GgCsN0cMG1+mRE6Z03UEw0M7sG4+qNcv rwja70feRsHp6ursLtgjpFUwfzvqZE8dq5iqg+By7UO/9vUFW0Wwb7dEFwY9R/esfi4h CZqj/6QYuQRJbLqHVsI5cScijogOrOPuFOB542+WLrSEtEgyvNZs65t4o50wXq01dGVL MNyZUYRhmjBLSnJ/xla4vuvBWgaXz2TRrQBFsw5tnkp63C3ncl4vuhXPNxs7c5QwpGhV hIog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=PTtrwXyo; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h1si12651458plt.44.2018.12.11.11.39.21; Tue, 11 Dec 2018 11:39:36 -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=@linux-foundation.org header.s=google header.b=PTtrwXyo; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727036AbeLKST3 (ORCPT + 99 others); Tue, 11 Dec 2018 13:19:29 -0500 Received: from mail-lf1-f68.google.com ([209.85.167.68]:44309 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726722AbeLKST3 (ORCPT ); Tue, 11 Dec 2018 13:19:29 -0500 Received: by mail-lf1-f68.google.com with SMTP id z13so11484786lfe.11 for ; Tue, 11 Dec 2018 10:19:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Lj0p4F+Wqt8o2/eaaV6cPeKTzG8Y+EbESwMhilDDlF8=; b=PTtrwXyoVgYMfspHGAPHJ+Xc2iHt3h/8IvorKcg5cgjE1FuN7UPyjFzo5uIjfsNm1a XYLRq42Lgk7H72zQ9XXWO/naWP7ycT7UCtueu1YIBrL+2MTgfaSFDAjaNpfC5DCEKGLY OfZscA5X6TmpOyyo5FI2POLZf0HLgezErMEC4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Lj0p4F+Wqt8o2/eaaV6cPeKTzG8Y+EbESwMhilDDlF8=; b=NAwLbNwlnoF+xAHrbQO2aXzEm6L1JUQr3iHo023qDmhQ4IZsWxzAhehiYMoWWz+Tap 0N5HgKKCmeLz0maNvGaAkw7DDH1Hzg0uDBReXb++wWUh8YhS0OP3XrcZbDUG11HM3rrN 6evxXnH9uCzLVByXwSHT16yfmhDR/B5+zbwJDDFn+SgKyH/5xv4zKzFfsCOyv3XIhXsf aJ0kNa5Oi6VAjccMNQdGET0lCBxdHv+drsBAnqvKSsxIkEyGt4KFA3cywUc9q4ycGkgY 5PGqWKm/x8ezBbxyA8LqTYWaPXFiPWkn7v2ye0j5fKN286hnfx6NJHd6wRUcReRO8gLr otcg== X-Gm-Message-State: AA+aEWZbgV/wxhx2TFDBxy6hYU8jPOMBqKbRiWbU8fE5fry6BN4I0N4z qiS6VexDrnAvGTgY/HqXs4/YFVSUupc= X-Received: by 2002:ac2:4215:: with SMTP id y21mr9908283lfh.6.1544552366358; Tue, 11 Dec 2018 10:19:26 -0800 (PST) Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com. [209.85.167.44]) by smtp.gmail.com with ESMTPSA id o5-v6sm2814185ljh.75.2018.12.11.10.19.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Dec 2018 10:19:25 -0800 (PST) Received: by mail-lf1-f44.google.com with SMTP id c16so11481167lfj.8 for ; Tue, 11 Dec 2018 10:19:24 -0800 (PST) X-Received: by 2002:a19:982:: with SMTP id 124mr9668394lfj.138.1544552364547; Tue, 11 Dec 2018 10:19:24 -0800 (PST) MIME-Version: 1.0 References: <20181211152113.8523-1-thomas.preston@codethink.co.uk> <20181211152113.8523-3-thomas.preston@codethink.co.uk> <20181211180458.GE10650@smile.fi.intel.com> In-Reply-To: <20181211180458.GE10650@smile.fi.intel.com> From: Linus Torvalds Date: Tue, 11 Dec 2018 10:19:08 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 2/2] vsprintf: Stop using obsolete simple_strtoul() To: Andy Shevchenko Cc: thomas.preston@codethink.co.uk, Andrew Morton , Petr Mladek , Steven Rostedt , geert+renesas@glider.be, Jonathan Corbet , tcharding , Sergey Senozhatsky , Linux List Kernel Mailing , ben.dooks@codethink.co.uk Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 11, 2018 at 10:05 AM Andy Shevchenko wrote: > > I think it's slightly more complicated, I run the following test case on glibc: > > uint32_t hi, lo, t; > > sscanf("00fafafafa0d0b0b0b0c000000", "%8x%8x%x", &hi, &lo, &t); > > 64-bit: > HI: 00fafafa LO: fa0d0b0b (c000000) > 32-bit: > HI: 00fafafa LO: fa0d0b0b (ffffffff) But that's exactly the values my pseudo-code gets (well, my "pseudo-code obviously just said // Now do "sign" and range checking on val The three sub-parts are: "00fafafa" "fa0d0b0b" and "0b0c000000" and the third one encounters an overflow in "long" on 32-bit, so it turns into ~0. And yes, the 64-bit "long" in that third value gets truncated to "uint32" when written to "t" (which is wht that "0b" part just gets lost. And that's just because of historical C scanf behavior. There's no overflow checking in "int". Only in "long" and "long long". Linus