Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp3386161lqp; Tue, 26 Mar 2024 07:55:10 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXnAQ3Wl4R2NFJv+lmp/gniLuGB6LHyMfooKeJqwlkM8mJaMfH+eLmN3IVOETuh54u1zZP9ZXzhzqAXw+99kiJNVYbgydOqfjLxGEfPUQ== X-Google-Smtp-Source: AGHT+IG6R9XhBp+YozN0/9s7+pcxogb4K/KHtUnIUf4oSut0vFn6Ai/PWuPy8IHYhYxs27DmLXB0 X-Received: by 2002:a05:6a20:9147:b0:1a3:bdd4:a298 with SMTP id x7-20020a056a20914700b001a3bdd4a298mr8028906pzc.43.1711464910402; Tue, 26 Mar 2024 07:55:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711464910; cv=pass; d=google.com; s=arc-20160816; b=lgSJeeV3fZ2heQogPIbh/+Xi8iMVcv48kq9KDB3dejckpwLgtfCygaMMfgbmFBxsjd XDn9vcCPVLWwzwjuuJ/KbP0jHfPMvzecHNLngXVusn/O0pMKEWwLRIylACOh7TiO6FME OBVqf4Zu4QWsR4+Sws7MtaytUY/Iib0+9Z076PfUS6rDKyt9TZNPHDq0Q+VMfhM9v3E2 4Ra2zrrxQ0vj6GppKkIx3zprqTZ8ISEJ3KsJ81zcLTJ0Zb/SpUpnxppAci8+Q/cfOcGA zglJuiakNnOGSaGJKDfZPqvUd1Pz3CssVPgW0mb/nsqob1B7s8Mri/v8Mp6v8JT5XjgB FIDw== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=2ZKz/BJga2azhUMb4UVEDoHM42ekSwnAeMTsTDZzoRE=; fh=td8zQki+QTlryztgGw9FssZW8QgjtyxP2SVLB87KKUU=; b=uBeU5hP8BgYDoWhLQlgt6+Tp9P1tWxzRTF9xO06AYAuJ0v70+pUbcMXr+MMHZ0eT7j jc3C10dFAeiNBgnByx7dBYUQ/9BcwX7Nh/4S+rCch5TWIFiiOpA09uk+MRntOuSovXWQ kEYxvDQFhSyiW3lKXhR84ylc/bK2Cwi9P+eTvJ6xEUVfVW5txqlMtD1PFK1HaMbpJfra u41E5rQSLUf/nK3eq7pMKjra3tfgWfpzb7hmhgxbxtiQfF6jn2aq7UuSGB83X4i5CZLv EIzkLWriR/SEqRS6gnCRSzVIomNTtVyQB+p47OrDuFwQ7XaudufOG+lmAFoXFHm6UpxC vJBw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QXSi1TwM; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-119232-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-119232-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id jc18-20020a17090325d200b001ddde668b61si6972573plb.604.2024.03.26.07.55.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 07:55:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-119232-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QXSi1TwM; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-119232-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-119232-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id A4A07305BAB for ; Tue, 26 Mar 2024 14:54:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 825FA13C69A; Tue, 26 Mar 2024 14:53:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QXSi1TwM" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 8931813C687; Tue, 26 Mar 2024 14:53:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711464834; cv=none; b=fu+M3MivWYfTjKB0Z/pIG5p+ytzW+WaxYYdwXDSLfM8RqlsIpdB11oWKk6YgqXoxd6As+MmEh9vcA2WRee/oAUkdVg5dCKk2OvquSye1p7P09pAgd/hrRCdY2JH5j5lrxfveNAb/sjV9UPLGusAn3/qkNNLymayHARS3ZtPieRk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711464834; c=relaxed/simple; bh=jkUwCCs2ehDNVM/jmHEp5augAJwEF3YMSQWolNWMTfg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=q6p0IK1n+NFm4FxKfCykE6c5YZRbXAeYEgGL6uC3bK0Gh3TaenLGzS1IEYFw2i8kd8kE1/tGj5UCeYYAsSF32/947TNWc0ZhvxjdZPgKFKC0U8RX5tiJUtkF6SpCR1Ro3+DjnLec7EKJSx4trS5kkOhw+ujtnTEyZ2OTtJE35vo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QXSi1TwM; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 89622C433F1; Tue, 26 Mar 2024 14:53:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711464834; bh=jkUwCCs2ehDNVM/jmHEp5augAJwEF3YMSQWolNWMTfg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QXSi1TwM8UlBSQOOZ6bV0PCri437P+ddY42TMgKB9+d+xHoMGe6rj6ApVgAaPVOVf F7csm0GeCe0embSNPker9mie0sw55BK1KxYbjnq3O//uHZZoeU9SnHxGpQ6kLfb2fs mQfEbmIpi/0i56u1WMX+zAf0K0wxw/d+ORbq6ueii6LYDlNe/GXvABo/TNnhTL/NbV HT73L6fk8EDZ+bsmkXqcwSaAmxI4Uh48griGQieXPO9nkEBtCagKVPJSlE1w/PLO0h nt+5ZCPybbpit83cSMCG+6CEWXDM+WfXrJQjUBfami36qqByn1OoCeeKK807yc0Ph1 P0tO+DJucITiw== From: Arnd Bergmann To: linux-kbuild@vger.kernel.org, Masahiro Yamada , Damien Le Moal , Niklas Cassel Cc: Nicolas Schier , Nathan Chancellor , Arnd Bergmann , John Garry , "Martin K. Petersen" , linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 10/12] sata: sx4: fix pdc20621_get_from_dimm() on 64-bit Date: Tue, 26 Mar 2024 15:53:37 +0100 Message-Id: <20240326145348.3318887-1-arnd@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240326144741.3094687-1-arnd@kernel.org> References: <20240326144741.3094687-1-arnd@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Arnd Bergmann gcc warns about a memcpy() with overlapping pointers because of an incorrect size calculation: In file included from include/linux/string.h:369, from drivers/ata/sata_sx4.c:66: In function 'memcpy_fromio', inlined from 'pdc20621_get_from_dimm.constprop' at drivers/ata/sata_sx4.c:962:2: include/linux/fortify-string.h:97:33: error: '__builtin_memcpy' accessing 4294934464 bytes at offsets 0 and [16, 16400] overlaps 6442385281 bytes at offset -2147450817 [-Werror=restrict] 97 | #define __underlying_memcpy __builtin_memcpy | ^ include/linux/fortify-string.h:620:9: note: in expansion of macro '__underlying_memcpy' 620 | __underlying_##op(p, q, __fortify_size); \ | ^~~~~~~~~~~~~ include/linux/fortify-string.h:665:26: note: in expansion of macro '__fortify_memcpy_chk' 665 | #define memcpy(p, q, s) __fortify_memcpy_chk(p, q, s, \ | ^~~~~~~~~~~~~~~~~~~~ include/asm-generic/io.h:1184:9: note: in expansion of macro 'memcpy' 1184 | memcpy(buffer, __io_virt(addr), size); | ^~~~~~ The problem here is the overflow of an unsigned 32-bit number to a negative that gets converted into a signed 'long', keeping a large positive number. Replace the complex calculation with a more readable min() variant that avoids the warning. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Arnd Bergmann --- drivers/ata/sata_sx4.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/ata/sata_sx4.c b/drivers/ata/sata_sx4.c index b51d7a9d0d90..a482741eb181 100644 --- a/drivers/ata/sata_sx4.c +++ b/drivers/ata/sata_sx4.c @@ -957,8 +957,7 @@ static void pdc20621_get_from_dimm(struct ata_host *host, void *psource, offset -= (idx * window_size); idx++; - dist = ((long) (window_size - (offset + size))) >= 0 ? size : - (long) (window_size - offset); + dist = min(size, window_size - offset); memcpy_fromio(psource, dimm_mmio + offset / 4, dist); psource += dist; @@ -1005,8 +1004,7 @@ static void pdc20621_put_to_dimm(struct ata_host *host, void *psource, readl(mmio + PDC_DIMM_WINDOW_CTLR); offset -= (idx * window_size); idx++; - dist = ((long)(s32)(window_size - (offset + size))) >= 0 ? size : - (long) (window_size - offset); + dist = min(size, window_size - offset); memcpy_toio(dimm_mmio + offset / 4, psource, dist); writel(0x01, mmio + PDC_GENERAL_CTLR); readl(mmio + PDC_GENERAL_CTLR); -- 2.39.2