From patchwork Thu Apr 22 09:02:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 12218029 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A3A83C433ED for ; Thu, 22 Apr 2021 09:04:58 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 053FE61428 for ; Thu, 22 Apr 2021 09:04:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 053FE61428 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-ID:Subject:Cc:To:From:Date: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=6KdmtLErSsyVWshskEXtoSpHD/QdDfcOEEaRkABZdhc=; b=BjYNMwfIN6jDLXZf1DF1ijvYfZ blq94XmJ/uRL01OkSR7jpmVeG6rdoP0tgMlHP7AbFA89nuaozHqsMGY1gtAcT3Ix9FImQZwWVU429 Yr3mZ2aDIVuEbAyp0fHPzcD6x4ngLPemgM7LK8jIl5smQFIilTiSHDWI0UmPbTTIVdwVQFr8Mxgcf x1ZL+xhkGg+4Fw+kjFwVPC4nKQiCv4c0eOHTwB/peeaAIjsMV+svT9UDPJ5WXGe9ml1NAo4cY82yn bHYed5bD0XVQ0IS+XDPGPYB9sTTf5dhocEDsKW0xwnDj9YWBO05EsbwfZdjQILHUu4ZnnqtljjjBR g4jhR60A==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lZVEl-00GKkh-Rf; Thu, 22 Apr 2021 09:03:04 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lZVEj-00GKkb-4b for linux-arm-kernel@desiato.infradead.org; Thu, 22 Apr 2021 09:03:01 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Type:MIME-Version:Message-ID: Subject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:In-Reply-To:References; bh=luKBrUqgQXuE6ecf9zdzvMeJVaBMF+rgQS18TT6YaPA=; b=oEVLlTejqcMyK10q53ZDj7GMRe 8LqRaxhZNxZKx1On5WR3szDqf5+NIOxDFYTv4hnianPFralrVur/3awdM5YVhkDkjVQepuO/67Fpr 20GdbWJ0UPPVCIj4dtLN8tCV7jeNcaJILTQdB/V2UPv2vP72hbfITpK3JG6buG9ImnN4P91CZXc4P k8l1cj7ArxkMqfgOS3FxJiqrVnk0EzISGz1dHx4RYGGCpF00qRu6V67WSm66WVHH7z/BDcnpw6DPF I/1sBTonb8EWou8CF7GlvvqypeVI9DDm7GA6+ScExlt7uD6+nRiABToZkjLOXGTpEMBZbtpI77od/ GGvsc5/A==; Received: from userp2130.oracle.com ([156.151.31.86]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lZVEg-00DWhO-HT for linux-arm-kernel@lists.infradead.org; Thu, 22 Apr 2021 09:02:59 +0000 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 13M8evtu061731; Thu, 22 Apr 2021 09:02:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : mime-version : content-type; s=corp-2020-01-29; bh=luKBrUqgQXuE6ecf9zdzvMeJVaBMF+rgQS18TT6YaPA=; b=rj5IDy98a1ehCtAM80zC/x0IcJiL/RU5XYtd39WlRaw4mq638nti628pFWfEZ2reVLa8 TFf62VNjYkXNYjtwqvohr+SM3kxRfapDYyXbRdveDyNrWLrOb2okwKKtRdDVabvwJFqM mk3yhSiy5cdL+T07A8iMA1ni5GZmb4mhvkR+uZpQ0QV0mU1lNRZKOwK02df5MkwzxWs8 1akpvtqRId4zjOlvIWpfvk86yHfsFiybynPegOPAx4T/YbzdXEdC1o6RQq3TwAQRvsVK wHU31F+/K+BwDC6mNmxJ+j7lccu1jemHF/P1v9AJ4YO0oX68qDEnQYSR4AgpKkYzBOGu cw== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 37yveamdgf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 22 Apr 2021 09:02:37 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 13M9038W156046; Thu, 22 Apr 2021 09:02:37 GMT Received: from pps.reinject (localhost [127.0.0.1]) by userp3020.oracle.com with ESMTP id 3809evjx53-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 22 Apr 2021 09:02:37 +0000 Received: from userp3020.oracle.com (userp3020.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 13M92bRp170135; Thu, 22 Apr 2021 09:02:37 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3020.oracle.com with ESMTP id 3809evjx4s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 22 Apr 2021 09:02:37 +0000 Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 13M92Zp4019604; Thu, 22 Apr 2021 09:02:35 GMT Received: from mwanda (/10.175.205.56) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 22 Apr 2021 09:02:35 +0000 Date: Thu, 22 Apr 2021 12:02:29 +0300 From: Dan Carpenter To: Sudeep Holla Cc: Cristian Marussi , "Jon Medhurst (Tixy)" , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH] firmware: arm_scpi: prevent ternary sign expansion bug Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Mailer: git-send-email haha only kidding X-Proofpoint-GUID: 6Sb26I_pnSMvX2LJsvaeWNeSbcTLo0wR X-Proofpoint-ORIG-GUID: 6Sb26I_pnSMvX2LJsvaeWNeSbcTLo0wR X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9961 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 impostorscore=0 phishscore=0 mlxscore=0 suspectscore=0 lowpriorityscore=0 mlxlogscore=999 spamscore=0 bulkscore=0 adultscore=0 malwarescore=0 clxscore=1011 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104220073 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210422_020258_737447_74D05A34 X-CRM114-Status: GOOD ( 16.60 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org How type promotion works in ternary expressions is a bit tricky. The problem is that scpi_clk_get_val() returns longs, "ret" is a int which holds a negative error code, and le32_to_cpu() is an unsigned int. We want the negative error code to be cast to a negative long. But because le32_to_cpu() is an u32 then "ret" is type promoted to u32 and becomes a high positive and then it is promoted to long and it is still a high positive value. Fix this by getting rid of the ternary. Fixes: 8cb7cf56c9fe ("firmware: add support for ARM System Control and Power Interface(SCPI) protocol") Signed-off-by: Dan Carpenter Reviewed-by: Cristian Marussi --- drivers/firmware/arm_scpi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/arm_scpi.c b/drivers/firmware/arm_scpi.c index d0dee37ad522..3bf61854121d 100644 --- a/drivers/firmware/arm_scpi.c +++ b/drivers/firmware/arm_scpi.c @@ -552,8 +552,10 @@ static unsigned long scpi_clk_get_val(u16 clk_id) ret = scpi_send_message(CMD_GET_CLOCK_VALUE, &le_clk_id, sizeof(le_clk_id), &rate, sizeof(rate)); + if (ret) + return ret; - return ret ? ret : le32_to_cpu(rate); + return le32_to_cpu(rate); } static int scpi_clk_set_val(u16 clk_id, unsigned long rate)