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 B9178C001DF for ; Tue, 1 Aug 2023 17:51:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229828AbjHARvv (ORCPT ); Tue, 1 Aug 2023 13:51:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229642AbjHARvt (ORCPT ); Tue, 1 Aug 2023 13:51:49 -0400 Received: from mgamail.intel.com (unknown [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00046126 for ; Tue, 1 Aug 2023 10:51:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690912308; x=1722448308; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=23Wc3k0mFLbrQycUcEsHy3FEUV7003iJlGRdyTKc6ms=; b=WRT98ZQu3pv8AFD8jErVRk4p2F2YMeWXWW4WZXNHoottfqAMptBK5Eb3 SY7S6f5DbP8QZKFOGEBYgSLBpRvZ3NpBX8kCRC0TgY8ftrric6qPuCdhv RR3A8n4ArcwdEgYUWEj6J97lgtwKPzEggdkXqia+CAYuHWrDQge6TlDOu 6Q5ZjtFQk9igu4TZENavKNnBKL56d8tupVsGGvXh76WkmZXrJyxiyhpsH r8BZhamH1Nk8F9xDBHfatuuJHXhgSIu7uRopfe08w8/rKpNs6F2TFOmBD J91LpdzkFobur3VDVF74fxG/mJPvq4X5vzTAlRNvZ38t1D2yfdyNEPsOL Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10789"; a="368273817" X-IronPort-AV: E=Sophos;i="6.01,247,1684825200"; d="scan'208";a="368273817" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Aug 2023 10:51:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10789"; a="758441153" X-IronPort-AV: E=Sophos;i="6.01,247,1684825200"; d="scan'208";a="758441153" Received: from smile.fi.intel.com ([10.237.72.54]) by orsmga008.jf.intel.com with ESMTP; 01 Aug 2023 10:51:43 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.96) (envelope-from ) id 1qQtX2-00DKb2-0b; Tue, 01 Aug 2023 20:51:40 +0300 Date: Tue, 1 Aug 2023 20:51:39 +0300 From: Andy Shevchenko To: Takashi Iwai Cc: Mark Brown , alsa-devel@alsa-project.org, Andrey Utkin , Anton Sviridenko , Arnaud Pouliquen , Banajit Goswami , Bluecherry Maintainers , Claudiu Beznea , Ismael Luceno , Lars-Peter Clausen , Mauro Carvalho Chehab , Oleksandr Andrushchenko , Olivier Moysan , Srinivas Kandagatla , linux-media@vger.kernel.org, xen-devel@lists.xenproject.org Subject: Re: [PATCH 00/24] ALSA: Generic PCM copy ops using sockptr_t Message-ID: References: <20230731154718.31048-1-tiwai@suse.de> <87h6pjj2ui.wl-tiwai@suse.de> <87leeugbxm.wl-tiwai@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87leeugbxm.wl-tiwai@suse.de> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org On Tue, Aug 01, 2023 at 02:54:45PM +0200, Takashi Iwai wrote: > On Mon, 31 Jul 2023 21:40:20 +0200, > Mark Brown wrote: > > On Mon, Jul 31, 2023 at 09:30:29PM +0200, Takashi Iwai wrote: > > > Mark Brown wrote: > > > > > > It really feels like we ought to rename, or add an alias for, the type > > > > if we're going to start using it more widely - it's not helping to make > > > > the code clearer. > > > > > That was my very first impression, too, but I changed my mind after > > > seeing the already used code. An alias might work, either typedef or > > > define genptr_t or such as sockptr_t. But we'll need to copy the > > > bunch of helper functions, too... > > > > I would predict that if the type becomes more widely used that'll happen > > eventually and the longer it's left the more work it'll be. > > That's true. The question is how more widely it'll be used, then. > > Is something like below what you had in mind, too? I agree with your proposal (uniptr_t also works for me), but see below. ... > +#include > +#include But let make the list of the headers right this time. It seems to me that err.h minmax.h // maybe not, see a remark at the bottom string.h types.h are missing. More below. ... > + void *p = kmalloc_track_caller(len, GFP_USER | __GFP_NOWARN); > + > + if (!p) > + return ERR_PTR(-ENOMEM); This can use cleanup.h. > + if (copy_from_uniptr(p, src, len)) { > + kfree(p); > + return ERR_PTR(-EFAULT); > + } > + return p; > +} > + > +static inline void *memdup_uniptr_nul(uniptr_t src, size_t len) > +{ > + char *p = kmalloc_track_caller(len + 1, GFP_KERNEL); Ditto. > + if (!p) > + return ERR_PTR(-ENOMEM); > + if (copy_from_uniptr(p, src, len)) { > + kfree(p); > + return ERR_PTR(-EFAULT); > + } > + p[len] = '\0'; > + return p; > +} ... > +static inline long strncpy_from_uniptr(char *dst, uniptr_t src, size_t count) > +{ > + if (uniptr_is_kernel(src)) { > + size_t len = min(strnlen(src.kernel, count - 1) + 1, count); I didn't get why do we need min()? To check the count == 0 case? Wouldn't size_t len; len = strnlen(src.kernel, count); if (len == 0) return 0; /* Copy a trailing NUL if found */ if (len < count) len++; be a good equivalent? > + memcpy(dst, src.kernel, len); > + return len; > + } > + return strncpy_from_user(dst, src.user, count); > +} ... > +static inline int check_zeroed_uniptr(uniptr_t src, size_t offset, size_t size) > +{ > + if (!uniptr_is_kernel(src)) Why not to align all the functions to use same conditional (either always positive or negative)? > + return check_zeroed_user(src.user + offset, size); > + return memchr_inv(src.kernel + offset, 0, size) == NULL; > +} ... Taking all remarks into account I would rather go with sockptr.h being untouched for now, just a big /* DO NOT USE, it's obsolete, use uniptr.h instead! */ to be added. -- With Best Regards, Andy Shevchenko