Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1026547pxj; Tue, 18 May 2021 20:00:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZpeZTDA9hK8vLczZCv5cQcaQjuMxPavzPoI22X6rY3NMFxyGQT7ZcnYkmq+Gtz+GeOeDr X-Received: by 2002:a05:6402:2786:: with SMTP id b6mr11323726ede.20.1621393245601; Tue, 18 May 2021 20:00:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621393245; cv=none; d=google.com; s=arc-20160816; b=UJfAfM5WiPrj+e1auCS+Y1PQczSNkFfrYSFI2f2lJf9DKPH6YACNqXdz3h9oF9UZVr Nwy29YSi2PJCEaCHiwRm9v4tE/P8FZY/VpF24aQ0tz95XocSzxjl4OyNSHGGXwOVhXlc 0kcAHmiU4XycAtJY1hGXL3ez3qJ/636LNeM9yJp3IJNqOVVxCRhmVttIXuk8nN601b42 JIhGOJM1/pqsM/4kPkLRVNQPJyc4hg/KYnJjm7A3KhqLCueBJ3HZ3qK05CXJCB6OInNY vpTKlPQRDBg5NL6gO/frSCFLE14ooXjqpSMMPZ6c/H0xE10H1Y9L1VZIzcE6+ZEubExu vD9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=IVIyPTZ6w0h3Ret1w2E/pdnyUaIbFCtkLZj+hGFpk4s=; b=zF3W0G/FXsCZORYQGgqc74hNCAcGxtalfvAq/6yoTkCCYD3Vu66FS+LfmcWimwQVqp T8Gl9EUtsGRSDuhT0wbsKwplLZVbhWKobSH+kUIJEANiNJw3M3Rbe/C7ok1IpWdXMntM OdSYCBAvDB5v43xbGKwKRoqPOtt88fk9FsU2coFeDC6rqPuSlGNJHzaZGKE3iCPItN1B aUs+p2noB0WGL14HhAcGq3wegEXMC+UG9QsSgDkEpoW9hjTwZhkfcaSYZrXvjzzu7gM/ z2vbDMXeIFTKJXHEKDho5+hyxfbb85tTk7Q/ePEb9eFB3uoBpO+p5V7n7yyNI7nxr71D AEsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="X/xKCa7K"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id hb7si401167ejc.507.2021.05.18.20.00.22; Tue, 18 May 2021 20:00:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="X/xKCa7K"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S237303AbhEQUDf (ORCPT + 99 others); Mon, 17 May 2021 16:03:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236917AbhEQUDe (ORCPT ); Mon, 17 May 2021 16:03:34 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A751FC061573; Mon, 17 May 2021 13:02:16 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id q2so5699559pfh.13; Mon, 17 May 2021 13:02:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=IVIyPTZ6w0h3Ret1w2E/pdnyUaIbFCtkLZj+hGFpk4s=; b=X/xKCa7K0LvTnwJIilIzC4PbSZ3Jyv4ccdvzbTeTE1jp0CSwvEaJQoa1aIQ4US9wBD 5ZtZlpz4h1vu4DczOH0/dLUQGjRsDmU2T/CBSvqNcJTN1dU6oOfQi/1kdHfyIHPloic4 z4OURolq6UZCMn5Y3kZx9BjxlS8+eKZFJ3FyHhqtu6vnRC6riDhJbJngl2CcLUL1ezJi YJfU0bHExh3fUT7JbgrX4jaswiDvuYPqx+IX934+03pywURe+kHy907p0RAlmWJFXd5h QTiwfoA90u9TXBs2NOIozH0xeippZ3xxIKSkh5Jj8cbgvCZotga6xoR/OCkBMxGMk5Ro crNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=IVIyPTZ6w0h3Ret1w2E/pdnyUaIbFCtkLZj+hGFpk4s=; b=joxXkp8WJzcTIP72NbLwKT9UuNy6no86l5jXXfQa7RnaQRT+5QOfkeHUPCj2OL29DW dhNIEGSAae96agA6nO3n4OL/houNj9sYU9BOOtuZDrYDLg0YaTh51RTGj7VlXFdd/Ssp rK1B4eORQ1Ug/NQSrOvTOdO5FzguhI6uyiVIFpDtXifnxuZDjA4cnUf0EoeXGaAFIYPM WEL0UXxQ3PXJ07pmP8/TNBSEuBMxGPWHao2VJEggtyXNp8apeNbUiwvW6rCvGmJ9coIk 6jVwONWpbY2bSnBLDJJORL4CAq3rhlpNyhE7Ji1/pOLsN8bHMvk5Quktpd0wzsmIwaqR eMyQ== X-Gm-Message-State: AOAM5303MBDunb9eW+9FIrj2oee8A3mLnLhmpBipnUfbUP5aKTOk6eth x9SQt+Xr0b8oPBaKJyxHXVE+B8I2PoOby8clWl8= X-Received: by 2002:a05:6a00:1591:b029:2d9:369a:b846 with SMTP id u17-20020a056a001591b02902d9369ab846mr1390908pfk.40.1621281736214; Mon, 17 May 2021 13:02:16 -0700 (PDT) MIME-Version: 1.0 References: <20210516135531.2203-1-dariobin@libero.it> <20210516135531.2203-2-dariobin@libero.it> In-Reply-To: <20210516135531.2203-2-dariobin@libero.it> From: Andy Shevchenko Date: Mon, 17 May 2021 23:02:00 +0300 Message-ID: Subject: Re: [PATCH 1/2] pinctrl: core: configure pinmux from pins debug file To: Dario Binacchi , Drew Fustini Cc: Linux Kernel Mailing List , Linus Walleij , "open list:GPIO SUBSYSTEM" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, May 16, 2021 at 7:43 PM Dario Binacchi wrote: > > The MPUs of some architectures (e.g AM335x) must be in privileged > operating mode to write on the pinmux pinmux is not pin configuration. You need to rethink the approach. > registers. In such cases, where > writes will not work from user space, now it can be done from the pins > debug file if the platform driver exports the pin_dbg_set() helper among > the registered operations. Drew, is it similar to what you are trying to achieve? ... > +static ssize_t pinctrl_pins_write(struct file *file, > + const char __user *user_buf, size_t count, > + loff_t *ppos) > +{ > + struct seq_file *s = file->private_data; > + struct pinctrl_dev *pctldev = s->private; > + const struct pinctrl_ops *ops = pctldev->desc->pctlops; > + char buf[32]; > + char *c = &buf[0]; > + char *token; > + int ret, buf_size; > + unsigned int i, pin; > + > + if (!ops->pin_dbg_set) > + return -EFAULT; > + > + /* Get userspace string and assure termination */ > + buf_size = min(count, sizeof(buf) - 1); > + if (copy_from_user(buf, user_buf, buf_size)) > + return -EFAULT; > + > + buf[buf_size] = 0; Can't you use strncpy_from_user() ? > + token = strsep(&c, " "); > + if (kstrtouint(token, 0, &pin)) > + return -EINVAL; Don't shadow an error code. > + for (i = 0; i < pctldev->desc->npins; i++) { > + if (pin != pctldev->desc->pins[i].number) > + continue; Hmm... I don't get this. Why is it needed? > + ret = ops->pin_dbg_set(pctldev, pin, c); > + if (ret) > + return ret; > + > + return count; > + } > + > + return -EINVAL; > +} ... > - debugfs_create_file("pins", 0444, > + debugfs_create_file("pins", 0644, > device_root, pctldev, &pinctrl_pins_fops); Why is it in this file? -- With Best Regards, Andy Shevchenko