Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp459461ybl; Tue, 28 Jan 2020 06:18:39 -0800 (PST) X-Google-Smtp-Source: APXvYqxloSfslqxFFp7bq1CH6rPBCmzlUSJl6d1nLZH6FkWFoZ3cYcbrF+UoRdLcjkLO5scUkNVm X-Received: by 2002:a05:6830:1198:: with SMTP id u24mr15991154otq.215.1580221119438; Tue, 28 Jan 2020 06:18:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580221119; cv=none; d=google.com; s=arc-20160816; b=Ug3eC2L/Bg5ZrGN/91i/uaQoEXEvBuqj3FW14wK2+c246J8PSHJJgOwcoHx/oYDRxc BeNqmzVRzq94MmoWWQFW/Fr09+ixzHKZeChiIl7Vf0AgGQeGKZy/x2zr0uuW30NwbaVm pNrMx2d1cQQ0V42chdcsJzFEXYaYFw1JyzOn9CRItcp6wQRXamC9sG0T9EbsjhYsO1Bl sf4qmQqA0l1juV1EPjt9ijTjDj2aoQWja6du4YaM9yHFJJNQoO8WhnF1AiAaPfAXN9VZ N8BONQwGAYsrgc+4DEL3zGLYKbhDubuon0cMppINVtVCJQZjB37RpACVsCNW5R36nICK NaCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5R0zTzKTG2LuaHW+UoER5uCb5+3ko2l52LNEHROJ9Zs=; b=CXEYDArvXbSaUxm+gJEPdIvGLkjuhfyGI7OADU9Mfr2VgEPjgRq8m2R/mvf8sl3qpP psQKE2bt0Gx8Wga42FgRAfCwz/+32I1PXXQZ/HEoAFmUAOK02ZfLxU9rGpVVDYY7jUJX YRePjhEZwTkfHtMnUl9VNAIRQHcUboNlO/Jrr6ElSVS/ZnfoQtMoTahLpdJMNZcJkUBs PZhcgZqc5w21yt3guUdjpHFQOkUJ90FbqdCNz05Wn2vkqmeFFANIovD1gIrLWuaiiMHa p34MNGAMcpgEiPX4147Itx6/GLxc0HEzNrtMgKw4YiYvj05LGI0OaUUlafk7dikqO79Y 95xQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TjGoAVjn; 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 m14si2704285otr.131.2020.01.28.06.18.27; Tue, 28 Jan 2020 06:18:39 -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=@kernel.org header.s=default header.b=TjGoAVjn; 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 S1730503AbgA1ORZ (ORCPT + 99 others); Tue, 28 Jan 2020 09:17:25 -0500 Received: from mail.kernel.org ([198.145.29.99]:40990 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729986AbgA1ORS (ORCPT ); Tue, 28 Jan 2020 09:17:18 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E530B2071E; Tue, 28 Jan 2020 14:17:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580221037; bh=4tsbLvzpH6KACgrSusRTvQLdfeOm9HSCRWokT2heKuA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TjGoAVjnOpwIEfVjW1oq70KrP6S7IZT2nAuDdDNWGX9uuAcIh6P6rY336BMvSC5Co dLroZSPlmmUjXVMlvzUPJS3kcV5oGVSS6TyXeFD6Qb33RdNHHpWs7KuBSetWoAdym5 FFtlEDKwD08nZKqY6wRnL4c7okJNhIacc2WINKWk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Colin Ian King , Alexandre Belloni , Sasha Levin Subject: [PATCH 4.9 062/271] rtc: 88pm860x: fix unintended sign extension Date: Tue, 28 Jan 2020 15:03:31 +0100 Message-Id: <20200128135857.239307385@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200128135852.449088278@linuxfoundation.org> References: <20200128135852.449088278@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Colin Ian King [ Upstream commit dc9e47160626cdb58d5c39a4f43dcfdb27a5c004 ] Shifting a u8 by 24 will cause the value to be promoted to an integer. If the top bit of the u8 is set then the following conversion to an unsigned long will sign extend the value causing the upper 32 bits to be set in the result. Fix this by casting the u8 value to an unsigned long before the shift. Detected by CoverityScan, CID#144925-144928 ("Unintended sign extension") Fixes: 008b30408c40 ("mfd: Add rtc support to 88pm860x") Signed-off-by: Colin Ian King Signed-off-by: Alexandre Belloni Signed-off-by: Sasha Levin --- drivers/rtc/rtc-88pm860x.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/drivers/rtc/rtc-88pm860x.c b/drivers/rtc/rtc-88pm860x.c index 166faae3a59cd..7d3e5168fcefc 100644 --- a/drivers/rtc/rtc-88pm860x.c +++ b/drivers/rtc/rtc-88pm860x.c @@ -115,11 +115,13 @@ static int pm860x_rtc_read_time(struct device *dev, struct rtc_time *tm) pm860x_page_bulk_read(info->i2c, REG0_ADDR, 8, buf); dev_dbg(info->dev, "%x-%x-%x-%x-%x-%x-%x-%x\n", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]); - base = (buf[1] << 24) | (buf[3] << 16) | (buf[5] << 8) | buf[7]; + base = ((unsigned long)buf[1] << 24) | (buf[3] << 16) | + (buf[5] << 8) | buf[7]; /* load 32-bit read-only counter */ pm860x_bulk_read(info->i2c, PM8607_RTC_COUNTER1, 4, buf); - data = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0]; + data = ((unsigned long)buf[3] << 24) | (buf[2] << 16) | + (buf[1] << 8) | buf[0]; ticks = base + data; dev_dbg(info->dev, "get base:0x%lx, RO count:0x%lx, ticks:0x%lx\n", base, data, ticks); @@ -145,7 +147,8 @@ static int pm860x_rtc_set_time(struct device *dev, struct rtc_time *tm) /* load 32-bit read-only counter */ pm860x_bulk_read(info->i2c, PM8607_RTC_COUNTER1, 4, buf); - data = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0]; + data = ((unsigned long)buf[3] << 24) | (buf[2] << 16) | + (buf[1] << 8) | buf[0]; base = ticks - data; dev_dbg(info->dev, "set base:0x%lx, RO count:0x%lx, ticks:0x%lx\n", base, data, ticks); @@ -170,10 +173,12 @@ static int pm860x_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) pm860x_page_bulk_read(info->i2c, REG0_ADDR, 8, buf); dev_dbg(info->dev, "%x-%x-%x-%x-%x-%x-%x-%x\n", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]); - base = (buf[1] << 24) | (buf[3] << 16) | (buf[5] << 8) | buf[7]; + base = ((unsigned long)buf[1] << 24) | (buf[3] << 16) | + (buf[5] << 8) | buf[7]; pm860x_bulk_read(info->i2c, PM8607_RTC_EXPIRE1, 4, buf); - data = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0]; + data = ((unsigned long)buf[3] << 24) | (buf[2] << 16) | + (buf[1] << 8) | buf[0]; ticks = base + data; dev_dbg(info->dev, "get base:0x%lx, RO count:0x%lx, ticks:0x%lx\n", base, data, ticks); @@ -198,11 +203,13 @@ static int pm860x_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) pm860x_page_bulk_read(info->i2c, REG0_ADDR, 8, buf); dev_dbg(info->dev, "%x-%x-%x-%x-%x-%x-%x-%x\n", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]); - base = (buf[1] << 24) | (buf[3] << 16) | (buf[5] << 8) | buf[7]; + base = ((unsigned long)buf[1] << 24) | (buf[3] << 16) | + (buf[5] << 8) | buf[7]; /* load 32-bit read-only counter */ pm860x_bulk_read(info->i2c, PM8607_RTC_COUNTER1, 4, buf); - data = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0]; + data = ((unsigned long)buf[3] << 24) | (buf[2] << 16) | + (buf[1] << 8) | buf[0]; ticks = base + data; dev_dbg(info->dev, "get base:0x%lx, RO count:0x%lx, ticks:0x%lx\n", base, data, ticks); -- 2.20.1