Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1348386ybp; Thu, 17 Oct 2019 11:25:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqxwDQ53uihlKfaB+Cc4h4EWHVbuOiaLy15jaXY2FHrN7HBZvgBZxWrE1MTXh7sGXb4pzReM X-Received: by 2002:a05:6402:2028:: with SMTP id ay8mr5233965edb.273.1571336708134; Thu, 17 Oct 2019 11:25:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571336708; cv=none; d=google.com; s=arc-20160816; b=lLYpzaX/bCUPMc77srJtFmzBHP/sPrw0sjPAOZG5Zt0YVTST1LUnneX1uzsrDDywhG B6j/uznyEa+YnRrVWLw8Qzpdu2ufCu6dFmtXoFozxgaGgDMdNtIo5DxwCitu5IvLjo5v 8w5B6M/Jj1BUTibS+zvgqtgTH1//E/sbkMuhsxG7Z+WrtOMyJczvF1tCMTt1envEPXcs HhIRhiQLaIjSwPB4xeNQAUxLxVxRsVhyhq4zk6Na68PHDqZjXB8RZbs2f/JLth/LWgPP ebwchgw4ygPv469ztoPMk5+xUZX7QXfO02R2e4ybhKxE6E3Z+Iw2PgLY7hQpJ9z0dx57 deCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=W4VIKR9Nx6Q65LvQzuxKMssSL4TGgUfDQGgH9y/fwAM=; b=cIK2fHzJqvr6cpP8nlfqhhi/3HzO4uK7qBdUlixKzPNjlz6oHXz/zv0m+bFvxIdpp2 r/8C5aIgL4GS2KyLo9cWVgXgTG21Uma9Nk/TKZBvA9JYJc04XJHjEXTQOmTISBpVRx1h MALZly/j8lcPjGWAur1QfXk4kaAWIS/9KlS4f8FhRbVD4Lk0JgBHAFBUeS2rapzpxkCz nDzdzTUE/ymW0lS2SktMy6H02cSb0bvLDsT+j9kkD6ucCAxv2Cp6qOgkZ0o4z3LzXcov KkbEg0kzUxhpbQ96ItshmhtZecXq5R2lxtunX4Zg04D/Ntay2Eev3thHwg9ZwiueFjVJ h9lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ntiOtuJf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h13si1958581edw.348.2019.10.17.11.24.45; Thu, 17 Oct 2019 11:25:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ntiOtuJf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404385AbfJPWEL (ORCPT + 99 others); Wed, 16 Oct 2019 18:04:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:53624 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438416AbfJPV7L (ORCPT ); Wed, 16 Oct 2019 17:59:11 -0400 Received: from localhost (unknown [192.55.54.58]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 771BC21D7A; Wed, 16 Oct 2019 21:59:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571263150; bh=ErdbU82ThM3I9cHDFmp0MNhZUp0TxhFVzZStJVwB6h8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ntiOtuJfW+b4eA3WCjvbyNK1R5xCs+trQshov+qBHUwCdyNHxI78BF+kosfvBQYse 4hTsqgE5VyFiZAmPdPs4oA0HOuEfjanFfj5y+HjJooXjJXZSaNJqGv2ft6WqJ+Tckj npIzrMegDMdLJLdq+BNamT/xeOresYWoe6LA89bA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Andy Shevchenko , David Rientjes , Matthew Wilcox , Thomas Gleixner , Enrico Weigelt , Kate Stewart , Andrew Morton , Linus Torvalds Subject: [PATCH 5.3 078/112] mm/vmpressure.c: fix a signedness bug in vmpressure_register_event() Date: Wed, 16 Oct 2019 14:51:10 -0700 Message-Id: <20191016214904.308616614@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191016214844.038848564@linuxfoundation.org> References: <20191016214844.038848564@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dan Carpenter commit 518a86713078168acd67cf50bc0b45d54b4cce6c upstream. The "mode" and "level" variables are enums and in this context GCC will treat them as unsigned ints so the error handling is never triggered. I also removed the bogus initializer because it isn't required any more and it's sort of confusing. [akpm@linux-foundation.org: reduce implicit and explicit typecasting] [akpm@linux-foundation.org: fix return value, add comment, per Matthew] Link: http://lkml.kernel.org/r/20190925110449.GO3264@mwanda Fixes: 3cadfa2b9497 ("mm/vmpressure.c: convert to use match_string() helper") Signed-off-by: Dan Carpenter Reviewed-by: Andy Shevchenko Acked-by: David Rientjes Reviewed-by: Matthew Wilcox Cc: Greg Kroah-Hartman Cc: Thomas Gleixner Cc: Enrico Weigelt Cc: Kate Stewart Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/vmpressure.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) --- a/mm/vmpressure.c +++ b/mm/vmpressure.c @@ -355,6 +355,9 @@ void vmpressure_prio(gfp_t gfp, struct m * "hierarchy" or "local"). * * To be used as memcg event method. + * + * Return: 0 on success, -ENOMEM on memory failure or -EINVAL if @args could + * not be parsed. */ int vmpressure_register_event(struct mem_cgroup *memcg, struct eventfd_ctx *eventfd, const char *args) @@ -362,7 +365,7 @@ int vmpressure_register_event(struct mem struct vmpressure *vmpr = memcg_to_vmpressure(memcg); struct vmpressure_event *ev; enum vmpressure_modes mode = VMPRESSURE_NO_PASSTHROUGH; - enum vmpressure_levels level = -1; + enum vmpressure_levels level; char *spec, *spec_orig; char *token; int ret = 0; @@ -375,20 +378,18 @@ int vmpressure_register_event(struct mem /* Find required level */ token = strsep(&spec, ","); - level = match_string(vmpressure_str_levels, VMPRESSURE_NUM_LEVELS, token); - if (level < 0) { - ret = level; + ret = match_string(vmpressure_str_levels, VMPRESSURE_NUM_LEVELS, token); + if (ret < 0) goto out; - } + level = ret; /* Find optional mode */ token = strsep(&spec, ","); if (token) { - mode = match_string(vmpressure_str_modes, VMPRESSURE_NUM_MODES, token); - if (mode < 0) { - ret = mode; + ret = match_string(vmpressure_str_modes, VMPRESSURE_NUM_MODES, token); + if (ret < 0) goto out; - } + mode = ret; } ev = kzalloc(sizeof(*ev), GFP_KERNEL); @@ -404,6 +405,7 @@ int vmpressure_register_event(struct mem mutex_lock(&vmpr->events_lock); list_add(&ev->node, &vmpr->events); mutex_unlock(&vmpr->events_lock); + ret = 0; out: kfree(spec_orig); return ret;