Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp622403pxb; Tue, 5 Apr 2022 16:16:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwXMM4QNKbmiwPXKv4M2gfBIGGVpAJBBdMCejUW6AVrGAW37d7ZAKDMfHGhIlA/jXesR6t1 X-Received: by 2002:a05:6a00:1683:b0:4f7:e497:6a55 with SMTP id k3-20020a056a00168300b004f7e4976a55mr5843691pfc.21.1649200563937; Tue, 05 Apr 2022 16:16:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649200563; cv=none; d=google.com; s=arc-20160816; b=RbLDdBX1UhYXXQIPEgHlChs0UU1h+ysj+rtYZhZWZBpHtoZ69jJXSlWr2jChPP0lzm HObKONpC4328gYwIcJOssS3nhXfp7+qC9hWp1FDiq0sOS7dHTaDCXDM0QrpcfZuYQmXR Q+nU3u6vueQWrKYq4TMq67ZejNYV0AW+TxWeIaeP49YKN6vrDn6F5wgR89C3ZRxZEa9j /49PX6gIKZ9FRG6pVqt6dwz61/0Q8PwmVZuQCSG4eeHfi2YNPQXc20t32YUJgqhykg9y 6mWihuLNzQMkKfY2OqXslqkQ7R+lLH9VSeBwZyEyMXh0cQyXh/Vm9dpZV7jxY82G0SXu W0kQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=0tnomBD7nrx87EgB0/t+DNSLEIvF1aqiAdiXAkIzsd0=; b=0l9fKNusrYudUfg1o80w7gh74OhAYC+UgejQo//AGVO/e3WKpjA6zd/lzyJCOr0QCN oWMzfrQ+MxV4UR7i0/Z000HXNdQr/1b26mDMK76DJ0QcVo+LmgXryr/zMLjT/0jAQvKI I6z785Pwq1Gbr1e5jIobenAXrJFNx4ZrTZic8yWCdJ+JPbPVAUOkg0w6x6yHmd+6PKRU vNt+LXGxNq6ZH/3ato2FzB8EfXoW0P2DQokuNHpOAFejLnyXrYcoLBh5aM0pakeDIT73 yWY5fkbk+W934n8RxSHGiGBEfKhk6bQcZPY/FsQA8PApad8wO3J43aQBFDPE+/csqA/D hjIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DRvvDLFl; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id k189-20020a636fc6000000b0039928e63d26si7130629pgc.375.2022.04.05.16.16.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 16:16:03 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DRvvDLFl; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 37851223233; Tue, 5 Apr 2022 16:00:30 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378089AbiDEOHi (ORCPT + 99 others); Tue, 5 Apr 2022 10:07:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236250AbiDEJbO (ORCPT ); Tue, 5 Apr 2022 05:31:14 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 374B9C3C; Tue, 5 Apr 2022 02:18:55 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C5A7A61654; Tue, 5 Apr 2022 09:18:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CAFBDC385A3; Tue, 5 Apr 2022 09:18:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649150334; bh=5z96HNtCSD9lIA7Pp9tRzOIjIWNw7nGrfQ84IMYPEZA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DRvvDLFl1DUBUp9QeB2J1s+4giLQygF+1dYd0UjVZkrV2GzGQ1q+pZ1dLyll31KhR 498I3wS4u3cfWg+y5rm0VrNDhycigmKwI6GWJrLzkQQqQot0smZ8qZv9wG3OruduKJ wB907/TGar+XumwTL1tIDKqQZAALwfDMOULDwwFk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Linus Torvalds , Geert Uytterhoeven , Biju Das , Lad Prabhakar , Mark Brown , Sasha Levin Subject: [PATCH 5.15 020/913] spi: Fix erroneous sgs value with min_t() Date: Tue, 5 Apr 2022 09:18:02 +0200 Message-Id: <20220405070340.419902803@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Biju Das [ Upstream commit ebc4cb43ea5ada3db46c80156fca58a54b9bbca8 ] While computing sgs in spi_map_buf(), the data type used in min_t() for max_seg_size is 'unsigned int' where as that of ctlr->max_dma_len is 'size_t'. min_t(unsigned int,x,y) gives wrong results if one of x/y is 'size_t' Consider the below examples on a 64-bit machine (ie size_t is 64-bits, and unsigned int is 32-bit). case 1) min_t(unsigned int, 5, 0x100000001); case 2) min_t(size_t, 5, 0x100000001); Case 1 returns '1', where as case 2 returns '5'. As you can see the result from case 1 is wrong. This patch fixes the above issue by using the data type of the parameters that are used in min_t with maximum data length. Fixes: commit 1a4e53d2fc4f68aa ("spi: Fix invalid sgs value") Reported-by: Linus Torvalds Suggested-by: Geert Uytterhoeven Signed-off-by: Biju Das Reviewed-by: Lad Prabhakar Link: https://lore.kernel.org/r/20220316175317.465-1-biju.das.jz@bp.renesas.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/spi/spi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index c7c8d13b2f83..cb7eb1e2e0e9 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -942,10 +942,10 @@ int spi_map_buf(struct spi_controller *ctlr, struct device *dev, int i, ret; if (vmalloced_buf || kmap_buf) { - desc_len = min_t(unsigned int, max_seg_size, PAGE_SIZE); + desc_len = min_t(unsigned long, max_seg_size, PAGE_SIZE); sgs = DIV_ROUND_UP(len + offset_in_page(buf), desc_len); } else if (virt_addr_valid(buf)) { - desc_len = min_t(unsigned int, max_seg_size, ctlr->max_dma_len); + desc_len = min_t(size_t, max_seg_size, ctlr->max_dma_len); sgs = DIV_ROUND_UP(len, desc_len); } else { return -EINVAL; -- 2.34.1