Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp8100040rwb; Wed, 23 Nov 2022 15:38:38 -0800 (PST) X-Google-Smtp-Source: AA0mqf5yeF9qPY+rrVsoRCLMyvXET1uxDv9Jx2CxCmWSL5Jl3qFUhYi6SSCtzSDJGSPUTsqSmDQL X-Received: by 2002:a17:906:5213:b0:7b6:12ee:b7fc with SMTP id g19-20020a170906521300b007b612eeb7fcmr14705138ejm.265.1669246718297; Wed, 23 Nov 2022 15:38:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669246718; cv=none; d=google.com; s=arc-20160816; b=gWD21rjxx1uVAo96sOot514hEHNpN6ZE9j1jpwd6Gn+ShDVHq2qBkl7agnGNjKEXLE bLNmRVVhFOpr5Htm0cho6SI6rjBUlkBi2oGFiRPbWwV33UFE91APsiYb2NGhwGfFki9L 6wyXXd4AX7Q/dEZcE6hzDm0U09Tzm1XSaspSgYl85hoU8HDHMztGIkJwt3+cLdhnWEO6 vXdi8Zxaoyrbe+GayOmTv0IT8BHctUogMVBPVA3+NINIrMmxAKcXnOHDo6I71nLvdDGo o4ie/qtDJZI2Qvrd2mqnN/IZMsVbdnLyaN+fmES0hnLYlPk+qaYp86SL0sZM2hfQ1C4H gQug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :feedback-id:references:in-reply-to:message-id:subject:cc:from:to :dkim-signature:date; bh=4D7H7t9cQFG+vEXPzrmjxP0kBkCA637MqCW+lh8xlvo=; b=JYwQ3wJjdF6iGUteb8YuIJqCP0ASMkGBl1LmiiBO2TlLdHA9mse39JRZGm0Itr1eKw T9+kdu6qfSjLqEeIpUxzTy8Dx1LB/A+dBC6FLKYeUc8NQFzy7y1KjQj7/YlFr6nYIZYx Z6R7IRsHuMv/u77AdBNEyGH+ckujTd2Y/lcUWRMDADjULd8ICp2ezTA0w7kLfQD3qGXf 9Fr+OXTD7UKGwB20Cq9vm0twdsMb15xQO0aHD3+BoDxEwWyJA0hXe96VYEt5PWqgwQie t7Xo/7hp9c2QvU8vkSoBh+jAcwreJbVgOtsjprRMhd4XLkFSPr8xnyt+wBuHeN/cv4Mo alMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail3 header.b=hPbJVkIu; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m8-20020a056402430800b0045d27c0ba90si1081595edc.577.2022.11.23.15.38.17; Wed, 23 Nov 2022 15:38:38 -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; dkim=pass header.i=@protonmail.com header.s=protonmail3 header.b=hPbJVkIu; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229604AbiKWXYq (ORCPT + 88 others); Wed, 23 Nov 2022 18:24:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229928AbiKWXYk (ORCPT ); Wed, 23 Nov 2022 18:24:40 -0500 Received: from mail-0201.mail-europe.com (mail-0201.mail-europe.com [51.77.79.158]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FA3D1121C8; Wed, 23 Nov 2022 15:24:39 -0800 (PST) Date: Wed, 23 Nov 2022 23:24:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1669245874; x=1669505074; bh=4D7H7t9cQFG+vEXPzrmjxP0kBkCA637MqCW+lh8xlvo=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=hPbJVkIuL1M0qEmL0bT4PuPpgSPCUAu33Y+Qb7tdeEgjcQqAn2P9/FpfK16HEA2EM 7vjsfHf0eS2PmoRXdPNGezpmX314hJ02XB0zpjgzVkJDzPqhEL7AMChGfIwFpiPwIA NF7ZZEj1iGDIHy5p8DLkWQw2m5Qldpno4e6/JtLA16r0ZaA4hkUD/VeqWm5hbTdlnb BxWDFCkr77h+K0/o8YNYsqjLGq0ZWGeFJce25BsYm5wcKn9VpmO0zKAO32OE9aTevx yfP5UsPCKW2I3bqPQKJL7FqD0bhsWsXV2qxdqiRQ7WsVWh4oHNK9TFNBq0m4+w4lGn bmQFT/VhhjM8A== To: Greg Kroah-Hartman From: =?utf-8?Q?Barnab=C3=A1s_P=C5=91cze?= Cc: Jason Gunthorpe , Matthew Wilcox , Maximilian Luz , Andy Shevchenko , linux-kernel@vger.kernel.org, Jens Axboe , "Rafael J. Wysocki" , Len Brown , Stefan Richter , Wolfram Sang , Alexandre Belloni , Dmitry Torokhov , Sean Young , Mauro Carvalho Chehab , Rob Herring , Frank Rowand , Hans de Goede , Mark Gross , Vinod Koul , Bard Liao , Pierre-Louis Bossart , Sanyog Kale , Andreas Noever , Michael Jamet , Mika Westerberg , Yehezkel Bernat , Jiri Slaby , Heikki Krogerus , "Martin K. Petersen" , Chaitanya Kulkarni , Ming Lei , Jilin Yuan , Alan Stern , Sakari Ailus , Thomas Gleixner , Ira Weiny , Dan Williams , Won Chung , alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-acpi@vger.kernel.org, linux-block@vger.kernel.org, linux-i2c@vger.kernel.org, linux-i3c@lists.infradead.org, linux-input@vger.kernel.org, linux-media@vger.kernel.org, linux-serial@vger.kernel.org, linux-usb@vger.kernel.org, linux1394-devel@lists.sourceforge.net, platform-driver-x86@vger.kernel.org Subject: Re: [PATCH 3/5] driver core: make struct device_type.uevent() take a const * Message-ID: In-Reply-To: References: Feedback-ID: 20568564:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS autolearn=unavailable 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: X-Mailing-List: linux-kernel@vger.kernel.org Hi 2022. november 23., szerda 20:06 keltez=C3=A9ssel, Greg Kroah-Hartman = =C3=ADrta: > On Wed, Nov 23, 2022 at 02:25:59PM -0400, Jason Gunthorpe wrote: >=20 > > On Wed, Nov 23, 2022 at 07:10:49PM +0100, Greg Kroah-Hartman wrote: > >=20 > > > On Wed, Nov 23, 2022 at 05:49:36PM +0000, Matthew Wilcox wrote: > > >=20 > > > > On Wed, Nov 23, 2022 at 01:29:56PM -0400, Jason Gunthorpe wrote: > > > >=20 > > > > > #define generic_container_of(in_type, in, out_type, out_member) \ > > > > > _Generic(in, \ > > > > > const in_type *: ((const out_type *)container_of(in, out_type, ou= t_member)), \ > > > > > in_type *: ((out_type *)container_of(in, out_type, out_member)) \ > > > > > ) > > > >=20 > > > > There's a neat trick I found in seqlock.h: > > > >=20 > > > > #define generic_container_of(in_t, in, out_t, m) \ > > > > _Generic(*(in), \ > > > > const in_t: ((const out_t *)container_of(in, out_t, m)), \ > > > > in_t: ((out_t *)container_of(in, out_type, m)) \ > > > > ) > > > >=20 > > > > and now it fits in 80 columns ;-) > > >=20 > > > Nice trick! Dropping the inline functions is a bit different, let me > > > see if that still gives a sane error if we pass an incorrect type or > > > mess with the const * the wrong way. I'll run some tests tomorrow > > > afternoon... > >=20 > > The errors in some cases are very verbose, but it is somewhat > > understandable - the worst is when _Generic fails to match anything, > > but also at least clang partially expanded container_of and it throws > > other assertions too. > >=20 > > I also wonder if this could just be rolled into the normal > > container_of. >=20 >=20 > I think we might be able to now, my previous attempts with inline > functions prevented that. I'll beat on that tomorrow... >=20 > > in_type would have to be derived like: > >=20 > > in_type =3D typeof((out_type *)NULL)->out_member) > >=20 > > But I don't know if you can use typeof in a generic type matching expre= ssion.. >=20 >=20 > Maybe that is what threw me before, I can't remember. I do know we > tried a number of different attempts, can't recall the failed ones... >=20 I am sorry I haven't followed the previous discussion, but has something like the following been considered? #define container_of2(ptr, type, member) \ =09_Generic((ptr), \ =09=09typeof_member(const type, member) *: container_of((ptr), const type= , member), \ =09=09const void *: container_of((ptr), const type, member), \ =09=09default: container_of((ptr), type, member) \ =09) This is not perfect by any means, but I believe it is a reasonable improvement. It only really works reliably if the member type and the specified `type` in the arguments are unqualified, but I believe that should cover the majority of cases. I have tried to build an x86-64 defconfig with this and there are numerous const violations, but I haven't seen any false positives. > [...] Regards, Barnab=C3=A1s P=C5=91cze