Received: by 10.223.176.46 with SMTP id f43csp676565wra; Fri, 19 Jan 2018 00:05:02 -0800 (PST) X-Google-Smtp-Source: ACJfBosLctipZ0Iz8WZaGE0sAIA/E5F+xJ4sJhOO7xpnbfSeOUJrMrTVegzY3frWyorFR+QLUw6K X-Received: by 10.98.74.20 with SMTP id x20mr18975859pfa.191.1516349102143; Fri, 19 Jan 2018 00:05:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516349102; cv=none; d=google.com; s=arc-20160816; b=em2huo7Op+ldpUpRI2DyB3fY0gG0UT+KpeIbw+xNutTFMkfGdlxeJ4qFQ+axVpicai bKLnLHSggNIgtmOjYhi6b/1pl/UBuPesiTCf0FKR67tsDbajrWkpL6ICI9NSQ2HSZuru rJ2kHpj5M+5rJW0spFdXJzCKGZ7shd0fCVoeNtYWyDPfB6MUwmLzmdT9o8aYbmeWEb36 qoBXW2uSBRUReJjdRQ1C4HQ/WbBmOHAwNhsFTGQ1+dWRO9/FXLC32AEd/qDvdZfEq7Sa BuQs9A5um0wxgFzOhTspvYXToAc2/lIg1yXlaPIi7+Ih2oTAcI2tM5mwT9yRccqq3miN b4yA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=lqzqtBV9kGrSrPST0rne18QdSPyKn5inENXqV/j7PjA=; b=qdn7aSfbfZpTAtfxulFkZistSUjMlRqp5+phkyoCNfQj8Qnk42ALFTXI2aak97pKlJ A+YYil8xCA02Mtx8UlAiRFiLiLjq/mxXnWK1wlmjeHcI5Yzj3cQ8BhcSYgRh1ST4DFDp u3YHGATWbfAJY/PtPELzraQupN8qurJMoiwix+Ol/yvpdSYSeEL+FYIXT2o3b23EfkwB Aeh+1PXpAI+aHUyXkQV9jRnVc+U8W5A2w+GDgKnXEXwIElnnoXKHHQgePOcTb0BZNPUb z1516357aMjN1kJ4biGMV8dhVKZWBTHDtR9NXwaZurHfFPALvfyI6ciJQYpXyowrW2KI Ba9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=PRCGY5XD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t18si7518080pgv.668.2018.01.19.00.04.48; Fri, 19 Jan 2018 00:05:02 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=PRCGY5XD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754796AbeASIDr (ORCPT + 99 others); Fri, 19 Jan 2018 03:03:47 -0500 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:53041 "EHLO out1-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751747AbeASIDk (ORCPT ); Fri, 19 Jan 2018 03:03:40 -0500 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id BB92320AA5; Fri, 19 Jan 2018 03:03:39 -0500 (EST) Received: from frontend1 ([10.202.2.160]) by compute6.internal (MEProxy); Fri, 19 Jan 2018 03:03:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=lqzqtB V9kGrSrPST0rne18QdSPyKn5inENXqV/j7PjA=; b=PRCGY5XD0aj+5k81SzzVNx LuFHS42NbJdCFi90SSauVRFi9vaN0TU3XfQ+vmBHnT0LhYKJaxYhhAnrgMfJb4bV yvdY3guAETP2jRumO5hWCuH4l8Zq9cJpa9Gf+YrR9K69qKhD6WEY7Y8+z0E860dq eeSaOIv/pjgQvPyJV0Y0YNaGMaABm8dnwIyWLxEE/E8GXc/4aMyHDC6gweHWP+NU Gyxi22rQfir3j5skJ48adyuhBZQn7JSdm660UwENkom3cADykWSxD2Ti2EAO4t7D zAo2CxHpTEAQFk1m3eH+H6GzBsNwqqHy61H0h/+KSJlIwrXbhsntok5bZfhsn5uw == X-ME-Sender: Received: from localhost (unknown [185.216.33.115]) by mail.messagingengine.com (Postfix) with ESMTPA id 42B107E3DF; Fri, 19 Jan 2018 03:03:39 -0500 (EST) Date: Fri, 19 Jan 2018 09:03:39 +0100 From: 'Greg KH' To: =?utf-8?B?c2h1ZmFuX2xlZSjmnY7mm7jluIYp?= Cc: ShuFanLee , "heikki.krogerus@linux.intel.com" , =?utf-8?B?Y3lfaHVhbmco6buD5ZWf5Y6fKQ==?= , "linux-kernel@vger.kernel.org" , "linux-usb@vger.kernel.org" Subject: Re: [PATCH] USB TYPEC: RT1711H Type-C Chip Driver Message-ID: <20180119080339.GB31079@kroah.com> References: <1515567552-7692-1-git-send-email-leechu729@gmail.com> <20180117134219.GE3188@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 18, 2018 at 01:13:15PM +0000, shufan_lee(李書帆) wrote: > > + > > +#include "rt1711h.h" > > Why a .h file for a single .c file? > > Is the suggestion to move all content in rt1711h.h into rt1711h.c? If it can be, sure, you only need a .h file for things that are shared among other .c files. > > +/* I2C */ > > +atomic_t i2c_busy; > > +atomic_t pm_suspend; > > Why are these atomic? You know that doesn't mean they do not need locking, right? > > For my understanding, a single operation on atomic_t doesn't need lock, like a single atomic_set. > But two consecutive operations doesn't guarantee anything. Like atomic_set followed by an atomic_read. > This part is referenced from fusb302 used to make sure I2C is idle before system suspends. > It only needs to guarantee a single read/write on these variable is atomic operation, so atomic is used. It's atomic for read/write, yes, but that does not mean it can not be instantly changed after the value is read, right? So you might need to look and ensure you are not doing something wrong that can race. A single lock should be simpler than this type of thing, and will be correct. > > +#ifdef CONFIG_DEBUG_FS > > +struct dentry *dbgdir; > > +struct rt1711h_dbg_info dbg_info[RT1711H_DBG_MAX]; > > +struct dentry *dbg_files[RT1711H_DBG_MAX]; > > +int dbg_regidx; > > +struct mutex dbgops_lock; > > +/* lock for log buffer access */ > > +struct mutex logbuffer_lock; > > +int logbuffer_head; > > +int logbuffer_tail; > > +u8 *logbuffer[LOG_BUFFER_ENTRIES]; > > +#endif /* CONFIG_DEBUG_FS */ > > That's a lot of stuff jsut for debugfs. Why do you care about #define at all? The code should not. > > Is the suggestion to remove #ifdef CONFIG_DEBUG_FS? Yes. Or just move it all to another structure that you can dynamically add to this one if needed. > And another 2 locks? Ick, no. > > dbgops_lock is used to prevent user from accessing different debug files simultaneously. > Is the suggestion to use the lock of the following one? > > +/* lock for sharing chip states */ > > +struct mutex lock; Sure, why not? > ======================================================================== > > > +snprintf(dirname, len + 9, "rt1711h-%s", dev_name(chip->dev)); > > +if (!chip->dbgdir) { > > +chip->dbgdir = debugfs_create_dir(dirname, NULL); > > +if (!chip->dbgdir) > > +return -ENOMEM; > > No need to ever check the return value of debugfs_ calls, you should not care and can always use the value to any future debugfs calls, if you really need it. > > If it is NULL without checking and we use it in debugfs_create_file, all the debug files will be created in the root of the debugfs filesystem. > Is this correct? If it returns NULL then any future calls to debugfs will also not be working, so all will be fine. So there is no need to check this. > ======================================================================== > > > +for (i = 0; i < RT1711H_DBG_MAX; i++) { > > +info = &chip->dbg_info[i]; > > static array of debug info? That feels odd. > > Is the suggestion to use pointer of array and dynamically allocated it? If that makes more sense, it's up to you. Just a suggestion. thanks, greg k-h