Received: by 2002:a19:f614:0:0:0:0:0 with SMTP id x20csp54403lfe; Fri, 15 Apr 2022 19:10:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNHUcQG9U9Hq2ayznopLt1GM/7LMvC21US8zK4KltBQES5lKi9nsS1NIvkat/S3N+yjMk2 X-Received: by 2002:a17:902:c751:b0:158:5852:9c25 with SMTP id q17-20020a170902c75100b0015858529c25mr1755271plq.118.1650075008993; Fri, 15 Apr 2022 19:10:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650075008; cv=none; d=google.com; s=arc-20160816; b=eWsD7BxxwG1fR/fYi+1x1Ja6+iy4IAGUd2+hXyfo+Wl8dJm5V6wd5oGHja/EoPENm9 Pf4ZfGyscHOPD8oi43Q6/d6OjyhL4yB8yunNfXI9CRO1Mwt4kF/E+cb4orxumI1NOgQJ g59fqm07GR/dRcuxcySx74gbf7Qn0I2ymdiToDwII76VinX6Fj2ynn0BHB2pHwQLt5WV nGi13Z+0tVLhasLgVvROUzXHDdY5Qe++oADfwUJLwU3HhsLeObvmhMfP8d2yvuiUopeK d539PJcDi2jT9vqj+2p4OrTWjKRnIN2hH2vlCsrJWs7m0Um/pNHWAzp5ci21OvZNIbg2 QjlA== 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=GuiGrqmJ3ITnK3x5FBN1zcT5KI/+RvY0D5FowojXojM=; b=Wxjj0UByIJzxJqEeejYvfi/rRj2s8GGawEc8x9CwlJNXgUXzg6s0p1SGJVcmFMQet7 9zNtnPKFjQllwgPSD71Y+qMGlVLTzHUyQuEsoGyfDEHX9N+txkADKdgspEFTohGgz/pj zRU0Kv8Ay9tmEUnzaHHtH6kNRIcRLVcPgoAdWRnYJM3oHONFmu6R10eyHbMS0FLnC52y 0w0NyL0sduvurayz9VaYueX2UWqGDkAgJii/JLsgQLBXq5Zke/xDmu1nRsWhMvxgePQn u9UEEQ26VrXErm9OmzpxeM3UirYK4Pxh/8bDiRvML6PYifcUdHQm6wtPzKIoxRB70iqZ j/hQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kXeg73jj; 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 rj6-20020a17090b3e8600b001cb42a61a7esi6151974pjb.75.2022.04.15.19.10.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 19:10:08 -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=kXeg73jj; 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8FF7ED4474; Fri, 15 Apr 2022 18:27:34 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243734AbiDNNRQ (ORCPT + 99 others); Thu, 14 Apr 2022 09:17:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243723AbiDNNRM (ORCPT ); Thu, 14 Apr 2022 09:17:12 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E38E19018; Thu, 14 Apr 2022 06:14:48 -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 ams.source.kernel.org (Postfix) with ESMTPS id AEAC7B82929; Thu, 14 Apr 2022 13:14:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 23D57C385A1; Thu, 14 Apr 2022 13:14:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649942085; bh=/2Dck0yXQAUw92M8J6qwutwzsjxHo15GjzK9bZxlqOA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kXeg73jjoNUr6pvl1rpHcuY8lvw6iW2qct47gyA5lklAA8Vcf5ErmEBAvrMC4Sx3u fS1p/mK5ls1kt3c5Y/NbKn12k18qd6rDaaUy01q1VDUXB80UoQjPjC1bUbpyGO4V5C UTwvrhVjG0+Vs6u9dgFZ5ZxgYfAIvjialVDindJk= 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 4.19 010/338] spi: Fix erroneous sgs value with min_t() Date: Thu, 14 Apr 2022 15:08:33 +0200 Message-Id: <20220414110839.184071949@linuxfoundation.org> X-Mailer: git-send-email 2.35.2 In-Reply-To: <20220414110838.883074566@linuxfoundation.org> References: <20220414110838.883074566@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 518c8e0eef7f..3bcd6f178f73 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -779,10 +779,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