From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A608E280024 for ; Wed, 26 Nov 2025 13:42:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764164527; cv=none; b=npIprccJ2R/60nW5mf5/agJiPTBpkGVsJiM894wI2N3BZ8Y1/KGRMSVDAIBYjWbetPiQPve/QiT5cId3BQKZRCHoifIlB6dEFKxTVENgy3NyjAu2fb6iGnTnCezWlCIlD+OQdkGwakgt3zvgMaSCkxXHAUYNrB2iU4FbOrY1lmY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764164527; c=relaxed/simple; bh=Ay5uhr+OGodg/D8kiyRKpx80qA4d1CaQM4U9NXPT0F0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=m6n4vKlTJponODQ+e831L3prQzujjCcUJDHjm+uuejhmXVaeToPu9PSjeNA5Q7N/+nuq3FAzModN+fkLlEEO98tytvn6AelKsVq9n50RnCU6lTdRcfqd9ZJbxAwmr0a2lYMGgJE32x7Foiti/xZsI2RKLesE0MKJiPHj4OoWUwM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=F5m36lk4; arc=none smtp.client-ip=198.175.65.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="F5m36lk4" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1764164525; x=1795700525; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=Ay5uhr+OGodg/D8kiyRKpx80qA4d1CaQM4U9NXPT0F0=; b=F5m36lk4wSgKhqlKxtqnLFJy9PwSUBAEmEXrbtY4uMQh42zIgEoRV/rE uzzyl6tfr2vJ75fOt+CFv6hYvD7ECDeOsL4/dkpRStrJSqvtP2vsAqlKK E/ZibIkldhNYFoJDAP0ew+5d8oaD+P1Q1DzzueCqYvTsOP3fsiYM7mKf2 DdBdoP4HIjfTLeVakU3D3G5KvvGumxgXTE/Dq+XOcGd6qX55oIN/sclFC 27v6VtcUe1kECxC8ZUsPV23fwNCQ9GoWt+A7ZODDzpC75eBftxWD5w4jM t1FW+JRhTqKDcB1iCETsTgoLNn49csqBD7qyRQV/CRLav1WNKr9KlGxLc w==; X-CSE-ConnectionGUID: rU42ERv6QfeyVc1mZSs7Hg== X-CSE-MsgGUID: JOJIhj/gRmOSy+WdHHa72A== X-IronPort-AV: E=McAfee;i="6800,10657,11624"; a="77675222" X-IronPort-AV: E=Sophos;i="6.20,228,1758610800"; d="scan'208";a="77675222" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Nov 2025 05:42:04 -0800 X-CSE-ConnectionGUID: DeVFkYwwSIKheZf5B3uWBA== X-CSE-MsgGUID: cAvGYbpuToWIvYVgytSaNw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.20,228,1758610800"; d="scan'208";a="198051621" Received: from black.igk.intel.com ([10.91.253.5]) by orviesa005.jf.intel.com with ESMTP; 26 Nov 2025 05:42:04 -0800 Received: by black.igk.intel.com (Postfix, from userid 1003) id A439DA0; Wed, 26 Nov 2025 14:42:02 +0100 (CET) Date: Wed, 26 Nov 2025 14:42:02 +0100 From: Andy Shevchenko To: srini@kernel.org Cc: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, Heiko Stuebner Subject: Re: [PATCH 3/8] nvmem: Add driver for the eeprom in qnap-mcu controllers Message-ID: References: <20251114110636.143268-1-srini@kernel.org> <20251114110636.143268-4-srini@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20251114110636.143268-4-srini@kernel.org> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo On Fri, Nov 14, 2025 at 11:06:31AM +0000, srini@kernel.org wrote: > > The qnap-mcu also has an eeprom connected to it, that contains some > specific product-information like the mac addresses for the network > interfaces. > > Add a nvmem driver for it. I have no problem with current code, but below some hints in case you want to improve it. ... + device.h + err.h > +#include > +#include > +#include > +#include > +#include + string.h + types.h ... > +static int qnap_mcu_eeprom_read_block(struct qnap_mcu *mcu, unsigned int offset, > + void *val, size_t bytes) > +{ > + const u8 cmd[] = { 0xf7, 0xa1, offset, bytes }; > + u8 *reply; > + int ret = 0; > + > + reply = kzalloc(bytes + sizeof(cmd), GFP_KERNEL); > + if (!reply) > + return -ENOMEM; Using __free() from cleanup.h actually fits here and makes code easier to read. > + ret = qnap_mcu_exec(mcu, cmd, sizeof(cmd), reply, bytes + sizeof(cmd)); > + if (ret) > + goto out; > + > + /* First bytes must mirror the sent command */ > + if (memcmp(cmd, reply, sizeof(cmd))) { > + ret = -EIO; > + goto out; > + } > + > + memcpy(val, reply + sizeof(cmd), bytes); > + > +out: > + kfree(reply); > + return ret; > +} ... > +static int qnap_mcu_eeprom_probe(struct platform_device *pdev) > +{ struct device *parent = pdev->dev.parent; > + struct qnap_mcu *mcu = dev_get_drvdata(pdev->dev.parent); struct qnap_mcu *mcu = dev_get_drvdata(parent); > + struct nvmem_config nvcfg = {}; > + struct nvmem_device *ndev; > + > + nvcfg.dev = &pdev->dev; > + nvcfg.of_node = pdev->dev.parent->of_node; nvcfg.of_node = dev_of_node(parent); (will need to include of.h, but ideally nvmem can be switched to fwnode) > + nvcfg.name = dev_name(&pdev->dev); > + nvcfg.id = NVMEM_DEVID_NONE; > + nvcfg.owner = THIS_MODULE; > + nvcfg.type = NVMEM_TYPE_EEPROM; > + nvcfg.read_only = true; > + nvcfg.root_only = false; > + nvcfg.reg_read = qnap_mcu_eeprom_read; > + nvcfg.size = QNAP_MCU_EEPROM_SIZE, > + nvcfg.word_size = 1, > + nvcfg.stride = 1, > + nvcfg.priv = mcu, > + > + ndev = devm_nvmem_register(&pdev->dev, &nvcfg); > + if (IS_ERR(ndev)) > + return PTR_ERR(ndev); > + > + return 0; retrun PTR_ERR_OR_ZERO(...); > +} -- With Best Regards, Andy Shevchenko