Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp4902671pxb; Tue, 28 Sep 2021 06:37:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9QJkF30vCSiR7oO9p3h6Ok+UJY8KXanyTafu6iWH492EYLZegYQb+ukmuI18NjPexYDhV X-Received: by 2002:a17:906:7c86:: with SMTP id w6mr6701690ejo.215.1632836254626; Tue, 28 Sep 2021 06:37:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632836254; cv=none; d=google.com; s=arc-20160816; b=KktyeiLkoC1RzJjKY3mDXkUSzKHzdSo4Hi+s3fGBlZxOy+0RK0TlKSkpv+TT0tWjp2 nYzJGsulASs5qAG9Ls4xZufujjve28KAVIVSI/cx6+UkS7KflWgX6LlfKTrDhI1nQKIq 0od0LcMmCyYAqVMbszlhsjgiUR40s7/aBdnZs3lrd4qC7bak1dRNuBmYrCK6ztJhtCmQ AXTyqyWQklete/aBM366RKVd0MIOz8GfGtb8/OV4fgbIhV7w34U8ihaB6FOcMCNgmvHq EDCw2xog3zkyevjeYxC5mVecYAMSfVf3YVHGMBffL4IKDD4F3Sv8AHsC5/yk5/9UiUr8 7Vzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=rQfE7KZdMhHmuIeP5K8CNc8n21oMgbxVS8aHE2vpZr0=; b=yH+hQtAkIB6MppjLdGuZa+eN8ID1QPjF64s/BQWCGMC2KFb+L6uNPicVsGHW/veJPF nVZT6hfUNQai8W7VV6dgsD9nBzTv2VUds/++hKfxTSVvNdC5dTM7QagmODc+KSK9VmVc Tj8tbGMjDBfIUfbKwo7V2vInnAihz+NuunXlbGeUYAmbsHNUQFIBUTdKzszDXl+WzeDE 36PYCm4iwNCho39V25gI22Fygc+zois1m7Quk6kYhb7gBtw7r9UT10VJF1jIKWZqNPSV XTm/kaMIL1FOAdGwQ44SEMjXFv6PGC9DVRIbjB5qSy4w2ZKvM6CLs3fQjjf7XVlXVRyb bCNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@0x0f.com header.s=google header.b=GBJ9+Dxu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 9si19787189ejj.312.2021.09.28.06.37.07; Tue, 28 Sep 2021 06:37:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@0x0f.com header.s=google header.b=GBJ9+Dxu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240833AbhI1NdA (ORCPT + 99 others); Tue, 28 Sep 2021 09:33:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240959AbhI1Nc5 (ORCPT ); Tue, 28 Sep 2021 09:32:57 -0400 Received: from mail-vk1-xa30.google.com (mail-vk1-xa30.google.com [IPv6:2607:f8b0:4864:20::a30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 659E5C061575 for ; Tue, 28 Sep 2021 06:31:17 -0700 (PDT) Received: by mail-vk1-xa30.google.com with SMTP id y74so8419178vky.12 for ; Tue, 28 Sep 2021 06:31:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=0x0f.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=rQfE7KZdMhHmuIeP5K8CNc8n21oMgbxVS8aHE2vpZr0=; b=GBJ9+DxuBZ8tnIfVluUcbn6MWwT0n0XFm9KEV4MkSZdaXPP9ywf2wceYCUeXfTmpP1 FnH/jo9M8QKPEQFKlRcPvUOPX6i9ripLluxFJQEL/fLwObPf9h6MRTozvTh8dmK40l1g BETFRGBEgcxYnEUqst4gVyRz8KOa5Cs2Fzti0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=rQfE7KZdMhHmuIeP5K8CNc8n21oMgbxVS8aHE2vpZr0=; b=QB+QC1Si84Ka96kMFjmz2EuosNqZTo06qSiU9vitgFQYP4uIrLv5MwnJuh8XSf1uCr eMPa2HEIOnkZCnabwPBWoi+boJcAmDwDsa4r5LRkHl6PVTKGhr6Ie/WFd8Zic1fXMs90 VYbEkttfL+PyWR9ZNb6BHlaOHdS5uN+gkoTaJMsGNddCyCwavsPYpqbnBUjYyfVpRGJU wMyOmvs/+/VzGBOO4BFkF3go4bUxa48VnupA8W3ztJbK99WsfkIn6AgjVp1V2gLBbX5x bRm7lPlaLDjxDYlEXFM40vd0nHCCWDugtXM4pSoQmO9YjU0QcdjOr1/rvkF/Z9ZxdFja ArnQ== X-Gm-Message-State: AOAM531PZnldwu4GEmMPyRQpBGN1yvl3028mB4YwLn9gEfJoySGdURUR N5zNFxXYguAW67ZW57QvQPtFs0IUi6T7DFU9lVEeWA== X-Received: by 2002:a1f:9d09:: with SMTP id g9mr4598977vke.4.1632835876523; Tue, 28 Sep 2021 06:31:16 -0700 (PDT) MIME-Version: 1.0 References: <20210928123906.988813-1-colin.king@canonical.com> In-Reply-To: <20210928123906.988813-1-colin.king@canonical.com> From: Daniel Palmer Date: Tue, 28 Sep 2021 22:31:06 +0900 Message-ID: Subject: Re: [PATCH][next] rtc: msc313: Fix unintentional sign extension issue on left shift of a u16 To: Colin King Cc: Daniel Palmer , Romain Perier , Alessandro Zummo , Alexandre Belloni , Nobuhiro Iwamatsu , linux-arm-kernel , linux-rtc@vger.kernel.org, kernel-janitors@vger.kernel.org, Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Colin, On Tue, 28 Sept 2021 at 21:39, Colin King wrote: >Shifting the u16 value returned by readw by 16 bits to the left >will be promoted to a 32 bit signed int and then sign-extended >to an unsigned long. If the top bit of the readw is set then >the shifted value will be sign extended and the top 32 bits of >the result will be set. Ah,.. C is fun in all the wrong places. :) These chips are full of 32bit registers that are split into two 16 registers 4 bytes apart when seen from the ARM CPU so we probably have this same mistake in a few other places. A similar pattern is used a bit later on in the same file to read the counter: seconds = readw(priv->rtc_base + REG_RTC_CNT_VAL_L) | (readw(priv->rtc_base + REG_RTC_CNT_VAL_H) << 16); I guess it works at the moment because the top bit won't be set until 2038. Thanks, Daniel