From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2AF1CC4363A for ; Wed, 21 Oct 2020 23:07:46 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8993922248 for ; Wed, 21 Oct 2020 23:07:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="acEch0rd" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8993922248 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B74976EEB3; Wed, 21 Oct 2020 23:07:44 +0000 (UTC) Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4E4996EEB2 for ; Wed, 21 Oct 2020 23:07:43 +0000 (UTC) Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0238252F; Thu, 22 Oct 2020 01:07:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1603321660; bh=+WdOvFjpRjvrv6B+F7afibmUjbgU1KtzOI9H01Uwlcw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=acEch0rd/KOHPm5hzTCGdtnqcfSg5H5g0n+0pUmWx9fPM1g8djEdE+T2GBaTT/W+P cD4tpGfAvoas/GDRnbZvtEXpi3wKkA1cH68xJxn6pBQBzTJK2o4NPRSY5pVn6nGoY1 FGo7zsVLpgQCCPW/k9MvvpiZENbB9+Lv0jmekNCI= Date: Thu, 22 Oct 2020 02:06:54 +0300 From: Laurent Pinchart To: Thomas Zimmermann Subject: Re: [PATCH] drivers/video: Fix -Wstringop-truncation in hdmi.c Message-ID: <20201021230654.GS3942@pendragon.ideasonboard.com> References: <20201021121241.17623-1-tzimmermann@suse.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20201021121241.17623-1-tzimmermann@suse.de> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-fbdev@vger.kernel.org, b.zolnierkie@samsung.com, bernard@vivo.com, dri-devel@lists.freedesktop.org, gwan-gyeong.mun@intel.com, daniel.vetter@ffwll.ch, sam@ravnborg.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Hi Thomas, Thank you for the patch. On Wed, Oct 21, 2020 at 02:12:41PM +0200, Thomas Zimmermann wrote: > Trying to copy into the string fields with strncpy() gives a warning from > gcc. Both fields are part of a packed HDMI header and do not require a > terminating \0 character. > > ../drivers/video/hdmi.c: In function 'hdmi_spd_infoframe_init': > ../drivers/video/hdmi.c:230:2: warning: 'strncpy' specified bound 8 equals destination size [-Wstringop-truncation] > 230 | strncpy(frame->vendor, vendor, sizeof(frame->vendor)); > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > ../drivers/video/hdmi.c:231:2: warning: 'strncpy' specified bound 16 equals destination size [-Wstringop-truncation] > 231 | strncpy(frame->product, product, sizeof(frame->product)); > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > Just use memcpy() instead. > > Signed-off-by: Thomas Zimmermann > --- > drivers/video/hdmi.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/drivers/video/hdmi.c b/drivers/video/hdmi.c > index b7a1d6fae90d..1e4cb63d0d11 100644 > --- a/drivers/video/hdmi.c > +++ b/drivers/video/hdmi.c > @@ -221,14 +221,18 @@ EXPORT_SYMBOL(hdmi_avi_infoframe_pack); > int hdmi_spd_infoframe_init(struct hdmi_spd_infoframe *frame, > const char *vendor, const char *product) > { > + size_t len; > + > memset(frame, 0, sizeof(*frame)); > > frame->type = HDMI_INFOFRAME_TYPE_SPD; > frame->version = 1; > frame->length = HDMI_SPD_INFOFRAME_SIZE; > > - strncpy(frame->vendor, vendor, sizeof(frame->vendor)); > - strncpy(frame->product, product, sizeof(frame->product)); > + len = strlen(vendor); > + memcpy(frame->vendor, vendor, min(len, sizeof(frame->vendor))); > + len = strlen(product); > + memcpy(frame->product, product, min(len, sizeof(frame->product))); As this seems to be a legitimate use of strncpy(), isn't there a way to silence the warning without requiring this additional runtime complexity ? > > return 0; > } -- Regards, Laurent Pinchart _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel