From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1468C433EF for ; Thu, 3 Mar 2022 12:28:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232621AbiCCM2s convert rfc822-to-8bit (ORCPT ); Thu, 3 Mar 2022 07:28:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232047AbiCCM2r (ORCPT ); Thu, 3 Mar 2022 07:28:47 -0500 Received: from aposti.net (aposti.net [89.234.176.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B96B1344F7; Thu, 3 Mar 2022 04:28:01 -0800 (PST) Date: Thu, 03 Mar 2022 12:27:37 +0000 From: Paul Cercueil Subject: RE: [PATCH v3] serial: make uart_console_write->putchar()'s character an unsigned char To: David Laight Cc: "'Maciej W. Rozycki'" , Jiri Slaby , 'Uwe =?iso-8859-1?q?Kleine-K=F6nig=27?= , gregkh@linuxfoundation.org, Alexandre Belloni , Mateusz Holenko , Neil Armstrong , Benjamin Herrenschmidt , Liviu Dudau , Baruch Siach , linux-kernel@vger.kernel.org, Paul Mackerras , Michael Ellerman , Michal Simek , Karol Gugala , Jerome Brunet , Peter Korsgaard , Florian Fainelli , Alexander Shiyan , Krzysztof Kozlowski , Alexandre Torgue , Fabio Estevam , Russell King , Ludovic Desroches , Andy Gross , bcm-kernel-feedback-list@broadcom.com, NXP Linux Team , linux-serial@vger.kernel.org, Vineet Gupta , Orson Zhai , Tobias Klauser , Patrice Chotard , Albert Ou , Maxime Coquelin , Manivannan Sadhasivam , Martin Blumenstingl , Sascha Hauer , Takao Orito , Vladimir Zapolskiy , Lorenzo Pieralisi , Paul Walmsley , Bjorn Andersson , Sudeep Holla , Richard Genoud , Chunyan Zhang , Nicolas Ferre , "David S. Miller" , Taichi Sugaya , Palmer Dabbelt , Pengutronix Kernel Team , Kevin Hilman , Baolin Wang , Shawn Guo , Andreas =?iso-8859-1?q?F=E4rber?= Message-Id: <1A568R.RVXRB53P9YYQ1@crapouillou.net> In-Reply-To: <9fa84690ed244eba89f1efe4e6670f80@AcuMS.aculab.com> References: <20220302072732.1916-1-jslaby@suse.cz> <20220302175242.ejiaf36vszr4xvou@pengutronix.de> <5c7045c1910143e08ced432d938b5825@AcuMS.aculab.com> <84ad3854-28b9-e450-f0a2-f1448f32f137@suse.cz> <9fa84690ed244eba89f1efe4e6670f80@AcuMS.aculab.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org Hi David, Le jeu., mars 3 2022 at 11:44:42 +0000, David Laight a écrit : > From: Maciej W. Rozycki >> Sent: 03 March 2022 11:31 > .. >> It does, but, oh dear, it's a "solution" to a problem we have >> created in >> the first place. Why do we ever want to have signed characters in >> the TTY >> layer, and then to vary between platforms? It's asking for >> portability >> issues. > > C 'char' is signed because the pdp/11 byte load sign extended. That's incorrect. The C standard does say that "the implementation shall define char to have the same range, representation, and behavior as either signed char or unsigned char". C 'char' is signed on x86 (and MIPS and Sparc etc.). It is unsigned on ARM, PowerPC and Risc-V among others. > I guess some ABI use unsigned char to avoid issues with all > the functions that take/return an int parameter that is > either a 'char' cast to 'unsigned char' or EOF. > > EOF is usually (-1) - but doesn't have to be. > But it needs to be different from any value obtained > by casting a 'char' to 'unsigned char'. > (But that may only need to be all characters, not all values of > 'char'.) Is the putchar() callback ever going to be called with EOF? I don't think so. > Then you get the requirement that: > sizeof (int) >= sizeof (short) >= sizeof (char) > which means that it is perfectly valid for all 3 to be the same size > [1]. > In that case 'unsigned char' promotes to 'unsigned int' > which probably breaks some code. We're talking about Linux here. Ints are 32-bit. Cheers, -Paul