Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1022853imm; Wed, 4 Jul 2018 10:01:46 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfMo7+U6yH5dIFsiM4FXTLyt6asIualGBfT4yUz7+SZdA8xu6o41I48XGPR5+BA6WJdjDhq X-Received: by 2002:a62:6882:: with SMTP id d124-v6mr3001286pfc.122.1530723706582; Wed, 04 Jul 2018 10:01:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530723706; cv=none; d=google.com; s=arc-20160816; b=hy4tZVTO25IUeuJ3G8X7m4Cc6YU8pBze+Qf92EBvPshPvoi6Am7HHAU7oXDryBrstg JJQEggXepgOcRy/X2qdz/P4vwxusyjEga4WHv0KzfxRw4ex1K+XbPA8YGhkd5VApoo3c TTjFveGkzf4gwRaN9Fok6y2OV8KrxSx//IEZEVUXPYLKGHXEFkwQ5cXnx3mvnBoB7uZr lapt5xQcaeZc/xVFzblU4t//++numZgWjeqswjdNnNLct/3DYtbwaWS3LqDJRsageTsP YRCw8At24TGqIIwY8SxIAtJ1aka0Lpnu7hphC/dgmBC77zyQ4AkRyN+NPDUlwsJmF7h6 5WWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=MN+Mid/JXxBQFpgoLr4mZiOYYM12A1skz4d9JMA09ao=; b=FRiQHmBseQo7pEFA7X+47xb76yQxeWh7rA1nXKzC2rqk0StR0nJQypeGqadgQMV9vZ GoFc8pQrIwJjDgdNzUfd2p31QQtWC0A4mdAnHelCJ5qCHPFAQa+x5iDfcnLXZdhLUOpC EkVzNeivVcCHzCOED4ZrexGv96caVgwt23NFudnARyzXL7t+4iDEAfO1ZivnPUp8WBHc UG0uAFyGI+ZA+wcflTgtsOxNpgbVD5MF/50LkiRpproyvcaPg6VS9xCOwn8KxOkCjbMo lCl+Qec2eD0EjITF2JPX6l8PWoF84f7Uh0bLdDvZSWMC/ByGKevADxVR+g+7rzDRwXGG rqJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=aF1T3oyU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r21-v6si3496030pgu.55.2018.07.04.10.01.31; Wed, 04 Jul 2018 10:01:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=aF1T3oyU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753083AbeGDRAx (ORCPT + 99 others); Wed, 4 Jul 2018 13:00:53 -0400 Received: from mail-vk0-f68.google.com ([209.85.213.68]:44112 "EHLO mail-vk0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752816AbeGDRAu (ORCPT ); Wed, 4 Jul 2018 13:00:50 -0400 Received: by mail-vk0-f68.google.com with SMTP id 125-v6so3422079vke.11; Wed, 04 Jul 2018 10:00:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=MN+Mid/JXxBQFpgoLr4mZiOYYM12A1skz4d9JMA09ao=; b=aF1T3oyUsSzqcoJKmRo5Hzg+pL7TNCj098JM4ZgEP74KN9fMWej10uPHZX0JwNuun2 Ez1tnTMhcekJqNp3B3Nxvl++HiFqfF5yCMVeRB86wF0OHBq5mdiZyKECY4dBxrYw0jXL V6fDaw5www+Jm2wD0DyydCj10OOapxkZWUEVvLlbNHsDDi2kHGJDj43QV2nQ/UbI/SMT T03WuaRJYeznlHCEy1NGouUZBVdFe+KH2q9uucr8PStlxrNkmXIulGM7fbpJUd+eXaQy Xz5UHb6dQU1vgHXBWJ6zONe6MeQUvLjS+Wx7UB9h2Id7Cb1L8c08F/WjChNmqOxPHcit egAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=MN+Mid/JXxBQFpgoLr4mZiOYYM12A1skz4d9JMA09ao=; b=Ua6mNkmrUNuMrvUt9sZdAImGlT4cBwd82ZgHNtydeoCXi/3BfBVbOEgRmgbtk8St/L z+udcH2SW9PTzGwgAFGtF7+HnOwP0eqyTYus67/Mn3vaiKF5LoKhONj1V/aHgbjxaaKG EgGG4fNwBPyWcR1EZzC/rYgclKCd1SJ2iazubd5TXUZNm0QGfb8mE2OBnv30r8ae11cR EiZ9Hanb4IFM0Cs4eSBwST+mhuMooJ41KVgOkAGg7igO4rniI/GXOO3SaV/VEDNVQ5Ms LgXoFoD8R6wdvEpIVRp5BPKdfgoW24QcDUVlogP+0IT5ZoI9k53wKFXJdmbdJiHdjFez N3cQ== X-Gm-Message-State: APt69E2eJJesdi8rjg+KTSeWUjuLSBljY1lDWsD3kEhCaBbyM+P47X3g OqmLchgMBtITWWGYt2QlbxN72FC6fHtwO4aHFI3rASxtyt4= X-Received: by 2002:a1f:820e:: with SMTP id e14-v6mr1504917vkd.187.1530723649134; Wed, 04 Jul 2018 10:00:49 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a67:2149:0:0:0:0:0 with HTTP; Wed, 4 Jul 2018 10:00:48 -0700 (PDT) In-Reply-To: <62fb47ea-9296-139b-1eeb-28ddc5826091@landley.net> References: <62fb47ea-9296-139b-1eeb-28ddc5826091@landley.net> From: Andy Shevchenko Date: Wed, 4 Jul 2018 20:00:48 +0300 Message-ID: Subject: Re: [PATCH] Fix platform data in leds-pca955x.c To: Rob Landley Cc: clg@kaod.org, Jacek Anaszewski , Pavel Machek , Andrew Jeffery , Linux LED Subsystem , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 4, 2018 at 3:46 AM, Rob Landley wrote: > I have some questions about recent changes to leds-pca955x.c since 4.13: > > How is non-of platform data supposed to work now? Commit ed1f4b9676a8 switched > struct led_platform_data *pdata in the _probe() function to a locally defined > structure that platform data can't provide because it's not in any header it > can #include. > > This is disguised by dev_get_platdata() returning a void * so changing the type > of pdata the returned pointer is assigned to didn't require a new typecast, > instead existing board definitions still compile but quietly break at runtime. > (Specifically the SH7760 board I use at work broke in the pdata->num_leds != > chip->bits sanity check, and then userpace sees an empty /sys/class/leds and I > started start digging because "huh"?) > > Why did the type change, anyway? The generic led_platform_data it was > using before has all the fields the device tree's actually initializing, at > least if you use flags for the new gpio stuff. > > Commit 561099a1a2e9 added CONFIG_LEDS_PCA955X_GPIO, but the initialization > code adds gpio logic outside this config symbol: probe only calls > devm_led_classdev_register() within a case statement that depends on setting the > right "this is not GPIO" value. > > The "GPIO" indicator could have been a flag in the existing LED structure's > flags field, but instead of a bit it's #defining three symbols. The > PCA955X_TYPE_* macros with the new type constants only exist in the device tree > header. Strangely, the old default "this is an LED" value isn't zero, zero is > PCA955X_TYPE_NONE which is unused (never set anywhere in the tree), and would > cause the LED to be skipped: you have to set a field platform data can't > access, using a macro platform data probably doesn't have, in order for > devm_led_classdev_register() to get called on that LED at all. Why? > > This is especially odd since if you did want to skip an LED, there was already a > way to indicate that: by giving it an empty string as a name. (It doesn't seem > to have come up, but it's the obvious way to do it.) Except commit 390c97dc6e34 > deals with that by writing the index number as a string to the platform data > struct. Leaving aside "why did you do that?", isn't the platform data supposed to > be in a read only section when it's actual platform data? And since the probe > function then immediately copies the data into the another structure, can't we > just fill out the other one directly without overwriting our arguments? > > As for the lifetime rules, the local pca955x_led (writeable copy initialized from > the read-only platform data) had the name[] array locally living in the > struct, but the device tree commits added char *default_trigger pointing to > external memory. Is there a reason this is now inconsistent? > > Here's the patch I whipped up at work today (applied to v4.14) that undid enough > of this to make the driver work again with platform data on the board we ship: No platform data, please. So, we have two options here: - use Unified Device Properties API - introduce something like LED_LOOKUP_TABLE (see analogue with GPIO / regulator / PWM) Looking at the platform data LED framework provides I don't see for now a necessity of creating lookup tables (though it might be better choice in long term). For now, you can switch to unified device properties API (basically un-ifdef pca955x_pdata_of_init() and replacing of_* by device_* or fwnode_* compatible calls) and providing a static table of built-in device properties in the platform code in question. (see include/linux/property.h, for example users of PROPERTY_ENTRY_U*() macros, like arch/arm/mach-pxa/raumfeld.c) -- With Best Regards, Andy Shevchenko