From patchwork Tue Feb 27 10:00:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Fitzgerald X-Patchwork-Id: 207115 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2596184dyb; Tue, 27 Feb 2024 02:02:14 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX1+DnPkvQU9MEZhsa/46p5pNuRl1cOe5RoDVKmPYgbNuMMBuH9cYv9xS5HQrelM48PKR8EG/JO95OCoCg1z1MCHfcKow== X-Google-Smtp-Source: AGHT+IGzAOjKCwtCcXqH5CUx5UsTSWJN38P1Vtipe3aGagUdy5N9EXTmHTmCGqf8GFf7oDmydacs X-Received: by 2002:ae9:f30d:0:b0:787:6a71:5f59 with SMTP id p13-20020ae9f30d000000b007876a715f59mr2040459qkg.20.1709028134070; Tue, 27 Feb 2024 02:02:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709028134; cv=pass; d=google.com; s=arc-20160816; b=VYrgqyJvDlFhbTuP7nIxXCnpREn8o4TLyc2S0yj+WKNmrEvPE2/9c/9mhflRrgRwgv mwRYncbdQaJ34Of3eo2UjGL9rIErPlUiVybD/Hh3XHyMwUeEfEn2yu/9niH8HbiN8kGX vCljOdawfprhs9SlK0aphPiduoszXJxgNkgzAf+aiBWO0TXVIw37GZIT5xes1XwWPL/b kaOejAeGzTQPsSoBmTAep62XhtEiVsJw+Vpe8VQG7KB3KeGiTv5TRyPViJPL0hy9fzI4 50e08GsiEWQuP3d79UmJYN7y2V/XSgz+aEok53kZ9pom6tRh2eggQwC/qc/YkC+LMbiP EoxA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=eKIvLq8xXb6oflbot81eGZAizbrGvdd+1Q79YDlPBfg=; fh=HmcxfOiRAhfdLjKRtDyRjTtuYfcotLlCNOFSdqEobBY=; b=iaM9tPpsLmEIfqjrP7ddcfBFKMgQ7icDn2Ekncxb0JwEaJ6wjqKyOCSOlryHYMprth O6rrC1xsgKOfVNc7jWJfA1Gg0X49opARKUKRYHvKUw0zj6VO3/yb5cK7dwCvEVpx6G3J Rhduq1bD4mjj1UE6FtIVSduTvKbWocJXVm1nGxc2+1R/ZLQbUblFpoTiyk2r23VvH5c+ omnFbKuLokxhbwHDEH3w6Vn2aJFO5DPZJW+Ub60RhiR0JBATj1/JvbTLeGzDaQh2WfRn eZs9AkEVyn/Qgfe9uo43gBxadhep4fC/GNZoDt4qc9gJzd2I2aK2eBJcIgqSL4mgF7ar f+nQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=jjIKGiEF; arc=pass (i=1 spf=pass spfdomain=opensource.cirrus.com dkim=pass dkdomain=cirrus.com dmarc=pass fromdomain=opensource.cirrus.com); spf=pass (google.com: domain of linux-kernel+bounces-82998-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82998-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id z17-20020a05620a101100b00787bae6b0a5si6892986qkj.589.2024.02.27.02.02.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 02:02:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-82998-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=jjIKGiEF; arc=pass (i=1 spf=pass spfdomain=opensource.cirrus.com dkim=pass dkdomain=cirrus.com dmarc=pass fromdomain=opensource.cirrus.com); spf=pass (google.com: domain of linux-kernel+bounces-82998-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82998-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id BBE7A1C222B9 for ; Tue, 27 Feb 2024 10:01:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 60030137C3A; Tue, 27 Feb 2024 10:01:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cirrus.com header.i=@cirrus.com header.b="jjIKGiEF" Received: from mx0b-001ae601.pphosted.com (mx0a-001ae601.pphosted.com [67.231.149.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06D7E56458; Tue, 27 Feb 2024 10:01:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.149.25 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709028069; cv=none; b=ZwbJ84gijogkP7rcBV0QpACIfGqzoSVVJVH9GS9qnvkoy5zMcphRjHZlW2JL9b2IaOKwGQ3GkzCKx3JOOC+iCnQkwSSlAN7ZhsM1N+svPx1oEIk8Ad9pPbUUbPBONdXT8h984dxXBhR3TJmxoCAxTyA//B8az0hK6P3cynuWzKg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709028069; c=relaxed/simple; bh=icVQbNc6Pzd3/XoMFybZxZR4XgSeB5FGoOCVNAL9xWE=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=GcQnhQxv3BKj5FeypssFUFvuthaUtiMitAOBJt18n3KTdXg8nGilkxfXKryqfvmne3jJIweY+KhD2cBhf/LompXhTJNxhkkkLHm1r9ZTlg9x4Akh66cqqNSgMAxs0k4YQ6KReWfuTLmAJW6c7w69VXrmxRsuBPYXubCOgZVHpnU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=opensource.cirrus.com; spf=pass smtp.mailfrom=opensource.cirrus.com; dkim=pass (2048-bit key) header.d=cirrus.com header.i=@cirrus.com header.b=jjIKGiEF; arc=none smtp.client-ip=67.231.149.25 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=opensource.cirrus.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=opensource.cirrus.com Received: from pps.filterd (m0077473.ppops.net [127.0.0.1]) by mx0a-001ae601.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41R59Fpo012520; Tue, 27 Feb 2024 04:00:47 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h= from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding:content-type; s=PODMain02222019; bh=e KIvLq8xXb6oflbot81eGZAizbrGvdd+1Q79YDlPBfg=; b=jjIKGiEF9iJDojLcV PmzfDAPYEFMmbld2KLy4GldiaePq3k9Xvew+Toj1H5E0xCM5mDEQq8XX988QuOPd r8owsQyxVMc8gi+bSpQxQrLYg7cWiwwrHnXWyVzzcuinM+SctHuQhSI2YIOuLPWn nRFbPeP2+e1sOszAyKKXJCrbjkiYbeFNtzverDy0eYae2xQQ+jfS91pjV89ilaHF Exp4fet7/0TeIG5w5xqh/Ltb6jzia7cZwnDYzXPocyWu/6ltE/8oeR5xtU556UU7 aKLgEwj6nZvuwzxFzQNbvPewmQklIx39aUaZVMWBcEqYmnRofMopye2Ydzx9l9rU +UOZw== Received: from ediex01.ad.cirrus.com ([84.19.233.68]) by mx0a-001ae601.pphosted.com (PPS) with ESMTPS id 3wfer2u9e5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 27 Feb 2024 04:00:47 -0600 (CST) Received: from ediex02.ad.cirrus.com (198.61.84.81) by ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 27 Feb 2024 10:00:44 +0000 Received: from ediswmail9.ad.cirrus.com (198.61.86.93) by anon-ediex02.ad.cirrus.com (198.61.84.81) with Microsoft SMTP Server id 15.2.1118.40 via Frontend Transport; Tue, 27 Feb 2024 10:00:44 +0000 Received: from EDIN4L06LR3.ad.cirrus.com (EDIN4L06LR3.ad.cirrus.com [198.61.65.56]) by ediswmail9.ad.cirrus.com (Postfix) with ESMTP id 5A600820246; Tue, 27 Feb 2024 10:00:44 +0000 (UTC) From: Richard Fitzgerald To: , CC: , , , , "Richard Fitzgerald" Subject: [PATCH] ASoC: cs35l56: Prevent bad sign extension in cs35l56_read_silicon_uid() Date: Tue, 27 Feb 2024 10:00:42 +0000 Message-ID: <20240227100042.99-1-rf@opensource.cirrus.com> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Proofpoint-GUID: sVtyfHros6atG7YF84seuCbHvi2LKv4u X-Proofpoint-ORIG-GUID: sVtyfHros6atG7YF84seuCbHvi2LKv4u X-Proofpoint-Spam-Reason: safe X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792045884639416083 X-GMAIL-MSGID: 1792045884639416083 Cast u8 values to u32 when using them to build a 32-bit unsigned value that is then stored in a u64. This avoids the possibility of a bad sign extension where the u8 is implicitly extended to an int, thus changing it from an unsigned to a signed value. Whether this is a real problem is debatable, but it does no harm to ensure that the u8 are cast to a suitable type for shifting. Signed-off-by: Richard Fitzgerald Fixes: e1830f66f6c6 ("ASoC: cs35l56: Add helper functions for amp calibration") --- sound/soc/codecs/cs35l56-shared.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sound/soc/codecs/cs35l56-shared.c b/sound/soc/codecs/cs35l56-shared.c index 20b6dbd3fbab..f3670bf85a95 100644 --- a/sound/soc/codecs/cs35l56-shared.c +++ b/sound/soc/codecs/cs35l56-shared.c @@ -659,9 +659,10 @@ static int cs35l56_read_silicon_uid(struct cs35l56_base *cs35l56_base, u64 *uid) return ret; } - unique_id = pte.lot[2] | (pte.lot[1] << 8) | (pte.lot[0] << 16); + unique_id = (u32)pte.lot[2] | ((u32)pte.lot[1] << 8) | ((u32)pte.lot[0] << 16); unique_id <<= 32; - unique_id |= pte.x | (pte.y << 8) | (pte.wafer_id << 16) | (pte.dvs << 24); + unique_id |= (u32)pte.x | ((u32)pte.y << 8) | ((u32)pte.wafer_id << 16) | + ((u32)pte.dvs << 24); dev_dbg(cs35l56_base->dev, "UniqueID = %#llx\n", unique_id);