From patchwork Thu Apr 16 23:03:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tejun Heo X-Patchwork-Id: 461864 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 31E46140273 for ; Fri, 17 Apr 2015 09:06:55 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="verification failed; unprotected key" header.d=gmail.com header.i=@gmail.com header.b=0ZSfYIw+; dkim-adsp=none (unprotected policy); dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932123AbbDPXGj (ORCPT ); Thu, 16 Apr 2015 19:06:39 -0400 Received: from mail-qc0-f170.google.com ([209.85.216.170]:34146 "EHLO mail-qc0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753503AbbDPXE3 (ORCPT ); Thu, 16 Apr 2015 19:04:29 -0400 Received: by qcyk17 with SMTP id k17so15346122qcy.1; Thu, 16 Apr 2015 16:04:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=ynbam04t+Qha7Pum+fuYTwhoDmvOQ53/Dg+Gtk/25jU=; b=0ZSfYIw+XLmImwlBGM5Rb5w/IkGMnd43qiCPHmrb+dH74rs1ZYzdZ82kRy6mTgU4jM tVLT9JbaDWOWS9D0Th20nluk3lf9cHoBU3OxyxCQgqeasaoyWx/uUocotolhtKWBjOWC o57JpnhKP2OAsff0+LCLDZ3zsjvd7M0z3MtED2r29C60b189Ul1UWPEqWWR0QEv3qf4d fYA/0RKeYRxyOq9zr9pSEr0iApKEUHYUJIovvAq0+YQEVc7WN80RGIdJ6KQtrguTcYJV yOP3OxXrRoQxFjWVNaUC1z6S5u2xOqHxdk5/teIQZD6kABi9AlVz77r008CjgMcS6lyx 1dpw== X-Received: by 10.55.22.65 with SMTP id g62mr292501qkh.72.1429225469155; Thu, 16 Apr 2015 16:04:29 -0700 (PDT) Received: from htj.duckdns.org.lan (207-38-238-8.c3-0.wsd-ubr1.qens-wsd.ny.cable.rcn.com. [207.38.238.8]) by mx.google.com with ESMTPSA id z77sm6677670qkg.44.2015.04.16.16.04.26 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Apr 2015 16:04:27 -0700 (PDT) From: Tejun Heo To: akpm@linux-foundation.org, davem@davemloft.net Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Tejun Heo Subject: [PATCH 07/16] netconsole: factor out alloc_netconsole_target() Date: Thu, 16 Apr 2015 19:03:44 -0400 Message-Id: <1429225433-11946-8-git-send-email-tj@kernel.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1429225433-11946-1-git-send-email-tj@kernel.org> References: <1429225433-11946-1-git-send-email-tj@kernel.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org alloc_param_target() and make_netconsole_target() were duplicating the same allocation and init logic. Factor it out to alloc_netconsole_target(). This is pure reorganization. Signed-off-by: Tejun Heo Cc: David Miller --- drivers/net/netconsole.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 09d4e12..17692b8 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -167,19 +167,17 @@ static void netconsole_target_put(struct netconsole_target *nt) #endif /* CONFIG_NETCONSOLE_DYNAMIC */ -/* Allocate new target (from boot/module param) and setup netpoll for it */ -static struct netconsole_target *alloc_param_target(char *target_config) +/* + * Allocate and initialize with defaults. Note that these targets get + * their config_item fields zeroed-out. + */ +static struct netconsole_target *alloc_netconsole_target(void) { - int err = -ENOMEM; struct netconsole_target *nt; - /* - * Allocate and initialize with defaults. - * Note that these targets get their config_item fields zeroed-out. - */ nt = kzalloc(sizeof(*nt), GFP_KERNEL); if (!nt) - goto fail; + return NULL; nt->np.name = "netconsole"; strlcpy(nt->np.dev_name, "eth0", IFNAMSIZ); @@ -188,6 +186,19 @@ static struct netconsole_target *alloc_param_target(char *target_config) mutex_init(&nt->mutex); eth_broadcast_addr(nt->np.remote_mac); + return nt; +} + +/* Allocate new target (from boot/module param) and setup netpoll for it */ +static struct netconsole_target *alloc_param_target(char *target_config) +{ + int err = -ENOMEM; + struct netconsole_target *nt; + + nt = alloc_netconsole_target(); + if (!nt) + goto fail; + /* Parse parameters and setup netpoll */ err = netpoll_parse_options(&nt->np, target_config); if (err) @@ -592,21 +603,10 @@ static struct config_item *make_netconsole_target(struct config_group *group, unsigned long flags; struct netconsole_target *nt; - /* - * Allocate and initialize with defaults. - * Target is disabled at creation (!enabled). - */ - nt = kzalloc(sizeof(*nt), GFP_KERNEL); + nt = alloc_netconsole_target(); if (!nt) return ERR_PTR(-ENOMEM); - nt->np.name = "netconsole"; - strlcpy(nt->np.dev_name, "eth0", IFNAMSIZ); - nt->np.local_port = 6665; - nt->np.remote_port = 6666; - mutex_init(&nt->mutex); - eth_broadcast_addr(nt->np.remote_mac); - /* Initialize the config_item member */ config_item_init_type_name(&nt->item, name, &netconsole_target_type);