Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1498762pxk; Fri, 4 Sep 2020 10:50:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/Qc97wwCGH4Hb+dBGgVv40GoZS6dCDFaPxDF31htmcv64KsuC8pfmPjoFXn2qYl20Q0Np X-Received: by 2002:a17:906:957:: with SMTP id j23mr8607967ejd.344.1599241845685; Fri, 04 Sep 2020 10:50:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599241845; cv=none; d=google.com; s=arc-20160816; b=tQdEwauH75q07vBgAqxFce6B1htQwDfvtxenaGJxcF7xtCkK7k2cv+NDQN4TJPF9MT LZspZuTofY3csMmS8t+BRHktN7SZc+cl8HcZpCWGLlVvUXeksbSCmx+GdKaTX+mAIasJ IpwNMK1K6C1L1CoDg+dPrv83ehtWzD3Et6ZgIr285XBUdUBSkVUIItvA2do5gmm+kecs db78AdNZHOu910MsjITMKees8by2buyf+dTvX2ticoluP+c4RvucHnrs3HajlC6+h68g dzfwxvveSXx7FkVUd4tUqOhnFuSbQMoy1A9vGUzAthO3rIfIuJYkhrInZreMaBYgdoYb 6ycA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:organization:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:ironport-sdr:ironport-sdr; bh=DKY4NqwA5rMOrL22KulAe1umXV6KNHnjogZgvMeBiTY=; b=aedDGA7v8qUWIP+P4RSJKVZz3cVVfwstl1Tr9PxK8EDH3mNtESk0m9woKbKAcrw8+1 aYqTwt6/DUlsHsbJqkLMRqNnIHArsWJvMXdVoyaZOGqATtIJqqtdMRJ4q8Weeeo7/P3p YOJGyXfEwi/WP7wlI4BNOdVhgvN/rbciOXAy+vwfdcBGQDMhLMLRtaADi+qUOfVGoHGw Pv6fZoYPNeIwqIL6cym9TCGTwFiEfXhFBhlarUV6BFxSbIF1f5wgV3WoNzkNkNay6FDg DIu4T/WwJmQOmoo91FpmqXh8wAaLy/xNBzIux0gxud34xcTj3ojUmt7Tia3mciEpZe7C W4ZA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j6si4356914ejk.734.2020.09.04.10.50.20; Fri, 04 Sep 2020 10:50:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726265AbgIDQf2 (ORCPT + 99 others); Fri, 4 Sep 2020 12:35:28 -0400 Received: from mga12.intel.com ([192.55.52.136]:22282 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726047AbgIDQfZ (ORCPT ); Fri, 4 Sep 2020 12:35:25 -0400 IronPort-SDR: N7G1NMA1vwgQZOyxy79IzchW1pPfH7PkEXNqYvcXOf+4iQvVX/gX2IOO38Od/e6Sd2bhLHM/BU afh1yvK+7vCQ== X-IronPort-AV: E=McAfee;i="6000,8403,9734"; a="137300774" X-IronPort-AV: E=Sophos;i="5.76,390,1592895600"; d="scan'208";a="137300774" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Sep 2020 09:35:22 -0700 IronPort-SDR: /dqQJqsIa/VFbqalbeB6jnnHq/h+KBnDMOXQYnSozk9jvYwAZbYayzsGNojeOYVl2FHGANE9zP QJyMI8K2AIJQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,390,1592895600"; d="scan'208";a="332215807" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by orsmga008.jf.intel.com with ESMTP; 04 Sep 2020 09:35:19 -0700 Received: from andy by smile with local (Exim 4.94) (envelope-from ) id 1kEEgH-00EKJ1-4s; Fri, 04 Sep 2020 19:35:17 +0300 Date: Fri, 4 Sep 2020 19:35:17 +0300 From: Andy Shevchenko To: Bartosz Golaszewski Cc: Linus Walleij , Jonathan Corbet , Mika Westerberg , Kent Gibson , linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: Re: [PATCH 03/23] lib: uaccess: provide getline_from_user() Message-ID: <20200904163517.GW1891694@smile.fi.intel.com> References: <20200904154547.3836-1-brgl@bgdev.pl> <20200904154547.3836-4-brgl@bgdev.pl> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200904154547.3836-4-brgl@bgdev.pl> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 04, 2020 at 05:45:27PM +0200, Bartosz Golaszewski wrote: > From: Bartosz Golaszewski > > Provide a uaccess helper that allows callers to copy a single line from > user memory. This is useful for debugfs write callbacks. Doesn't mm/util.c provides us something like this? strndup_user()? > > Signed-off-by: Bartosz Golaszewski > --- > include/linux/uaccess.h | 3 +++ > lib/usercopy.c | 37 +++++++++++++++++++++++++++++++++++++ > 2 files changed, 40 insertions(+) > > diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h > index 94b285411659..5aedd8ac5c31 100644 > --- a/include/linux/uaccess.h > +++ b/include/linux/uaccess.h > @@ -333,6 +333,9 @@ long strncpy_from_user_nofault(char *dst, const void __user *unsafe_addr, > long count); > long strnlen_user_nofault(const void __user *unsafe_addr, long count); > > +ssize_t getline_from_user(char *dst, size_t dst_size, > + const char __user *src, size_t src_size); > + > /** > * get_kernel_nofault(): safely attempt to read from a location > * @val: read into this variable > diff --git a/lib/usercopy.c b/lib/usercopy.c > index b26509f112f9..55aaaf93d847 100644 > --- a/lib/usercopy.c > +++ b/lib/usercopy.c > @@ -87,3 +87,40 @@ int check_zeroed_user(const void __user *from, size_t size) > return -EFAULT; > } > EXPORT_SYMBOL(check_zeroed_user); > + > +/** > + * getline_from_user - Copy a single line from user > + * @dst: Where to copy the line to > + * @dst_size: Size of the destination buffer > + * @src: Where to copy the line from > + * @src_size: Size of the source user buffer > + * > + * Copies a number of characters from given user buffer into the dst buffer. > + * The number of bytes is limited to the lesser of the sizes of both buffers. > + * If the copied string contains a newline, its first occurrence is replaced > + * by a NULL byte in the destination buffer. Otherwise the function ensures > + * the copied string is NULL-terminated. > + * > + * Returns the number of copied bytes or a negative error number on failure. > + */ > + > +ssize_t getline_from_user(char *dst, size_t dst_size, > + const char __user *src, size_t src_size) > +{ > + size_t size = min_t(size_t, dst_size, src_size); > + char *c; > + int ret; > + > + ret = copy_from_user(dst, src, size); > + if (ret) > + return -EFAULT; > + > + dst[size - 1] = '\0'; > + > + c = strchrnul(dst, '\n'); > + if (*c) > + *c = '\0'; > + > + return c - dst; > +} > +EXPORT_SYMBOL(getline_from_user); > -- > 2.26.1 > -- With Best Regards, Andy Shevchenko