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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49094C4321E for ; Mon, 4 Apr 2022 10:15:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350670AbiDDKR1 (ORCPT ); Mon, 4 Apr 2022 06:17:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243260AbiDDKRY (ORCPT ); Mon, 4 Apr 2022 06:17:24 -0400 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30D532F38A; Mon, 4 Apr 2022 03:15:28 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id w18so4175901edi.13; Mon, 04 Apr 2022 03:15:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=s/rlqtfSH/+OKtlWbKj/8X8QmPBtgrwTTfh5H/AMmr8=; b=M6UB/xq5U2lez0akpMy5cdYkLpWp5TY7avZOr9EOmD3mOmC7LnKWizhrsWVbS9OYXV WxZR1L3Zip6LzxkB/OPBaxvuvHRQ+I4ccmh7WVg7layXLF9PfwqQYZ+jlB6EvWgmb6tq 0lZWCE3uc7LImkbQu2mlfWDe2OdVL/M2gk8b/f83Msuz2BzcI+DWU/n4c03LXmBik2KW KbNMC8korkh/nF0C0QAzLDf4TOGpyF8a6IoEG8l74xBIia5wiIab+cBhjD/6K3P9R06b EK2dkk2s3pESu8s3Lp5ePedMQzZPflgxpC1RgXqt3TXscJmh/VeMBZJdhbyeZhLuCe4J VwFg== 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=s/rlqtfSH/+OKtlWbKj/8X8QmPBtgrwTTfh5H/AMmr8=; b=kiRMLuFauMnZZ01SYxJ9sfWlLOwmSagcfxoeWjN5ZuDR+SXbbsRmp/TYxTXxOkVIn5 Iqhrq8yPTGr+c2dINM2OCjxzfw2xv2EqP0qcIvgiQbXB6CFhupchg7qJS+X0SFW0zi0h 10z9rSVGKRM9PyU3/WzwV9S1SorXyBZk8owEoeBF5BvRSX1912zRUBp6h+W2B9/APwbd D1VBLhGr5Lmpbys4MmvMixIj6/oTkawSZx47oYwBvU0AZnh+RMVs6q3g7ZTZ8tokMIJK hXhlcVtD46KCz33aG8ELnbIxXeAfJDYCvDprSuF631kzWu5eMu3BoFQGf+rak9l67Sv2 LsgA== X-Gm-Message-State: AOAM532mDF0NxFmVYKAjRun0f+rN1TnS8jOMGtuOqGm86aGKsg3CL7QC fBKuXcMCzsvwMkB1Y5qiH18eomqf3gUkvgfkSAFiJObyoq8= X-Google-Smtp-Source: ABdhPJxh9T+A1Yt+ILwhaxqoZIRZw7XK7bOr8aWn5QI6DqXoAfRnxar+91mJpxHWbEEB8aKP53yR05gviFAyUrKxBls= X-Received: by 2002:a05:6402:b19:b0:41c:d713:5cba with SMTP id bm25-20020a0564020b1900b0041cd7135cbamr2668518edb.270.1649067326747; Mon, 04 Apr 2022 03:15:26 -0700 (PDT) MIME-Version: 1.0 References: <20220403183758.192236-1-krzysztof.kozlowski@linaro.org> <20220403183758.192236-2-krzysztof.kozlowski@linaro.org> <2976f4f9-4fda-c04f-45cf-351518f88ec0@linaro.org> In-Reply-To: <2976f4f9-4fda-c04f-45cf-351518f88ec0@linaro.org> From: Andy Shevchenko Date: Mon, 4 Apr 2022 13:14:22 +0300 Message-ID: Subject: Re: [PATCH v6 01/12] driver: platform: Add helper for safer setting of driver_override To: Krzysztof Kozlowski Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" , Stuart Yoder , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , Dexuan Cui , Bjorn Helgaas , Bjorn Andersson , Mathieu Poirier , Vineeth Vijayan , Peter Oberparleiter , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Andy Gross , Linux Kernel Mailing List , linux-clk , NXP Linux Team , linux-arm Mailing List , Linux on Hyper-V List , linux-pci , linux-remoteproc@vger.kernel.org, linux-s390@vger.kernel.org, linux-arm-msm@vger.kernel.org, ALSA Development Mailing List , linux-spi , virtualization@lists.linux-foundation.org, Linus Torvalds , Rasmus Villemoes Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org On Mon, Apr 4, 2022 at 12:34 PM Krzysztof Kozlowski wrote: > On 04/04/2022 11:16, Andy Shevchenko wrote: > > On Sun, Apr 3, 2022 at 9:38 PM Krzysztof Kozlowski > > wrote: ... > >> +int driver_set_override(struct device *dev, const char **override, > >> + const char *s, size_t len) > >> +{ > >> + const char *new, *old; > >> + char *cp; > > > >> + if (!override || !s) > >> + return -EINVAL; > > > > Still not sure if we should distinguish (s == NULL && len == 0) from > > (s != NULL && len == 0). > > Supplying the latter seems confusing (yes, I see that in the old code). Perhaps > > !s test, in case you want to leave it, should be also commented. > > The old semantics were focused on sysfs usage, so clearing is by passing > an empty string. In the case of sysfs empty string is actually "\n". I > intend to keep the semantics also for the in-kernel usage and in such > case empty string can be also "". > > If I understand your comment correctly, you propose to change it to NULL > for in-kernel usage, but that would change the semantics. Yes. It's also possible to have a wrapper for sysfs use. > > Another approach is to split above to two checks and move !s after !len. > > I don't follow why... The !override and !s are invalid uses. !len is a > valid user for internal callers, just like "\n" is for sysfs. I understand but always supplying s maybe an overhead for in-kernel usages. In any case, it's not critical right now, just a remark that it can be modified. > >> + /* > >> + * The stored value will be used in sysfs show callback (sysfs_emit()), > >> + * which has a length limit of PAGE_SIZE and adds a trailing newline. > >> + * Thus we can store one character less to avoid truncation during sysfs > >> + * show. > >> + */ > >> + if (len >= (PAGE_SIZE - 1)) > >> + return -EINVAL; > > > > Perhaps explain the case in the comment here? > > You mean the case we discuss here (to clear override with "")? Sure. Yep. Before the below check. > >> + if (!len) { > >> + device_lock(dev); > >> + old = *override; > >> + *override = NULL; > > > >> + device_unlock(dev); > >> + goto out_free; > > > > You may deduplicate this one, by > > > > goto out_unlock_free; > > > > But I understand your intention to keep lock-unlock in one place, so > > perhaps dropping that label would be even better in this case and > > keeping it > > Yes, exactly. > > > kfree(old); > > return 0; > > > > here instead of goto. > > Slightly more code, but indeed maybe easier to follow. I'll do like this. -- With Best Regards, Andy Shevchenko 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 Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7EF3EC433EF for ; Mon, 4 Apr 2022 10:15:32 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 333DF82AED; Mon, 4 Apr 2022 10:15:32 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ETT4OOTrphIS; Mon, 4 Apr 2022 10:15:31 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp1.osuosl.org (Postfix) with ESMTPS id C130F82948; Mon, 4 Apr 2022 10:15:30 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 96638C001D; Mon, 4 Apr 2022 10:15:30 +0000 (UTC) Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 8D95AC0012 for ; Mon, 4 Apr 2022 10:15:29 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 790FB81DB2 for ; Mon, 4 Apr 2022 10:15:29 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Jr6yP-qXe15J for ; Mon, 4 Apr 2022 10:15:28 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by smtp1.osuosl.org (Postfix) with ESMTPS id AB2158175A for ; Mon, 4 Apr 2022 10:15:28 +0000 (UTC) Received: by mail-ed1-x532.google.com with SMTP id g22so10462736edz.2 for ; Mon, 04 Apr 2022 03:15:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=s/rlqtfSH/+OKtlWbKj/8X8QmPBtgrwTTfh5H/AMmr8=; b=M6UB/xq5U2lez0akpMy5cdYkLpWp5TY7avZOr9EOmD3mOmC7LnKWizhrsWVbS9OYXV WxZR1L3Zip6LzxkB/OPBaxvuvHRQ+I4ccmh7WVg7layXLF9PfwqQYZ+jlB6EvWgmb6tq 0lZWCE3uc7LImkbQu2mlfWDe2OdVL/M2gk8b/f83Msuz2BzcI+DWU/n4c03LXmBik2KW KbNMC8korkh/nF0C0QAzLDf4TOGpyF8a6IoEG8l74xBIia5wiIab+cBhjD/6K3P9R06b EK2dkk2s3pESu8s3Lp5ePedMQzZPflgxpC1RgXqt3TXscJmh/VeMBZJdhbyeZhLuCe4J VwFg== 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=s/rlqtfSH/+OKtlWbKj/8X8QmPBtgrwTTfh5H/AMmr8=; b=anEj+AVsqFtMuroLa+v0QiVcEjXvA2OGwb9GnNWsPGrcXa+blraSMsQ2g/tVzzB3ZX DaILQiPgFaYATnBCa5JH2WAXrFkBxHHzDKDGaenFGxi16QK7HhAWghtjVfM6tsimUThT 4QXY/eZGhzZVvdygFqJBZETzOeEE9Y02iFMX24moY7kXuNOeNKeGsStYtx7T8jc3ipdu zs0gwgKb3iogMDKZiFH0eiVG4F/4Dv4hBmdGzwWsjbucsYK9d/UiEGfJfPKCJcKQ8XYw CN7c4sbR/o5/QTXicquBCmNphIwKsT3yc/KANAfMETuKyt3HhQPH741O5lAXjbvgrzr5 Ystg== X-Gm-Message-State: AOAM531UU8IMpXL+tBCyHC3UqpKsRzHO/FMlGrK7Ec17ijVSSiSvovn5 cjcAYNxr0V62g9g9XJO8zbMMTKcqDunK0vROJ1k= X-Google-Smtp-Source: ABdhPJxh9T+A1Yt+ILwhaxqoZIRZw7XK7bOr8aWn5QI6DqXoAfRnxar+91mJpxHWbEEB8aKP53yR05gviFAyUrKxBls= X-Received: by 2002:a05:6402:b19:b0:41c:d713:5cba with SMTP id bm25-20020a0564020b1900b0041cd7135cbamr2668518edb.270.1649067326747; Mon, 04 Apr 2022 03:15:26 -0700 (PDT) MIME-Version: 1.0 References: <20220403183758.192236-1-krzysztof.kozlowski@linaro.org> <20220403183758.192236-2-krzysztof.kozlowski@linaro.org> <2976f4f9-4fda-c04f-45cf-351518f88ec0@linaro.org> In-Reply-To: <2976f4f9-4fda-c04f-45cf-351518f88ec0@linaro.org> From: Andy Shevchenko Date: Mon, 4 Apr 2022 13:14:22 +0300 Message-ID: Subject: Re: [PATCH v6 01/12] driver: platform: Add helper for safer setting of driver_override To: Krzysztof Kozlowski Cc: Linux on Hyper-V List , Stuart Yoder , "Rafael J. Wysocki" , linux-pci , linux-remoteproc@vger.kernel.org, ALSA Development Mailing List , Bjorn Andersson , Vineeth Vijayan , Alexander Gordeev , linux-clk , linux-s390@vger.kernel.org, Wei Liu , Stephen Hemminger , Dexuan Cui , Andy Gross , NXP Linux Team , Heiko Carstens , Vasily Gorbik , linux-arm-msm@vger.kernel.org, Haiyang Zhang , linux-spi , Rasmus Villemoes , Bjorn Helgaas , virtualization@lists.linux-foundation.org, linux-arm Mailing List , Mathieu Poirier , Greg Kroah-Hartman , Peter Oberparleiter , Linux Kernel Mailing List , Sven Schnelle , Linus Torvalds X-BeenThere: virtualization@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux virtualization List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: virtualization-bounces@lists.linux-foundation.org Sender: "Virtualization" On Mon, Apr 4, 2022 at 12:34 PM Krzysztof Kozlowski wrote: > On 04/04/2022 11:16, Andy Shevchenko wrote: > > On Sun, Apr 3, 2022 at 9:38 PM Krzysztof Kozlowski > > wrote: ... > >> +int driver_set_override(struct device *dev, const char **override, > >> + const char *s, size_t len) > >> +{ > >> + const char *new, *old; > >> + char *cp; > > > >> + if (!override || !s) > >> + return -EINVAL; > > > > Still not sure if we should distinguish (s == NULL && len == 0) from > > (s != NULL && len == 0). > > Supplying the latter seems confusing (yes, I see that in the old code). Perhaps > > !s test, in case you want to leave it, should be also commented. > > The old semantics were focused on sysfs usage, so clearing is by passing > an empty string. In the case of sysfs empty string is actually "\n". I > intend to keep the semantics also for the in-kernel usage and in such > case empty string can be also "". > > If I understand your comment correctly, you propose to change it to NULL > for in-kernel usage, but that would change the semantics. Yes. It's also possible to have a wrapper for sysfs use. > > Another approach is to split above to two checks and move !s after !len. > > I don't follow why... The !override and !s are invalid uses. !len is a > valid user for internal callers, just like "\n" is for sysfs. I understand but always supplying s maybe an overhead for in-kernel usages. In any case, it's not critical right now, just a remark that it can be modified. > >> + /* > >> + * The stored value will be used in sysfs show callback (sysfs_emit()), > >> + * which has a length limit of PAGE_SIZE and adds a trailing newline. > >> + * Thus we can store one character less to avoid truncation during sysfs > >> + * show. > >> + */ > >> + if (len >= (PAGE_SIZE - 1)) > >> + return -EINVAL; > > > > Perhaps explain the case in the comment here? > > You mean the case we discuss here (to clear override with "")? Sure. Yep. Before the below check. > >> + if (!len) { > >> + device_lock(dev); > >> + old = *override; > >> + *override = NULL; > > > >> + device_unlock(dev); > >> + goto out_free; > > > > You may deduplicate this one, by > > > > goto out_unlock_free; > > > > But I understand your intention to keep lock-unlock in one place, so > > perhaps dropping that label would be even better in this case and > > keeping it > > Yes, exactly. > > > kfree(old); > > return 0; > > > > here instead of goto. > > Slightly more code, but indeed maybe easier to follow. I'll do like this. -- With Best Regards, Andy Shevchenko _______________________________________________ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization 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 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3B811C433F5 for ; Mon, 4 Apr 2022 10:16:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Zl5SdygDHKOHRvlk5ORCC5XQrZBCnRsBft5VR8lYNpo=; b=WoDMYdD47CMjtC 547YrTiWDIvONLbqG88RY5WyX5+V1nGwmrdw8J7YzN9ghukmZSETD7jGcOg1fs7dULDkBpMwc/CQW Np25asoEx8HuzqCVCSavoG9LBvQ4speEpLQeJo9hwQeIVaRSkszz0ckzDnvRFbL8NTuUiXKgQc+66 ittaWczX0fQGZ2phf5SW0QHwAz8GLHp8H3b0jLWG7gdewlPrHZqBKrlIgoYnGDOsUrhpn2IK2dD33 mcYhI0rlgew2bbTV59wC/5AuvnHCTTJOaQ47nOlzd5j99Vu6z525gVDIZcQxTM0XHKsmaXxZNGzTx 7XW9oAxhh95zxeVC8KmA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nbJkE-00EQfM-Ko; Mon, 04 Apr 2022 10:15:34 +0000 Received: from mail-ed1-x536.google.com ([2a00:1450:4864:20::536]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nbJkA-00EQcP-I8 for linux-arm-kernel@lists.infradead.org; Mon, 04 Apr 2022 10:15:32 +0000 Received: by mail-ed1-x536.google.com with SMTP id q26so2806117edc.7 for ; Mon, 04 Apr 2022 03:15:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=s/rlqtfSH/+OKtlWbKj/8X8QmPBtgrwTTfh5H/AMmr8=; b=M6UB/xq5U2lez0akpMy5cdYkLpWp5TY7avZOr9EOmD3mOmC7LnKWizhrsWVbS9OYXV WxZR1L3Zip6LzxkB/OPBaxvuvHRQ+I4ccmh7WVg7layXLF9PfwqQYZ+jlB6EvWgmb6tq 0lZWCE3uc7LImkbQu2mlfWDe2OdVL/M2gk8b/f83Msuz2BzcI+DWU/n4c03LXmBik2KW KbNMC8korkh/nF0C0QAzLDf4TOGpyF8a6IoEG8l74xBIia5wiIab+cBhjD/6K3P9R06b EK2dkk2s3pESu8s3Lp5ePedMQzZPflgxpC1RgXqt3TXscJmh/VeMBZJdhbyeZhLuCe4J VwFg== 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=s/rlqtfSH/+OKtlWbKj/8X8QmPBtgrwTTfh5H/AMmr8=; b=oRaaZkGJs1OHdl1714l2pMaEC+l4PhrGdwbwKHEE5kebM1aJC5Ue3Zb6JIZH3h+73E cz/8aH3nhd3mRtgh9R31KukHQORnto5EBYP79hGvbVN7uQsTiP5+yE4aLbsR31LuJxuT gzUoHs8cLw4bKJz4hjaBNdaTPMwGYmw8Yce00DYFfQYdCPcNvZ/g8Tz/50J8WlVvaa1x kAgf+9tUSX5BWZivyub7OBM+0HP3q1FQNXe439zp90TntsVz94/c520P/GcKaUtKnRfz 6NQcEccJGm2zgIsI1pUNU5x5tRcjAG4sjf9WoE4skVYywGZ+mhsAZMwzafgI9MzQrrP3 qpvQ== X-Gm-Message-State: AOAM532qO71jvjsaRJ8nIhKC9eX9Mv1YW0JnM+b6kFzhTOrfhvb548IS 0JfHdTV24VGBcnTwuTzluMhgS2pZtWqwi1c3S7M= X-Google-Smtp-Source: ABdhPJxh9T+A1Yt+ILwhaxqoZIRZw7XK7bOr8aWn5QI6DqXoAfRnxar+91mJpxHWbEEB8aKP53yR05gviFAyUrKxBls= X-Received: by 2002:a05:6402:b19:b0:41c:d713:5cba with SMTP id bm25-20020a0564020b1900b0041cd7135cbamr2668518edb.270.1649067326747; Mon, 04 Apr 2022 03:15:26 -0700 (PDT) MIME-Version: 1.0 References: <20220403183758.192236-1-krzysztof.kozlowski@linaro.org> <20220403183758.192236-2-krzysztof.kozlowski@linaro.org> <2976f4f9-4fda-c04f-45cf-351518f88ec0@linaro.org> In-Reply-To: <2976f4f9-4fda-c04f-45cf-351518f88ec0@linaro.org> From: Andy Shevchenko Date: Mon, 4 Apr 2022 13:14:22 +0300 Message-ID: Subject: Re: [PATCH v6 01/12] driver: platform: Add helper for safer setting of driver_override To: Krzysztof Kozlowski Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" , Stuart Yoder , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , Dexuan Cui , Bjorn Helgaas , Bjorn Andersson , Mathieu Poirier , Vineeth Vijayan , Peter Oberparleiter , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Andy Gross , Linux Kernel Mailing List , linux-clk , NXP Linux Team , linux-arm Mailing List , Linux on Hyper-V List , linux-pci , linux-remoteproc@vger.kernel.org, linux-s390@vger.kernel.org, linux-arm-msm@vger.kernel.org, ALSA Development Mailing List , linux-spi , virtualization@lists.linux-foundation.org, Linus Torvalds , Rasmus Villemoes X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220404_031530_659860_70917EE3 X-CRM114-Status: GOOD ( 32.31 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Apr 4, 2022 at 12:34 PM Krzysztof Kozlowski wrote: > On 04/04/2022 11:16, Andy Shevchenko wrote: > > On Sun, Apr 3, 2022 at 9:38 PM Krzysztof Kozlowski > > wrote: ... > >> +int driver_set_override(struct device *dev, const char **override, > >> + const char *s, size_t len) > >> +{ > >> + const char *new, *old; > >> + char *cp; > > > >> + if (!override || !s) > >> + return -EINVAL; > > > > Still not sure if we should distinguish (s == NULL && len == 0) from > > (s != NULL && len == 0). > > Supplying the latter seems confusing (yes, I see that in the old code). Perhaps > > !s test, in case you want to leave it, should be also commented. > > The old semantics were focused on sysfs usage, so clearing is by passing > an empty string. In the case of sysfs empty string is actually "\n". I > intend to keep the semantics also for the in-kernel usage and in such > case empty string can be also "". > > If I understand your comment correctly, you propose to change it to NULL > for in-kernel usage, but that would change the semantics. Yes. It's also possible to have a wrapper for sysfs use. > > Another approach is to split above to two checks and move !s after !len. > > I don't follow why... The !override and !s are invalid uses. !len is a > valid user for internal callers, just like "\n" is for sysfs. I understand but always supplying s maybe an overhead for in-kernel usages. In any case, it's not critical right now, just a remark that it can be modified. > >> + /* > >> + * The stored value will be used in sysfs show callback (sysfs_emit()), > >> + * which has a length limit of PAGE_SIZE and adds a trailing newline. > >> + * Thus we can store one character less to avoid truncation during sysfs > >> + * show. > >> + */ > >> + if (len >= (PAGE_SIZE - 1)) > >> + return -EINVAL; > > > > Perhaps explain the case in the comment here? > > You mean the case we discuss here (to clear override with "")? Sure. Yep. Before the below check. > >> + if (!len) { > >> + device_lock(dev); > >> + old = *override; > >> + *override = NULL; > > > >> + device_unlock(dev); > >> + goto out_free; > > > > You may deduplicate this one, by > > > > goto out_unlock_free; > > > > But I understand your intention to keep lock-unlock in one place, so > > perhaps dropping that label would be even better in this case and > > keeping it > > Yes, exactly. > > > kfree(old); > > return 0; > > > > here instead of goto. > > Slightly more code, but indeed maybe easier to follow. I'll do like this. -- With Best Regards, Andy Shevchenko _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel 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 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D0002C433EF for ; Fri, 8 Apr 2022 07:49:38 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id DF03818D7; Fri, 8 Apr 2022 09:48:46 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz DF03818D7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1649404176; bh=xdQZa32pNo5xnf5JXsjAQp2Droc/xkiIYpA/NtwNZAg=; h=References:In-Reply-To:From:Date:Subject:To:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=mt9VhQU/T/JEdZl4EVuHmfxlnYIr4q/l8zoaajA7o3aTEf1yekjt/Fikp5o1cU1RZ wLqecoTgEcpo2VSiKN3+mfed5rFTPTvhSp+dN7tpYnKDJy89HwlXeInsRyITxARLN0 Wh1GgOIb77d3QdJ0y8HmCLkrnlka9vqib1CgEQ0A= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 2EA20F804B1; Fri, 8 Apr 2022 09:48:15 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id F149DF80162; Mon, 4 Apr 2022 12:15:36 +0200 (CEST) Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 95F83F80100 for ; Mon, 4 Apr 2022 12:15:28 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 95F83F80100 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="M6UB/xq5" Received: by mail-ed1-x529.google.com with SMTP id d10so5639504edj.0 for ; Mon, 04 Apr 2022 03:15:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=s/rlqtfSH/+OKtlWbKj/8X8QmPBtgrwTTfh5H/AMmr8=; b=M6UB/xq5U2lez0akpMy5cdYkLpWp5TY7avZOr9EOmD3mOmC7LnKWizhrsWVbS9OYXV WxZR1L3Zip6LzxkB/OPBaxvuvHRQ+I4ccmh7WVg7layXLF9PfwqQYZ+jlB6EvWgmb6tq 0lZWCE3uc7LImkbQu2mlfWDe2OdVL/M2gk8b/f83Msuz2BzcI+DWU/n4c03LXmBik2KW KbNMC8korkh/nF0C0QAzLDf4TOGpyF8a6IoEG8l74xBIia5wiIab+cBhjD/6K3P9R06b EK2dkk2s3pESu8s3Lp5ePedMQzZPflgxpC1RgXqt3TXscJmh/VeMBZJdhbyeZhLuCe4J VwFg== 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=s/rlqtfSH/+OKtlWbKj/8X8QmPBtgrwTTfh5H/AMmr8=; b=sxr+6xtO7wUYLsg2NQaoA0VtqIhhNvwGpv5KRpcswAovUlpDXepr/+Dp6Z6pgCa2SG cxyluYMWmSujEpt5XUSJetG3gMuKuxTZn9h1HgS3sbkifQAnpQ+5OiHGxLloefdYP3A1 RvpkRno4U/4i1bk8c0XNP/qbrZEU4W/JZSSz3ZlZ6HdHE9HjpDzDVnu+lAQf8ROdvFch 28GsTShfEC/U9dc+yGwCCocbonfGPzTMB3t7g93II4Ypz4BrvhH9z1xyFOeFWPT6s1bW g2qahsOO8NdDaKP3x0A1tctuXp+5t0bxIckfON91T6/KE/YEr+rIbAndA/iWvAN/5IDO ohIA== X-Gm-Message-State: AOAM5317G8vuhbSvi14fVr+8kOdM/3LlHGdd2Bq9rdmGcixJzRSCM1rn UxtQwJb1fYpoPKU6GTaY01GIyORMvQS3+UklbvU= X-Google-Smtp-Source: ABdhPJxh9T+A1Yt+ILwhaxqoZIRZw7XK7bOr8aWn5QI6DqXoAfRnxar+91mJpxHWbEEB8aKP53yR05gviFAyUrKxBls= X-Received: by 2002:a05:6402:b19:b0:41c:d713:5cba with SMTP id bm25-20020a0564020b1900b0041cd7135cbamr2668518edb.270.1649067326747; Mon, 04 Apr 2022 03:15:26 -0700 (PDT) MIME-Version: 1.0 References: <20220403183758.192236-1-krzysztof.kozlowski@linaro.org> <20220403183758.192236-2-krzysztof.kozlowski@linaro.org> <2976f4f9-4fda-c04f-45cf-351518f88ec0@linaro.org> In-Reply-To: <2976f4f9-4fda-c04f-45cf-351518f88ec0@linaro.org> From: Andy Shevchenko Date: Mon, 4 Apr 2022 13:14:22 +0300 Message-ID: Subject: Re: [PATCH v6 01/12] driver: platform: Add helper for safer setting of driver_override To: Krzysztof Kozlowski Content-Type: text/plain; charset="UTF-8" X-Mailman-Approved-At: Fri, 08 Apr 2022 09:48:11 +0200 Cc: Linux on Hyper-V List , Stuart Yoder , "Rafael J. Wysocki" , linux-pci , linux-remoteproc@vger.kernel.org, ALSA Development Mailing List , Bjorn Andersson , Vineeth Vijayan , Alexander Gordeev , "K. Y. Srinivasan" , linux-clk , linux-s390@vger.kernel.org, Wei Liu , Stephen Hemminger , Dexuan Cui , Andy Gross , NXP Linux Team , Christian Borntraeger , Heiko Carstens , Vasily Gorbik , linux-arm-msm@vger.kernel.org, Haiyang Zhang , linux-spi , Rasmus Villemoes , Bjorn Helgaas , virtualization@lists.linux-foundation.org, linux-arm Mailing List , Mathieu Poirier , Greg Kroah-Hartman , Peter Oberparleiter , Linux Kernel Mailing List , Sven Schnelle , Linus Torvalds X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" On Mon, Apr 4, 2022 at 12:34 PM Krzysztof Kozlowski wrote: > On 04/04/2022 11:16, Andy Shevchenko wrote: > > On Sun, Apr 3, 2022 at 9:38 PM Krzysztof Kozlowski > > wrote: ... > >> +int driver_set_override(struct device *dev, const char **override, > >> + const char *s, size_t len) > >> +{ > >> + const char *new, *old; > >> + char *cp; > > > >> + if (!override || !s) > >> + return -EINVAL; > > > > Still not sure if we should distinguish (s == NULL && len == 0) from > > (s != NULL && len == 0). > > Supplying the latter seems confusing (yes, I see that in the old code). Perhaps > > !s test, in case you want to leave it, should be also commented. > > The old semantics were focused on sysfs usage, so clearing is by passing > an empty string. In the case of sysfs empty string is actually "\n". I > intend to keep the semantics also for the in-kernel usage and in such > case empty string can be also "". > > If I understand your comment correctly, you propose to change it to NULL > for in-kernel usage, but that would change the semantics. Yes. It's also possible to have a wrapper for sysfs use. > > Another approach is to split above to two checks and move !s after !len. > > I don't follow why... The !override and !s are invalid uses. !len is a > valid user for internal callers, just like "\n" is for sysfs. I understand but always supplying s maybe an overhead for in-kernel usages. In any case, it's not critical right now, just a remark that it can be modified. > >> + /* > >> + * The stored value will be used in sysfs show callback (sysfs_emit()), > >> + * which has a length limit of PAGE_SIZE and adds a trailing newline. > >> + * Thus we can store one character less to avoid truncation during sysfs > >> + * show. > >> + */ > >> + if (len >= (PAGE_SIZE - 1)) > >> + return -EINVAL; > > > > Perhaps explain the case in the comment here? > > You mean the case we discuss here (to clear override with "")? Sure. Yep. Before the below check. > >> + if (!len) { > >> + device_lock(dev); > >> + old = *override; > >> + *override = NULL; > > > >> + device_unlock(dev); > >> + goto out_free; > > > > You may deduplicate this one, by > > > > goto out_unlock_free; > > > > But I understand your intention to keep lock-unlock in one place, so > > perhaps dropping that label would be even better in this case and > > keeping it > > Yes, exactly. > > > kfree(old); > > return 0; > > > > here instead of goto. > > Slightly more code, but indeed maybe easier to follow. I'll do like this. -- With Best Regards, Andy Shevchenko