Message ID | 202211241926133236370@zte.com.cn |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3337688wrr; Thu, 24 Nov 2022 03:29:37 -0800 (PST) X-Google-Smtp-Source: AA0mqf5fFHhGxuuF734TG5+WHV0io1sFCmxyLjJ8iJSMHsGPUXIZXHZkwDcY42h92HkNGga289pS X-Received: by 2002:aa7:d998:0:b0:463:a4a7:d3f1 with SMTP id u24-20020aa7d998000000b00463a4a7d3f1mr21574253eds.299.1669289376834; Thu, 24 Nov 2022 03:29:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669289376; cv=none; d=google.com; s=arc-20160816; b=k4qLB6YEw/IWSUx/4E2qWOJK3/9Evt3sx86bXjUc20ukJfaA8gAPzTOeRiuXbGXRe5 dB4giB6rOTeYxV8er3mLWBhuXrbiqPYxI3PCI/U/GHq6RyQcu0qHNHRgCi0gH/UKZVOz eIH2Yb/DF0U5lLiu1YP30iWDIY602YXnY2k9QTixvX0/JpmUSFhtO/yRyd6HFbWi3FJM sESr9x/lKRDw4FSXvCrv5t91wL5dNVdm1pFyVFoq2KDa2kxUC3RUtpI4H/xSj17Xpniw 8IuTvWTB6/DpzcDAiJfEeqiiNqtDxlD5poHFsO5f13qejkg16vtAh3Ib1nBvrmj21IxM QgIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:mime-version:message-id:date; bh=uPpZWUmxYRjglAtuqHSqyHZ5mn0molDa0iLYcLNF470=; b=st34f74cAAiC3ObvRLIEVPLQ9F0QiYqRZrHonluku9fp3VQqaNd+x2FAB/kfwoo9gt W+6BNAfhFZUG/lvd2WYKzo0HwGy6ToLqOO/dBcVKxudgOq+0o0wo24ULbSm6D5qBWGC2 Vlg2xHhxvPLGvI9PNav0mSnZK7wYLntiIwrmGLQ/gq55ixr4ZSJhC9rWwnO3T88S3BCZ hoOM6ScWUbTbkg4Lc07RrpQiE83tO7EJ867YbRM4IQYsbhzW2/61XIp5codqDstOTDMi BHwAySrj5SGmUQNPSqckln8hAS5BdsXDvftTnK4mGMHDAATlSHOuK+mQ7v8fTm8pFE7E RT2g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=zte.com.cn Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id di13-20020a170906730d00b00782e437a368si793924ejc.160.2022.11.24.03.29.13; Thu, 24 Nov 2022 03:29:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=zte.com.cn Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229662AbiKXL0V (ORCPT <rfc822;fengqi706@gmail.com> + 99 others); Thu, 24 Nov 2022 06:26:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229459AbiKXL0U (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 24 Nov 2022 06:26:20 -0500 Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [63.216.63.35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0AB9B2529C; Thu, 24 Nov 2022 03:26:19 -0800 (PST) Received: from mse-fl2.zte.com.cn (unknown [10.5.228.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mxhk.zte.com.cn (FangMail) with ESMTPS id 4NHwfx2tNGz5BNRf; Thu, 24 Nov 2022 19:26:17 +0800 (CST) Received: from szxlzmapp04.zte.com.cn ([10.5.231.166]) by mse-fl2.zte.com.cn with SMTP id 2AOBQAQp098428; Thu, 24 Nov 2022 19:26:10 +0800 (+08) (envelope-from yang.yang29@zte.com.cn) Received: from mapi (szxlzmapp02[null]) by mapi (Zmail) with MAPI id mid14; Thu, 24 Nov 2022 19:26:13 +0800 (CST) Date: Thu, 24 Nov 2022 19:26:13 +0800 (CST) X-Zmail-TransId: 2b04637f54d5ffffffffd03e764f X-Mailer: Zmail v1.0 Message-ID: <202211241926133236370@zte.com.cn> Mime-Version: 1.0 From: <yang.yang29@zte.com.cn> To: <sumit.semwal@linaro.org> Cc: <christian.koenig@amd.com>, <linux-media@vger.kernel.org>, <dri-devel@lists.freedesktop.org>, <linaro-mm-sig@lists.linaro.org>, <linux-kernel@vger.kernel.org>, <xu.panda@zte.com.cn>, <yang.yang29@zte.com.cn> Subject: =?utf-8?q?=5BPATCH_linux-next=5D_dma-buf=3A_use_strscpy=28=29_to_in?= =?utf-8?q?stead_of_strlcpy=28=29?= Content-Type: text/plain; charset="UTF-8" X-MAIL: mse-fl2.zte.com.cn 2AOBQAQp098428 X-Fangmail-Gw-Spam-Type: 0 X-FangMail-Miltered: at cgslv5.04-192.168.250.138.novalocal with ID 637F54D9.000 by FangMail milter! X-FangMail-Envelope: 1669289177/4NHwfx2tNGz5BNRf/637F54D9.000/10.5.228.133/[10.5.228.133]/mse-fl2.zte.com.cn/<yang.yang29@zte.com.cn> X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 637F54D9.000/4NHwfx2tNGz5BNRf X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750376777655276613?= X-GMAIL-MSGID: =?utf-8?q?1750376777655276613?= |
Series |
[linux-next] dma-buf: use strscpy() to instead of strlcpy()
|
|
Commit Message
Yang Yang
Nov. 24, 2022, 11:26 a.m. UTC
From: Xu Panda <xu.panda@zte.com.cn> The implementation of strscpy() is more robust and safer. That's now the recommended way to copy NUL terminated strings. Signed-off-by: Xu Panda <xu.panda@zte.com.cn> Signed-off-by: Yang Yang <yang.yang29@zte.com> --- drivers/dma-buf/dma-buf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Thu, Nov 24, 2022 at 3:26 AM <yang.yang29@zte.com.cn> wrote: > > From: Xu Panda <xu.panda@zte.com.cn> > > The implementation of strscpy() is more robust and safer. > That's now the recommended way to copy NUL terminated strings. > > Signed-off-by: Xu Panda <xu.panda@zte.com.cn> > Signed-off-by: Yang Yang <yang.yang29@zte.com> > --- > drivers/dma-buf/dma-buf.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c > index b6c36914e7c6..485cf4f3431e 100644 > --- a/drivers/dma-buf/dma-buf.c > +++ b/drivers/dma-buf/dma-buf.c > @@ -51,7 +51,7 @@ static char *dmabuffs_dname(struct dentry *dentry, char *buffer, int buflen) > dmabuf = dentry->d_fsdata; > spin_lock(&dmabuf->name_lock); > if (dmabuf->name) > - ret = strlcpy(name, dmabuf->name, DMA_BUF_NAME_LEN); > + ret = strscpy(name, dmabuf->name, DMA_BUF_NAME_LEN); The type of ret should also be changed to ssize_t to capture the negative error value which strlcpy does not have. We shouldn't ever see that error condition here with the code the way it is now, but let's not risk it. > spin_unlock(&dmabuf->name_lock); > > return dynamic_dname(buffer, buflen, "/%s:%s", > -- > 2.15.2
diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index b6c36914e7c6..485cf4f3431e 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -51,7 +51,7 @@ static char *dmabuffs_dname(struct dentry *dentry, char *buffer, int buflen) dmabuf = dentry->d_fsdata; spin_lock(&dmabuf->name_lock); if (dmabuf->name) - ret = strlcpy(name, dmabuf->name, DMA_BUF_NAME_LEN); + ret = strscpy(name, dmabuf->name, DMA_BUF_NAME_LEN); spin_unlock(&dmabuf->name_lock); return dynamic_dname(buffer, buflen, "/%s:%s",