Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp634167pxj; Thu, 20 May 2021 18:31:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/Y43hErWF8Zvu2IWcn+zr20zF1shUnY1nydchVCQCIMOIeNLMJDkfUS7m+5cSivBwkrWh X-Received: by 2002:a02:8787:: with SMTP id t7mr499242jai.53.1621560708454; Thu, 20 May 2021 18:31:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621560708; cv=none; d=google.com; s=arc-20160816; b=C+ZRua4rP0wtjmsRwXsaUf+qVcQElbKb5C6BoyevFVf6n0BXDNwndekM/CMya0KKjM tE+wI9jb+qHa9CK6uEynat8u9M+ruQgt4+ai1cmO5k5Zf9XZmCGgHl913P3+8UW944A7 eQc4MJlWmUUjPTk4eskmqKADaOusyktlAOFxIeiUkTW+HOkYsxad0Gxrjj4F7NG09oWP sHObyxzSVgQqyXzbBNBoRelbvIUq8WsT93cW8niJ8qOdle6OQ0SDCTP6to7VojMtgZrd jnFiAeVk0d8+ITwF10gkPeBEqxsAsgI8gU9w8Eqf794Cx7bCG3D69bgAMGqLIRq2Qy3U 6b3w== 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=glT/5hpvSYu9vSZzH8eGyoSlfHMBr13knGcUCa3yg38=; b=oTIxv/Oy4NirrBsH2fNrnTMQMq8qM8N+7JazdAia+zhMSayEaXErIaxnTh+pkSfz10 2KBVj7HVda+iHKsN1aqmpIBHC4JNF493RawvbnCodrTIY0D83AGYvZc3V/e/kN3CyFQ4 knDMtL6naIF2OIKJ9y1R+MVUuR8QqHUavGQYY9JNzd9WoQNzBifa2g7ZPY/VMYulYMYo /ciTm7C+E/AzyJEXuYr4LYJUBGhvp6iw8YJPMiNn30tU4kocuPiduqPLlWNdcXHFLajQ uqbAStbqk6AcUEFvOXiK2ODFuRc3V4kMYxp+9SHgY+vDhnPn0Ffd5Nai5r3Or580ikAB oGXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="BQx9Qe/Q"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w17si1945908jad.108.2021.05.20.18.31.35; Thu, 20 May 2021 18:31:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="BQx9Qe/Q"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242645AbhETLkS (ORCPT + 99 others); Thu, 20 May 2021 07:40:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:38358 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240779AbhETLTW (ORCPT ); Thu, 20 May 2021 07:19:22 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 64D9C61D65; Thu, 20 May 2021 10:10:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621505432; bh=/ZW8JwvHwnl77jWCkthAo3Vaac0GolRsZMMhyixU/f4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BQx9Qe/QQkIW3cZ34XZiwQ+mSd7rFyVJ1DELwy3JjG9l7bbKeVrta2L2gw/SAuOTW eIp2Mmtc4K7u1lb3wXq6a1R1qAbdrG5vr7sLFQxTwNO35MBzK4D0/oPjcVhHP7wZOE SeVH69w/HBQQKurgFhOPMU1DYTe75L8iKIbrPAx0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Stefani Seibold , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 4.4 132/190] kfifo: fix ternary sign extension bugs Date: Thu, 20 May 2021 11:23:16 +0200 Message-Id: <20210520092106.560858243@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092102.149300807@linuxfoundation.org> References: <20210520092102.149300807@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dan Carpenter [ Upstream commit 926ee00ea24320052b46745ef4b00d91c05bd03d ] The intent with this code was to return negative error codes but instead it returns positives. The problem is how type promotion works with ternary operations. These functions return long, "ret" is an int and "copied" is a u32. The negative error code is first cast to u32 so it becomes a high positive and then cast to long where it's still a positive. We could fix this by declaring "ret" as a ssize_t but let's just get rid of the ternaries instead. Link: https://lkml.kernel.org/r/YIE+/cK1tBzSuQPU@mwanda Fixes: 5bf2b19320ec ("kfifo: add example files to the kernel sample directory") Signed-off-by: Dan Carpenter Cc: Stefani Seibold Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- samples/kfifo/bytestream-example.c | 8 ++++++-- samples/kfifo/inttype-example.c | 8 ++++++-- samples/kfifo/record-example.c | 8 ++++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/samples/kfifo/bytestream-example.c b/samples/kfifo/bytestream-example.c index 2fca916d9edf..a7f5ee8b6edc 100644 --- a/samples/kfifo/bytestream-example.c +++ b/samples/kfifo/bytestream-example.c @@ -124,8 +124,10 @@ static ssize_t fifo_write(struct file *file, const char __user *buf, ret = kfifo_from_user(&test, buf, count, &copied); mutex_unlock(&write_lock); + if (ret) + return ret; - return ret ? ret : copied; + return copied; } static ssize_t fifo_read(struct file *file, char __user *buf, @@ -140,8 +142,10 @@ static ssize_t fifo_read(struct file *file, char __user *buf, ret = kfifo_to_user(&test, buf, count, &copied); mutex_unlock(&read_lock); + if (ret) + return ret; - return ret ? ret : copied; + return copied; } static const struct file_operations fifo_fops = { diff --git a/samples/kfifo/inttype-example.c b/samples/kfifo/inttype-example.c index 8dc3c2e7105a..a326a37e9163 100644 --- a/samples/kfifo/inttype-example.c +++ b/samples/kfifo/inttype-example.c @@ -117,8 +117,10 @@ static ssize_t fifo_write(struct file *file, const char __user *buf, ret = kfifo_from_user(&test, buf, count, &copied); mutex_unlock(&write_lock); + if (ret) + return ret; - return ret ? ret : copied; + return copied; } static ssize_t fifo_read(struct file *file, char __user *buf, @@ -133,8 +135,10 @@ static ssize_t fifo_read(struct file *file, char __user *buf, ret = kfifo_to_user(&test, buf, count, &copied); mutex_unlock(&read_lock); + if (ret) + return ret; - return ret ? ret : copied; + return copied; } static const struct file_operations fifo_fops = { diff --git a/samples/kfifo/record-example.c b/samples/kfifo/record-example.c index 2d7529eeb294..deb87a2e4e6b 100644 --- a/samples/kfifo/record-example.c +++ b/samples/kfifo/record-example.c @@ -131,8 +131,10 @@ static ssize_t fifo_write(struct file *file, const char __user *buf, ret = kfifo_from_user(&test, buf, count, &copied); mutex_unlock(&write_lock); + if (ret) + return ret; - return ret ? ret : copied; + return copied; } static ssize_t fifo_read(struct file *file, char __user *buf, @@ -147,8 +149,10 @@ static ssize_t fifo_read(struct file *file, char __user *buf, ret = kfifo_to_user(&test, buf, count, &copied); mutex_unlock(&read_lock); + if (ret) + return ret; - return ret ? ret : copied; + return copied; } static const struct file_operations fifo_fops = { -- 2.30.2