From owner-freebsd-ppc@freebsd.org Mon Jan 13 15:18:22 2020 Return-Path: Delivered-To: freebsd-ppc@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 32EA822790F for ; Mon, 13 Jan 2020 15:18:22 +0000 (UTC) (envelope-from chmeeedalf@gmail.com) Received: from mail-yw1-xc29.google.com (mail-yw1-xc29.google.com [IPv6:2607:f8b0:4864:20::c29]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 47xHKT2k8tz4dmm for ; Mon, 13 Jan 2020 15:18:21 +0000 (UTC) (envelope-from chmeeedalf@gmail.com) Received: by mail-yw1-xc29.google.com with SMTP id d7so6259866ywl.12 for ; Mon, 13 Jan 2020 07:18:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Hxg077ssBWphNLbhgrpeUu19O60XUSrb3SbRi/U6o0c=; b=l8cXoz6KV3+y9jqIWeLIQL8g3S6JQ52zAVai0ayMnydrV80rB0nnC9rWoJiatH7paH yrTjs1ZSZAdnnG96g6n8DBElIdH3EaUheVbiiFaEMDCrCs7f7pJ8/EsD7KzJSkpGJCDy JoFYfPmROih41ai9empLYOhAG6wMFJfykCBpPcWiFxs1T29eIsSpPJDttNC/FI5U9/T5 NMhMWSuFpR50ZzWHJV+LKJd0JxHA5VJTFHrTsJAdBxFvNFUU2fIzjyA791HQG7FTxvs9 LnXR7gz3PtvbJFqHQnogYOkxocJyRPhu6pBeXloanwFY0z5wLJavOYZ/X0UHlUdneXwP I77Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Hxg077ssBWphNLbhgrpeUu19O60XUSrb3SbRi/U6o0c=; b=NlumFzCKBLkCmNWYgHlHTqfx5BChWq1ZTrivkuPwYowKytkwvvgiHalmYZy7WWf9GZ FZ3w1IDcq6zykDvoSnPadgGCAyykRJXW+GNOCJfkzuAl9AYuFap/mwo0aQ5OS9Y4bENJ vHP1bfqmuaQQfyRHSRVX//j/7+pqwKNDqVK5Z7NL5RFpjicEB3HuCgJ6qK7oxU8aQRU3 E6jLdA4weyDuX0mhQnjubJ72bZt/z/J5iExKgO4KY0TxzGunFerWoXRns42ZliPmNAZf 8SZMC5SMmnCBkT53RQleKIm1lR0uaC24hAkPKvakbUo+bxgfPzLNDOSzQtxwkvB0mWvd YwCg== X-Gm-Message-State: APjAAAUWgovME9qM56kr5uMqCJioT52i8/4GiyE8L2hQbBHlTrrSW2Jd yegb83HjmfRcOzjYmoSX94s= X-Google-Smtp-Source: APXvYqzsa2lKts1Xnk5mpHcVC/kF0V+It3q2MaLQFmKhaaWOP9Nc5Yue18sCFrWZ0YZO50VtCNVzZw== X-Received: by 2002:a81:1ac6:: with SMTP id a189mr13056149ywa.85.1578928700225; Mon, 13 Jan 2020 07:18:20 -0800 (PST) Received: from titan.knownspace (173-19-125-130.client.mchsi.com. [173.19.125.130]) by smtp.gmail.com with ESMTPSA id a74sm5268919ywe.42.2020.01.13.07.18.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2020 07:18:19 -0800 (PST) Date: Mon, 13 Jan 2020 09:17:50 -0600 From: Justin Hibbits To: Mark Millard Cc: FreeBSD PowerPC ML Subject: Re: head -r356640 and mixed signed/unsigned comparisons Message-ID: <20200113091750.4a02b428@titan.knownspace> In-Reply-To: <18622739-BB2E-432B-B877-2FBE3A9D4ECB@yahoo.com> References: <18622739-BB2E-432B-B877-2FBE3A9D4ECB.ref@yahoo.com> <18622739-BB2E-432B-B877-2FBE3A9D4ECB@yahoo.com> X-Mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; powerpc64-portbld-freebsd13.0) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 47xHKT2k8tz4dmm X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20161025 header.b=l8cXoz6K; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (mx1.freebsd.org: domain of chmeeedalf@gmail.com designates 2607:f8b0:4864:20::c29 as permitted sender) smtp.mailfrom=chmeeedalf@gmail.com X-Spamd-Result: default: False [-3.00 / 15.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; FREEMAIL_FROM(0.00)[gmail.com]; R_SPF_ALLOW(-0.20)[+ip6:2607:f8b0:4000::/36:c]; RCVD_COUNT_THREE(0.00)[3]; TO_DN_ALL(0.00)[]; DKIM_TRACE(0.00)[gmail.com:+]; RCPT_COUNT_TWO(0.00)[2]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; FREEMAIL_TO(0.00)[yahoo.com]; RECEIVED_SPAMHAUS_PBL(0.00)[130.125.19.173.khpj7ygk5idzvmvt5x4ziurxhy.zen.dq.spamhaus.net : 127.0.0.11]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; DWL_DNSWL_NONE(0.00)[gmail.com.dwl.dnswl.org : 127.0.5.0]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20161025]; FROM_HAS_DN(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-ppc@freebsd.org]; IP_SCORE_FREEMAIL(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCVD_IN_DNSWL_NONE(0.00)[9.2.c.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.4.6.8.4.0.b.8.f.7.0.6.2.list.dnswl.org : 127.0.5.0]; IP_SCORE(0.00)[ip: (-9.26), ipnet: 2607:f8b0::/32(-2.10), asn: 15169(-1.84), country: US(-0.05)]; RCVD_TLS_ALL(0.00)[] X-BeenThere: freebsd-ppc@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Porting FreeBSD to the PowerPC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Jan 2020 15:18:22 -0000 On Sat, 11 Jan 2020 17:28:22 -0800 Mark Millard wrote: > The code: > > 394 for (j = 0; j < addr_cells - 1; j++) { > > looks wrong to me. Evidence follows. > > /usr/src/sys/dev/ofw/openfirm.h:typedef uint32_t pcell_t; > /usr/include/sys/_stdint.h:typedef __uint32_t > uint32_t; /usr/include/machine/_types.h:typedef unsigned int > __uint32_t; > > So pcell_t and int are of the same rank but different > unsigned vs. signed status. > > From sys/powerpc/mpc85xx/lbc.c : > > 363 static int > 364 fdt_lbc_reg_decode(phandle_t node, struct lbc_softc *sc, > 365 struct lbc_devinfo *di) > 366 { > . . . > 369 pcell_t addr_cells, size_cells; > . . . > 371 int i, j, rv, bank; > . . . > 394 for (j = 0; j < addr_cells - 1; j++) { > 395 start <<= 32; > 396 start |= reg[j]; > 397 } > > So, for line 394, after the usual arithmetic > conversions for the "-" and then for the "<" > the line would look like (consolidating > some relevant material to be more > textually-local for ease of comparison): > > for (int j = 0; (unsigned int)j < addr_cells-1u; j++) > > For addr_cells==0u: addr_cells-1u == UINT_MAX . > > So, for addr_cells==0u substituted (at run-time): > > for (int j = 0; (unsigned int)j < UINT_MAX; j++) > > So, unless it is guaranteed that 0u there would appear to be a looping problem here. > > It appears to me that the condition: > > addr_cells==0u && 0u > would fail the tuples <= 0 test and so continue > on to try to use line 394. > > But I do not have context to know the > condition would be a worrisome issue. The only way addr_cells and size_cells can be zero is if the device tree explicitly has #address-cells = <0> and #size-cells = <0>. It's not impossible, but it's not reasonable, and violates the requirements of the node. It doesn't hurt to add checks, but it's not a priority either. - Justin