Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp956332pxb; Wed, 3 Mar 2021 22:27:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJwGJnt+LwzJRLnX7Cu4IaX83SpMx6vU1elxFtoZa1d/w9aAm89TR582TEq4u+Bp511307j/ X-Received: by 2002:a17:906:9386:: with SMTP id l6mr2443546ejx.455.1614839228519; Wed, 03 Mar 2021 22:27:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614839228; cv=none; d=google.com; s=arc-20160816; b=Ekh4jZAvxnGW7Rcu3MaSKHeEw/OgJGgHzQqf/YwlUB7M+bG/DT9NNiMMAdjGnr4qA+ X02YXjM0kzFAtBZ/2skNo1UYsDAftabq4ePsYh8OYSR495WY83BPwlC/vNbf+8/wNRhN fRxU1IkCXoASxDSIDVlflwmFw/C6wPUkLtU1X+BnVS/OkMW//IEVDN23oGcvJYn6CIDk we6JQ7nxBLm2WiaTKOm06hoeW3BfGKJ62mkGAfDrs0AyTCqBwL6MUuiuaTpMOUKPhUiq vWRGA7HG30EY5R60/GSTeXVXeLIwzDi168Pz+ySxX+xZILTLBIeGsKbA5a5m/aIrxmCL Z7Xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:user-agent:references:in-reply-to :subject:cc:to:from:date:content-transfer-encoding:mime-version :dkim-signature; bh=mTtVJwCrMEqy04BVWxGgfe8sOuG6CbjO06VOyD60coI=; b=hQt6YQ8/+J/f1d7PrR2ojM+hXoJBVwmss2jYZ0ciiCKsnTsmy/cRPlvOK7HiAdSUDn HlXpztVJMzy9Rw5p99t1aqxXi4lirqL23qmjNCArDfK29j0fot3I7pVp93ZSOLqlwU+V tFVYcJ0rdfPOReJvJ1kzeJzQqBZRgIenLuAJuGlftqsPl+vQMnB6EnNUsv8iwZg7h6A1 e1OECZ/9lz/Z2CWbK0081VYsAH+2s+05N0vF+25TDrfziqwTkt72IAFn3f3hWQYTqUzH fmfjO138sO6akpz0WrkUs5DuPSAeYAcGTBDWYgqi4AhZfUx6LubGFrvRAIc768XouP8i bStw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2016061301 header.b=N1jbqwuL; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l1si15895013ejb.137.2021.03.03.22.26.46; Wed, 03 Mar 2021 22:27:08 -0800 (PST) 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=@walle.cc header.s=mail2016061301 header.b=N1jbqwuL; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1575835AbhCBPor (ORCPT + 99 others); Tue, 2 Mar 2021 10:44:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1446119AbhCBNQl (ORCPT ); Tue, 2 Mar 2021 08:16:41 -0500 Received: from ssl.serverraum.org (ssl.serverraum.org [IPv6:2a01:4f8:151:8464::1:2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1A7AC061756; Tue, 2 Mar 2021 05:06:35 -0800 (PST) Received: from ssl.serverraum.org (web.serverraum.org [172.16.0.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id E185F2223E; Tue, 2 Mar 2021 14:06:33 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1614690394; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mTtVJwCrMEqy04BVWxGgfe8sOuG6CbjO06VOyD60coI=; b=N1jbqwuLG9dlRICo7gv/InhS3T3Z95hbPGXGxPecFPDxLjOzwAI+8oh76X1nIWpyGQ2wmh OjSHejnJe9fVnQlH2KmDVlcC0agYzilguPEGV3Cdql6nJfCD+mnu+UXiMaR8uX6lTzbNV1 ihERZ3CaUUAkTDmpjPY6Im1R8EIIm9o= MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Tue, 02 Mar 2021 14:06:33 +0100 From: Michael Walle To: Miquel Raynal Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, Richard Weinberger , Vignesh Raghavendra , Tudor.Ambarus@microchip.com Subject: Re: [RFC PATCH] mtd: add OTP (one-time-programmable) erase ioctl In-Reply-To: <20210302134617.5aa78cc4@xps13> References: <20210302110927.6520-1-michael@walle.cc> <20210302134617.5aa78cc4@xps13> User-Agent: Roundcube Webmail/1.4.11 Message-ID: <05c255e6d9d8d12e8e6af59d9c153981@walle.cc> X-Sender: michael@walle.cc Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Am 2021-03-02 13:46, schrieb Miquel Raynal: > Michael Walle wrote on Tue, 2 Mar 2021 12:09:27 > +0100: > >> This may sound like a contradiction but some SPI-NOR flashes really >> support erasing their OTP region until it is finally locked. Having >> the >> possibility to erase an OTP region might come in handy during >> development. >> >> The ioctl argument follows the OTPLOCK style. >> >> Signed-off-by: Michael Walle >> --- >> OTP support for SPI-NOR flashes may be merged soon: >> https://lore.kernel.org/linux-mtd/20210216162807.13509-1-michael@walle.cc/ >> >> Tudor suggested to add support for the OTP erase operation most >> SPI-NOR >> flashes have: >> https://lore.kernel.org/linux-mtd/d4f74b1b-fa1b-97ec-858c-d807fe1f9e57@microchip.com/ >> >> Therefore, this is an RFC to get some feedback on the MTD side, once >> this >> is finished, I can post a patch for mtd-utils. Then we'll have a >> foundation >> to add the support to SPI-NOR. >> [..] >> +int mtd_erase_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t >> len) >> +{ >> + struct mtd_info *master = mtd_get_master(mtd); >> + >> + if (!master->_erase_user_prot_reg) >> + return -EOPNOTSUPP; >> + if (!len) >> + return 0; > > Should we add a sanity check enforcing that we don't try to access > beyond the end of the OTP area? This is checked in the op itself, as it is done for all the other OTP read/write/lock ops. Right at the moment, I don't see how this could be achieved in an elegant way. Without additional changes, you'd have to call mtd_get_user_prot_info() and iterate over the returned values and figure out whether from and len are valid. [..] -michael