From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 66A81A0032; Wed, 11 May 2022 16:04:44 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5038B410F2; Wed, 11 May 2022 16:04:44 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 1FA3B406B4 for ; Wed, 11 May 2022 16:04:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652277881; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Fbk6uqx3k1KPbHl42yuMbS9WA5K5ufxCOAxEsVhET08=; b=ciWIWrVSRXb0OOWyL7j3CsH+BVPc8RyeQyo61NfycJs0cVQIagWHXKL8g+jRz0+KeGJyKJ QAqNw1BpQ7TjszYQ89zujjOmDFjfLpG1AwcCKZ6NmSMwRtKLVZOCHwZylD6wpi1yU01Ji8 sTz6J6uaeBdsR4HRbL60FbJyoNIxF7U= Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com [209.85.167.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-156-VWsKHFnBNgO8Au3Up9hlxw-1; Wed, 11 May 2022 10:04:40 -0400 X-MC-Unique: VWsKHFnBNgO8Au3Up9hlxw-1 Received: by mail-lf1-f69.google.com with SMTP id l19-20020ac24313000000b004739dbba717so858184lfh.5 for ; Wed, 11 May 2022 07:04:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Fbk6uqx3k1KPbHl42yuMbS9WA5K5ufxCOAxEsVhET08=; b=ClGYdlUGkF1C8tjWz/aIYnAvjpp4g0dOLmhqpwiP+DBwMOPAuTNYDTmyCzUxk9DXpB Aw13/mCAxX+4uT2VW8OmhZawPXuAPGu1w4ZJdsDzza/PprBbb6WXvqE1O0zZldgcIEaF NPgCtxuitLYloL3R5R+t4+fuzOM7NDKqEFITXaNGtOj/R7n2WOVqKoSCQKi/gf5uPBvh mTAOyOqifeh5U3uCEKs03dRbIC/sM4whRWUfMTSNFZ9MJdnA8A2JYsBqy5Fb2ld6kIEF fQZle8ATqmndp2hf//Ld5WlEMOwNyRpQuY8JH0vF070m2+RN9SFkAOIMJuGjqO5wPE9d JWWw== X-Gm-Message-State: AOAM5315EKX0Q46Mz9Wgasx8bmCS/C7c95SjBfnMK0PJbV4xFekICH2T JEa0VAV40aZ1xbhs82kgMNq7jubD5XGdtPdj47uG0P7lT6soyE4SNS/7PVWZzZHz62kCX52H4MF 0YtT3XS67/lg6Sqo+4fY= X-Received: by 2002:a05:6512:3f8c:b0:45d:cb2a:8779 with SMTP id x12-20020a0565123f8c00b0045dcb2a8779mr21074233lfa.499.1652277878397; Wed, 11 May 2022 07:04:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw8ZMguDIsMEJji0YQW05vBWLvQOcjfvDukQn7D/K5vymGv2LuVfWP5ksgpZ2qvwypwYupBb748mnKvPm4xnyE= X-Received: by 2002:a05:6512:3f8c:b0:45d:cb2a:8779 with SMTP id x12-20020a0565123f8c00b0045dcb2a8779mr21074214lfa.499.1652277878168; Wed, 11 May 2022 07:04:38 -0700 (PDT) MIME-Version: 1.0 References: <20220511135815.1564053-1-alialnu@nvidia.com> In-Reply-To: <20220511135815.1564053-1-alialnu@nvidia.com> From: David Marchand Date: Wed, 11 May 2022 16:04:26 +0200 Message-ID: Subject: Re: [PATCH] net/mlx5: fix build with clang 14 To: Ali Alnubani Cc: dev , michaelba@mellanox.com, dpdk stable Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dmarchan@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On Wed, May 11, 2022 at 3:59 PM Ali Alnubani wrote: > > Use fgets instead of fscanf to resolve the following warning > reported by clang 14.0.0 in Fedora 37 (Rawhide): > > drivers/net/mlx5/linux/mlx5_ethdev_os.c:1137:52: error: > 'fscanf' may overflow; destination buffer in argument 3 has size 16, > but the corresponding specifier may require size 17 > [-Werror,-Wfortify-source] > ret = fscanf(file, "%" RTE_STR(IF_NAMESIZE) "s", port_name); > > Fixes: 63d1db710fbc ("net/mlx5: fix unlimited parsing of switch info") > Cc: michaelba@mellanox.com > Cc: stable@dpdk.org > > Signed-off-by: Ali Alnubani > --- > drivers/net/mlx5/linux/mlx5_ethdev_os.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/drivers/net/mlx5/linux/mlx5_ethdev_os.c b/drivers/net/mlx5/linux/mlx5_ethdev_os.c > index 8fe73f1adb..3d28597e7b 100644 > --- a/drivers/net/mlx5/linux/mlx5_ethdev_os.c > +++ b/drivers/net/mlx5/linux/mlx5_ethdev_os.c > @@ -1118,7 +1118,7 @@ mlx5_sysfs_switch_info(unsigned int ifindex, struct mlx5_switch_info *info) > bool port_switch_id_set = false; > bool device_dir = false; > char c; > - int ret; > + char *ret; > > if (!if_indextoname(ifindex, ifname)) { > rte_errno = errno; > @@ -1134,9 +1134,9 @@ mlx5_sysfs_switch_info(unsigned int ifindex, struct mlx5_switch_info *info) > > file = fopen(phys_port_name, "rb"); > if (file != NULL) { > - ret = fscanf(file, "%" RTE_STR(IF_NAMESIZE) "s", port_name); > + ret = fgets(port_name, IF_NAMESIZE, file); > fclose(file); > - if (ret == 1) > + if (ret != NULL) > mlx5_translate_port_name(port_name, &data); You can directly check fgets return value and remove (misleading) variable ret from the global scope of this function. > } > file = fopen(phys_switch_id, "rb"); -- David Marchand