From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965777AbdIZGZZ (ORCPT ); Tue, 26 Sep 2017 02:25:25 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:36614 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965122AbdIZGZY (ORCPT ); Tue, 26 Sep 2017 02:25:24 -0400 X-Google-Smtp-Source: AOwi7QDQ+N0wNS+RpswFn4YXG8seO67Qix6hPh3VH9EPhBL7J3RCFh/eA1j2UQfjKzZ2Sf80FoIKww== From: Sergey Senozhatsky X-Google-Original-From: Sergey Senozhatsky To: Rob Herring Cc: Petr Mladek , Steven Rostedt , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCH] of: do not leak console options Date: Tue, 26 Sep 2017 15:25:10 +0900 Message-Id: <20170926062510.4948-1-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.14.1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Do not strdup() console options. It seems that the only reason for it to be strdup()-ed was a compilation warning: printk, UART and console drivers, for some reason, expect char pointer instead of const char pointer. So we can just pass `of_stdout_options', but need to cast it to char pointer. A better fix would be to change printk, console drivers and UART to accept const char `options'; but that will take time - there are lots of drivers to update. The patch also fixes a possible memory leak: add_preferred_console() can fail, but we don't kfree() options. Signed-off-by: Sergey Senozhatsky --- drivers/of/base.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/of/base.c b/drivers/of/base.c index 260d33c0f26c..63897531cd75 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -1781,8 +1781,12 @@ bool of_console_check(struct device_node *dn, char *name, int index) { if (!dn || dn != of_stdout || console_set_on_cmdline) return false; - return !add_preferred_console(name, index, - kstrdup(of_stdout_options, GFP_KERNEL)); + + /* + * XXX: cast `options' to char pointer to suppress complication + * warnings: printk, UART and console drivers expect char pointer. + */ + return !add_preferred_console(name, index, (char *)of_stdout_options); } EXPORT_SYMBOL_GPL(of_console_check); -- 2.14.1