From patchwork Fri Jul 27 07:33:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 10546711 X-Patchwork-Delegate: eduardo.valentin@ti.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8BD29180E for ; Fri, 27 Jul 2018 07:34:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 79DE62B367 for ; Fri, 27 Jul 2018 07:34:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6E1F52B383; Fri, 27 Jul 2018 07:34:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 007BD2B367 for ; Fri, 27 Jul 2018 07:34:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729445AbeG0Iyq (ORCPT ); Fri, 27 Jul 2018 04:54:46 -0400 Received: from mail.bootlin.com ([62.4.15.54]:55106 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729420AbeG0Iyq (ORCPT ); Fri, 27 Jul 2018 04:54:46 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id BE84A208FF; Fri, 27 Jul 2018 09:34:08 +0200 (CEST) Received: from localhost.localdomain (AAubervilliers-681-1-89-120.w90-88.abo.wanadoo.fr [90.88.30.120]) by mail.bootlin.com (Postfix) with ESMTPSA id 845EA206F6; Fri, 27 Jul 2018 09:33:58 +0200 (CEST) From: Miquel Raynal To: Eduardo Valentin , Zhang Rui , linux-pm@vger.kernel.org Cc: Thomas Petazzoni , Gregory Clement , Nadav Haklai , Miquel Raynal Subject: [PATCH] thermal: armada: fix strncpy use Date: Fri, 27 Jul 2018 09:33:53 +0200 Message-Id: <20180727073353.25012-1-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.14.1 MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Fix the following warning raised by the kbuild test robot infrastructure: In function 'armada_set_sane_name', inlined from 'armada_thermal_probe' at drivers/thermal/armada_thermal.c:416:2: >> drivers/thermal/armada_thermal.c:377:2: warning: 'strncpy' specified bound 20 equals destination size [-Wstringop-truncation] strncpy(priv->zone_name, name, THERMAL_NAME_LENGTH); Reduce the copy length by 1 to avoid this error and ensure the string is null terminated manually as suggested in the strncpy man page. Signed-off-by: Miquel Raynal --- Hello Eduardo, Sorry for messing with strncpy. If you want, you may squash this patch with: "thermal: armada: add a function that sanitizes the thermal zone name" It should solve the above issue. Cheers, Miquèl drivers/thermal/armada_thermal.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/armada_thermal.c b/drivers/thermal/armada_thermal.c index e493fe33bffb..b5b01cf9b061 100644 --- a/drivers/thermal/armada_thermal.c +++ b/drivers/thermal/armada_thermal.c @@ -777,7 +777,8 @@ static void armada_set_sane_name(struct platform_device *pdev, } /* Save the name locally */ - strncpy(priv->zone_name, name, THERMAL_NAME_LENGTH); + strncpy(priv->zone_name, name, THERMAL_NAME_LENGTH - 1); + priv->zone_name[THERMAL_NAME_LENGTH - 1] = '\0'; /* Then check there are no '-' or hwmon core will complain */ do {