From patchwork Thu Sep 28 20:25:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Ricardo Leitner X-Patchwork-Id: 819730 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="gB+HEfis"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3y35mT4Hxtz9sNr for ; Fri, 29 Sep 2017 06:25:45 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751579AbdI1UZm (ORCPT ); Thu, 28 Sep 2017 16:25:42 -0400 Received: from mail-qk0-f196.google.com ([209.85.220.196]:35001 "EHLO mail-qk0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750880AbdI1UZj (ORCPT ); Thu, 28 Sep 2017 16:25:39 -0400 Received: by mail-qk0-f196.google.com with SMTP id o77so1773051qke.2; Thu, 28 Sep 2017 13:25:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=OZdUtgMbul6TWLTps+tWb4b0ILnF8EbRcWZjwj9g+SU=; b=gB+HEfisLtp77So5aWPZCLTauvTU3Q9w3RDodDYIiCgN10q3NtW0YJkDblpbnF/Zfo GMF4S4nfDjNsFnGkGmx/NUJsfrMzl7Vzl3s5+zC340tte06wm4l9EljFwKIQ42ZZzsV8 7yFH6pKoSNTEj3U7+L//Xuf5DJc8XwkPrhFxY6Y+x3UzcEEt59H2vl9PI+7CGe75XfMP nENuZaDbf8o0uYxsSzN9ZDpR7BgsZxWedcYcUaDlAoNrAMRgnVQgaQwFDx7NjD0UTyFz BVWvG7BS6c3FKv7CKmx2XdZmTEr0FcRO6f63Z1K38u8rJzDWaPunGBm2foGXyHX8ZUYp yKRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=OZdUtgMbul6TWLTps+tWb4b0ILnF8EbRcWZjwj9g+SU=; b=YPxrjolWEBis+h5hiQ5bW+LHJwm3axHp3b/5wsUd87mOs8oBS7zpeNIxKFKGiKi4zy KqzQQjizAPSIBGLWSzgU+lAmbnIqFhOsBw13UfS5NooUFODhPXvtaLMGF6PFSwvoe1KZ /Dyu/MOo7qKYOxGR/Tnqd87XEK5Cv7Ml4JThmgitKrN9mFyEfVsGzegnWAEaVK9JvAHv WcGtNfjlTcuQga4oG1TwhGZBw/Y5f4t7nR4uEcBio9bNBHD1nc2RQN5PZ9YYufUBy7ur vJU+cAln3L9R0O7r3qsk1P8QcV98aiqvx+TdsWnPrE+VEYajo4xxxzzihohHPQqWg6uQ PuPw== X-Gm-Message-State: AMCzsaXa8ohzCJSH7B8iEFYmrA/wcuuzI6zxIWmffG20bO+Ij2Q5V7Cv 50el3BjOoD0YQBvvvBL+Jofq9r6j X-Google-Smtp-Source: AOwi7QAl4DWU2GzWf6wUvFe2tlVmm36DJI5eFyFfxCti4sSd1d60Z7Abt8+DV5e0VJQQEF8Ys7hnEA== X-Received: by 10.55.42.88 with SMTP id q85mr236121qkh.71.1506630338354; Thu, 28 Sep 2017 13:25:38 -0700 (PDT) Received: from localhost.localdomain.com ([2001:1284:f019:d59e:a58:6656:fe6b:aeea]) by smtp.gmail.com with ESMTPSA id 16sm1661745qtw.38.2017.09.28.13.25.36 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Sep 2017 13:25:37 -0700 (PDT) From: Marcelo Ricardo Leitner To: netdev@vger.kernel.org Cc: linux-sctp@vger.kernel.org, Neil Horman , Vlad Yasevich , Xin Long , David Laight Subject: [PATCH net-next 01/10] sctp: silence warns on sctp_stream_init allocations Date: Thu, 28 Sep 2017 17:25:14 -0300 Message-Id: <78853a7e413d1900fb410d73d064558fa09f221d.1506536044.git.marcelo.leitner@gmail.com> X-Mailer: git-send-email 2.13.5 In-Reply-To: References: Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org As SCTP supports up to 65535 streams, that can lead to very large allocations in sctp_stream_init(). As Xin Long noticed, systems with small amounts of memory are more prone to not have enough memory and dump warnings on dmesg initiated by user actions. Thus, silence them. Also, if the reallocation of stream->out is not necessary, skip it and keep the memory we already have. Reported-by: Xin Long Signed-off-by: Marcelo Ricardo Leitner --- net/sctp/stream.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/net/sctp/stream.c b/net/sctp/stream.c index 63ea1550371493ec8863627c7a43f46a22f4a4c9..1afa9555808390d5fc736727422d9700a3855613 100644 --- a/net/sctp/stream.c +++ b/net/sctp/stream.c @@ -40,9 +40,14 @@ int sctp_stream_init(struct sctp_stream *stream, __u16 outcnt, __u16 incnt, { int i; + gfp |= __GFP_NOWARN; + /* Initial stream->out size may be very big, so free it and alloc - * a new one with new outcnt to save memory. + * a new one with new outcnt to save memory if needed. */ + if (outcnt == stream->outcnt) + goto in; + kfree(stream->out); stream->out = kcalloc(outcnt, sizeof(*stream->out), gfp); @@ -53,6 +58,7 @@ int sctp_stream_init(struct sctp_stream *stream, __u16 outcnt, __u16 incnt, for (i = 0; i < stream->outcnt; i++) stream->out[i].state = SCTP_STREAM_OPEN; +in: if (!incnt) return 0;