From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753895AbcGDUSX (ORCPT ); Mon, 4 Jul 2016 16:18:23 -0400 Received: from mail-vk0-f47.google.com ([209.85.213.47]:33821 "EHLO mail-vk0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753830AbcGDUSU (ORCPT ); Mon, 4 Jul 2016 16:18:20 -0400 MIME-Version: 1.0 In-Reply-To: <8737nt83sc.fsf@rasmusvillemoes.dk> References: <1467330612-26242-1-git-send-email-mmayer@broadcom.com> <1467330612-26242-2-git-send-email-mmayer@broadcom.com> <8737nt83sc.fsf@rasmusvillemoes.dk> From: Markus Mayer Date: Mon, 4 Jul 2016 13:18:18 -0700 Message-ID: Subject: Re: [PATCH 1/6] lib: string: add function strtolower() To: Rasmus Villemoes Cc: Andrew Morton , Al Viro , Chris Metcalf , Kees Cook , dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-acpi@vger.kernel.org, devel@acpica.org, speakup@linux-speakup.org, devel@driverdev.osuosl.org, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, Linux Kernel Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1 July 2016 at 14:08, Rasmus Villemoes wrote: > A few suggestions: > > - Make the function take separate src and dst parameters, making it explicitly > allowed to pass the same value (but not other kinds of overlap, of > course). That way one can avoid "strcpy(dst, src); strtolower(dst);". > > - Drop the NULL check. If someone does "foo->bar = something; > strtolower(foo->bar); put foo in a global data structure...", the > dereference of foo->bar may happen much later. Doing the NULL deref > sooner means it's much easier to find and fix the bug. (Also, other > str* and mem* functions don't usually check for NULL). > > - While it's true that strcpy and memcpy by definition return dst, that's > mostly useless. If you want it to return anything, please make it > something that might be used - for example, having stpcpy semantics > (returning a pointer to dst's terminating \0) means a caller might avoid > a strlen call. > > - Maybe do strtoupper while you're at it. Quick grepping didn't find any > use for the copy-while-lowercasing, but copy-while-uppercasing can at > least be used in drivers/acpi/acpica/nsrepair2.c, > drivers/gpu/drm/nouveau/nvkm/engine/fifo/gk104.c, > drivers/power/power_supply_sysfs.c along with a bunch of inplace > uppercasing. > > > Rasmus Thanks for the suggestions to you and Jani. Based on the feedback I received, I am reworking the series now and will post v2 probably tomorrow. Regards, -Markus