Re: [Outreachy kernel] Re: [PATCH 1/2 v2] staging: media: hantro: Align line break to the open parenthesis in file hantro_hw.h

2021-04-09 Thread Vaishali Thakkar
On Thu, Apr 8, 2021 at 7:41 PM ascordeiro
 wrote:
>
> Em qui, 2021-04-08 às 13:20 -0300, Ezequiel Garcia escreveu:
> > Ola Aline,
> Ola Ezequiel,
>
> > Welcome to the kernel community. Hope you enjoy some of this
> > Outreachy adventures.
> Thank you!
>
> > Normally, when you submit a v2, we want to know what changed
> > between the first submission and v2.
> >
> > If you are subscribed to linux-media, you can read some
> > of the series with a vN+1 and look how it's done. Examples:
> >
> > https://www.spinics.net/lists/linux-media/msg190043.html
> >
> > https://www.spinics.net/lists/linux-media/msg189923.html
> >
> > I'm sure your Outreachy mentors can tell you more.
> Thank you for the examples, it won't happen again.
>
> The reason for sending a v2 is that I sent my very first patchset
> yesterday and I sent the cover-letter together, but (I think) I wasn't
> supposed to, and as the patches weren't marked as [PATCH 1/2] and
> [PATCH 2/2] in the email - since I commited all the files with the same
> message - I tought it was wrong and sent again today.
>
> However, I just realized that I've changed just the subject of the e-
> mail, but I would've to change the commit message, right? And then, it
> would be a second version, am I right?

Your next version should be v3 with information about changes since
v1 under --- . If you send it with v2, it'll still be confusing for people
because then they have to manually find out the difference between
two different patchsets with the same subject line. :)

You can also check 'Revising your patches' section in the tutorial.

> Thank you in advance,
>
> > On Thu, 2021-04-08 at 11:07 -0300, Aline Santana Cordeiro wrote:
> > > Aligns line break with the remaining function arguments
> > > to the open parenthesis. Issue found by checkpatch.
> > >
> > > Signed-off-by: Aline Santana Cordeiro <
> > > alinesantanacorde...@gmail.com>
> > > ---
> > >  drivers/staging/media/hantro/hantro_hw.h | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/staging/media/hantro/hantro_hw.h
> > > b/drivers/staging/media/hantro/hantro_hw.h
> > > index 34c9e46..a650b9c 100644
> > > --- a/drivers/staging/media/hantro/hantro_hw.h
> > > +++ b/drivers/staging/media/hantro/hantro_hw.h
> > > @@ -207,7 +207,7 @@ hantro_h264_mv_size(unsigned int width,
> > > unsigned int height)
> > >  void hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx);
> > >  void rk3399_vpu_mpeg2_dec_run(struct hantro_ctx *ctx);
> > >  void hantro_mpeg2_dec_copy_qtable(u8 *qtable,
> > > -   const struct v4l2_ctrl_mpeg2_quantization *ctrl);
> > > + const struct
> > > v4l2_ctrl_mpeg2_quantization *ctrl);
> > >  int hantro_mpeg2_dec_init(struct hantro_ctx *ctx);
> > >  void hantro_mpeg2_dec_exit(struct hantro_ctx *ctx);
> > >
> >
> >
>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "outreachy-kernel" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to outreachy-kernel+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/outreachy-kernel/6bba0e0a5768e902ffec4bda563d4ca810412f84.camel%40gmail.com.



-- 
Vaishali


Re: [Outreachy kernel] [PATCH v3] staging: rtl8723bs: hal: Remove camelcase in Hal8723BReg.h

2021-04-07 Thread Vaishali Thakkar
On Wed, Apr 7, 2021 at 10:49 AM Fabio M. De Francesco
 wrote:
>
> On Wednesday, April 7, 2021 10:18:13 AM CEST Greg KH wrote:
> > On Tue, Apr 06, 2021 at 06:00:37PM +0200, Fabio M. De Francesco wrote:
> > > Remove camelcase in some symbols defined in Hal8723BReg.h. These symbols
> > > are not used anywhere else, therefore this patch does not break the 
> > > driver.
> > >
> > > Signed-off-by: Fabio M. De Francesco 
> > > ---
> > >
> > > Patch v3 changes nothing with respect to v2 and v1. It exists only to cc 
> > > some recipients that were missing in the header of the previous email.
> > >
> > >  drivers/staging/rtl8723bs/hal/Hal8723BReg.h | 16 
> > >  1 file changed, 8 insertions(+), 8 deletions(-)
> >
> > This patch does not apply to my tree right now.  Can you refresh and
> > rebase your copy of my branch and rebase it and resend?
> >
> Sure. I'm about to submit that patch again in a few minutes.

Also while you're at it, don't forget to put the information under -- about
what has changed since the first version of it. Otherwise it becomes
hard for the reviewers to track the progress of each version.

Ideally it should go like below:

Changes since v2:
Changes since v1:

> Thanks,
>
> Fabio
> >
> > thanks,
> >
> > greg k-h
> >
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "outreachy-kernel" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to outreachy-kernel+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/outreachy-kernel/3526833.TqPzfDAv2q%40localhost.localdomain.



-- 
Vaishali


Re: [Outreachy kernel] [PATCH] staging: iio: cdc: remove repeated word

2021-04-05 Thread Vaishali Thakkar
On Mon, Apr 5, 2021 at 12:24 AM David Villasana Jiménez
 wrote:
>
> Fix checkpatch warning:
> WARNING: Possible repeated word: 'from'

You don't need to include the checkpatch warning in the commit log.
Your commit log should just be able to give enough information about
why you're doing this change. Then you can give credit to the tool by
adding a line like this:  'Issue found by checkpatch.pl'.

> Signed-off-by: David Villasana Jiménez 
> ---
>  drivers/staging/iio/cdc/ad7150.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/staging/iio/cdc/ad7150.c 
> b/drivers/staging/iio/cdc/ad7150.c
> index 48132ab157ef..1be214512ff8 100644
> --- a/drivers/staging/iio/cdc/ad7150.c
> +++ b/drivers/staging/iio/cdc/ad7150.c
> @@ -57,7 +57,7 @@
>   * @threshold: thresholds for simple capacitance value events
>   * @thresh_sensitivity: threshold for simple capacitance offset
>   * from 'average' value.
> - * @mag_sensitity: threshold for magnitude of capacitance offset from
> + * @mag_sensitity: threshold for magnitude of capacitance offset
>   * from 'average' value.
>   * @thresh_timeout: a timeout, in samples from the moment an
>   * adaptive threshold event occurs to when the average
> --
> 2.30.2
>
> --
> You received this message because you are subscribed to the Google Groups 
> "outreachy-kernel" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to outreachy-kernel+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/outreachy-kernel/YGo8q4R5dqgtDMlg%40fedora.



-- 
Vaishali


Re: [PATCH v2] soc: qcom: socinfo: Annotate switch cases with fall through

2019-08-06 Thread Vaishali Thakkar
On Wed, 7 Aug 2019 at 07:54, Bjorn Andersson  wrote:
>
> Introduce fall through annotations in the switch statements of
> socinfo_debugfs_init() to silence compiler warnings.

Oops, I missed this. Thanks for fixing it!

> Fixes: 9c84c1e78634 ("soc: qcom: socinfo: Expose custom attributes")
> Reported-by: Stephen Rothwell 
> Signed-off-by: Bjorn Andersson 

Acked-by: Vaishali Thakkar 

> ---
>  drivers/soc/qcom/socinfo.c | 8 
>  1 file changed, 8 insertions(+)
>
> diff --git a/drivers/soc/qcom/socinfo.c b/drivers/soc/qcom/socinfo.c
> index 855353bed19e..a39ea5061dc5 100644
> --- a/drivers/soc/qcom/socinfo.c
> +++ b/drivers/soc/qcom/socinfo.c
> @@ -323,6 +323,7 @@ static void socinfo_debugfs_init(struct qcom_socinfo 
> *qcom_socinfo,
> debugfs_create_x32("raw_device_number", 0400,
>qcom_socinfo->dbg_root,
>_socinfo->info.raw_device_num);
> +   /* Fall through */
> case SOCINFO_VERSION(0, 11):
> case SOCINFO_VERSION(0, 10):
> case SOCINFO_VERSION(0, 9):
> @@ -330,10 +331,12 @@ static void socinfo_debugfs_init(struct qcom_socinfo 
> *qcom_socinfo,
>
> debugfs_create_u32("foundry_id", 0400, qcom_socinfo->dbg_root,
>_socinfo->info.foundry_id);
> +   /* Fall through */
> case SOCINFO_VERSION(0, 8):
> case SOCINFO_VERSION(0, 7):
> DEBUGFS_ADD(info, pmic_model);
> DEBUGFS_ADD(info, pmic_die_rev);
> +   /* Fall through */
> case SOCINFO_VERSION(0, 6):
> qcom_socinfo->info.hw_plat_subtype =
> __le32_to_cpu(info->hw_plat_subtype);
> @@ -341,6 +344,7 @@ static void socinfo_debugfs_init(struct qcom_socinfo 
> *qcom_socinfo,
> debugfs_create_u32("hardware_platform_subtype", 0400,
>qcom_socinfo->dbg_root,
>_socinfo->info.hw_plat_subtype);
> +   /* Fall through */
> case SOCINFO_VERSION(0, 5):
> qcom_socinfo->info.accessory_chip =
> __le32_to_cpu(info->accessory_chip);
> @@ -348,23 +352,27 @@ static void socinfo_debugfs_init(struct qcom_socinfo 
> *qcom_socinfo,
> debugfs_create_u32("accessory_chip", 0400,
>qcom_socinfo->dbg_root,
>_socinfo->info.accessory_chip);
> +   /* Fall through */
> case SOCINFO_VERSION(0, 4):
> qcom_socinfo->info.plat_ver = __le32_to_cpu(info->plat_ver);
>
> debugfs_create_u32("platform_version", 0400,
>qcom_socinfo->dbg_root,
>_socinfo->info.plat_ver);
> +   /* Fall through */
> case SOCINFO_VERSION(0, 3):
> qcom_socinfo->info.hw_plat = __le32_to_cpu(info->hw_plat);
>
> debugfs_create_u32("hardware_platform", 0400,
>qcom_socinfo->dbg_root,
>_socinfo->info.hw_plat);
> +   /* Fall through */
> case SOCINFO_VERSION(0, 2):
> qcom_socinfo->info.raw_ver  = __le32_to_cpu(info->raw_ver);
>
> debugfs_create_u32("raw_version", 0400, 
> qcom_socinfo->dbg_root,
>_socinfo->info.raw_ver);
> +   /* Fall through */
> case SOCINFO_VERSION(0, 1):
> DEBUGFS_ADD(info, build_id);
> break;
> --
> 2.18.0
>


[PATCH v6 3/5] soc: qcom: Add socinfo driver

2019-07-23 Thread Vaishali Thakkar
From: Imran Khan 

The Qualcomm socinfo driver exposes information about the SoC, its
version and its serial number to user space.

Signed-off-by: Imran Khan 
[Bjorn: Extract code to platform_driver, split patch in multiple]
Signed-off-by: Bjorn Andersson 
[Vaishali: Simplify declarations, introduce qcom_socinfo struct, Fix
   memory leak, Remove extra code and Misc code refactoring]
Signed-off-by: Vaishali Thakkar 
---
Changes since v5:
-No code changes, fix diff.context setting for formatting
 patches. Version 5 was adding context at the bottom of
 the file with 'git am'.
Changes since v4:
- Return PTR_ERR in qcom_socinfo_probe instead of error value
- Return PTR_ERR in smem probe to print proper error message
  when we fail to register the socinfo device
- Use dev_dbg instead of dev_err in qcom_smem_probe
- Use offset_of for exposing the value of serial_number
- Unregister the platform device in smem remove function
- Drop error message in socinfo_machine
- Misc: Add spaces between brackets and strings/numbers in
soc_of_id, item ids->item id, socinfo->SoCinfo,
soc_of_id->soc_id
Changes since v3:
- None
Changes since v2:
- Fix typo in the work log under signed off by s
Changes since v1:
- None
---
 drivers/soc/qcom/Kconfig   |   8 ++
 drivers/soc/qcom/Makefile  |   1 +
 drivers/soc/qcom/smem.c|   9 ++
 drivers/soc/qcom/socinfo.c | 194 +
 4 files changed, 212 insertions(+)
 create mode 100644 drivers/soc/qcom/socinfo.c

diff --git a/drivers/soc/qcom/Kconfig b/drivers/soc/qcom/Kconfig
index a6d1bfb17279..661e47acc354 100644
--- a/drivers/soc/qcom/Kconfig
+++ b/drivers/soc/qcom/Kconfig
@@ -175,6 +175,14 @@ config QCOM_SMSM
  Say yes here to support the Qualcomm Shared Memory State Machine.
  The state machine is represented by bits in shared memory.
 
+config QCOM_SOCINFO
+   tristate "Qualcomm socinfo driver"
+   depends on QCOM_SMEM
+   select SOC_BUS
+   help
+Say yes here to support the Qualcomm socinfo driver, providing
+information about the SoC to user space.
+
 config QCOM_WCNSS_CTRL
tristate "Qualcomm WCNSS control driver"
depends on ARCH_QCOM || COMPILE_TEST
diff --git a/drivers/soc/qcom/Makefile b/drivers/soc/qcom/Makefile
index eeb088beb15f..162788701a77 100644
--- a/drivers/soc/qcom/Makefile
+++ b/drivers/soc/qcom/Makefile
@@ -18,6 +18,7 @@ obj-$(CONFIG_QCOM_SMEM) +=smem.o
 obj-$(CONFIG_QCOM_SMEM_STATE) += smem_state.o
 obj-$(CONFIG_QCOM_SMP2P)   += smp2p.o
 obj-$(CONFIG_QCOM_SMSM)+= smsm.o
+obj-$(CONFIG_QCOM_SOCINFO) += socinfo.o
 obj-$(CONFIG_QCOM_WCNSS_CTRL) += wcnss_ctrl.o
 obj-$(CONFIG_QCOM_APR) += apr.o
 obj-$(CONFIG_QCOM_LLCC) += llcc-slice.o
diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c
index f27c00d82ae4..0caf67e2f037 100644
--- a/drivers/soc/qcom/smem.c
+++ b/drivers/soc/qcom/smem.c
@@ -268,6 +268,7 @@ struct qcom_smem {
struct smem_partition_header *partitions[SMEM_HOST_COUNT];
size_t cacheline[SMEM_HOST_COUNT];
u32 item_count;
+   struct platform_device *socinfo;
 
unsigned num_regions;
struct smem_region regions[];
@@ -963,11 +964,19 @@ static int qcom_smem_probe(struct platform_device *pdev)
 
__smem = smem;
 
+   smem->socinfo = platform_device_register_data(>dev, 
"qcom-socinfo",
+ PLATFORM_DEVID_NONE, NULL,
+ 0);
+   if (IS_ERR(smem->socinfo))
+   dev_dbg(>dev, "failed to register socinfo device\n");
+
return 0;
 }
 
 static int qcom_smem_remove(struct platform_device *pdev)
 {
+   platform_device_unregister(__smem->socinfo);
+
hwspin_lock_free(__smem->hwlock);
__smem = NULL;
 
diff --git a/drivers/soc/qcom/socinfo.c b/drivers/soc/qcom/socinfo.c
new file mode 100644
index ..1b9eb44df7fe
--- /dev/null
+++ b/drivers/soc/qcom/socinfo.c
@@ -0,0 +1,194 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2009-2017, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2017-2019, Linaro Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * SoC version type with major number in the upper 16 bits and minor
+ * number in the lower 16 bits.
+ */
+#define SOCINFO_MAJOR(ver) (((ver) >> 16) & 0x)
+#define SOCINFO_MINOR(ver) ((ver) & 0x)
+
+#define SMEM_SOCINFO_BUILD_ID_LENGTH   32
+
+/*
+ * SMEM item id, used to acquire handles to respective
+ * SMEM region.
+ */
+#define SMEM_HW_SW_BUILD_ID137
+
+/* Socinfo SMEM item structure */
+struct socinfo {
+   __le32 fmt;
+   __le32 id;
+   __le

[PATCH v6 5/5] soc: qcom: socinfo: Expose image information

2019-07-23 Thread Vaishali Thakkar
The socinfo driver provides information about version of the various
images loaded in the system. Expose this to user space for debugging
purpose.

Signed-off-by: Vaishali Thakkar 
---
Changes since v5:
- No code changes, fix diff.context setting for formatting
  patches. Version 5 was adding context at the bottom of
  the file with 'git am'.
Changes since v4:
- Reduce number of duplicate image macros and functions
- Introduce array for image info debugfs entries and use it
  instead of open coding
Changes since v3:
- Remove extra debugfs directory creation checks
Changes since v2:
- None
Changes since v1:
- None
---
 drivers/soc/qcom/socinfo.c | 84 ++
 1 file changed, 84 insertions(+)

diff --git a/drivers/soc/qcom/socinfo.c b/drivers/soc/qcom/socinfo.c
index 6a4795433d57..855353bed19e 100644
--- a/drivers/soc/qcom/socinfo.c
+++ b/drivers/soc/qcom/socinfo.c
@@ -32,6 +32,39 @@
 #define SMEM_HW_SW_BUILD_ID137
 
 #ifdef CONFIG_DEBUG_FS
+#define SMEM_IMAGE_VERSION_BLOCKS_COUNT32
+#define SMEM_IMAGE_VERSION_SIZE4096
+#define SMEM_IMAGE_VERSION_NAME_SIZE   75
+#define SMEM_IMAGE_VERSION_VARIANT_SIZE20
+#define SMEM_IMAGE_VERSION_OEM_SIZE32
+
+/*
+ * SMEM Image table indices
+ */
+#define SMEM_IMAGE_TABLE_BOOT_INDEX 0
+#define SMEM_IMAGE_TABLE_TZ_INDEX   1
+#define SMEM_IMAGE_TABLE_RPM_INDEX  3
+#define SMEM_IMAGE_TABLE_APPS_INDEX 10
+#define SMEM_IMAGE_TABLE_MPSS_INDEX 11
+#define SMEM_IMAGE_TABLE_ADSP_INDEX 12
+#define SMEM_IMAGE_TABLE_CNSS_INDEX 13
+#define SMEM_IMAGE_TABLE_VIDEO_INDEX14
+#define SMEM_IMAGE_VERSION_TABLE   469
+
+/*
+ * SMEM Image table names
+ */
+static const char *const socinfo_image_names[] = {
+   [SMEM_IMAGE_TABLE_ADSP_INDEX] = "adsp",
+   [SMEM_IMAGE_TABLE_APPS_INDEX] = "apps",
+   [SMEM_IMAGE_TABLE_BOOT_INDEX] = "boot",
+   [SMEM_IMAGE_TABLE_CNSS_INDEX] = "cnss",
+   [SMEM_IMAGE_TABLE_MPSS_INDEX] = "mpss",
+   [SMEM_IMAGE_TABLE_RPM_INDEX] = "rpm",
+   [SMEM_IMAGE_TABLE_TZ_INDEX] = "tz",
+   [SMEM_IMAGE_TABLE_VIDEO_INDEX] = "video",
+};
+
 static const char *const pmic_models[] = {
[0]  = "Unknown PMIC model",
[9]  = "PM8994",
@@ -103,6 +136,13 @@ struct socinfo_params {
u32 hw_plat;
u32 fmt;
 };
+
+struct smem_image_version {
+   char name[SMEM_IMAGE_VERSION_NAME_SIZE];
+   char variant[SMEM_IMAGE_VERSION_VARIANT_SIZE];
+   char pad;
+   char oem[SMEM_IMAGE_VERSION_OEM_SIZE];
+};
 #endif /* CONFIG_DEBUG_FS */
 
 struct qcom_socinfo {
@@ -230,10 +270,37 @@ QCOM_OPEN(build_id, qcom_show_build_id);
 QCOM_OPEN(pmic_model, qcom_show_pmic_model);
 QCOM_OPEN(pmic_die_rev, qcom_show_pmic_die_revision);
 
+#define DEFINE_IMAGE_OPS(type) \
+static int show_image_##type(struct seq_file *seq, void *p)  \
+{\
+   struct smem_image_version *image_version = seq->private;  \
+   seq_puts(seq, image_version->type);   \
+   seq_puts(seq, "\n");  \
+   return 0; \
+}\
+static int open_image_##type(struct inode *inode, struct file *file) \
+{\
+   return single_open(file, show_image_##type, inode->i_private); \
+}\
+ \
+static const struct file_operations qcom_image_##type##_ops = {  \
+   .open = open_image_##type,\
+   .read = seq_read, \
+   .llseek = seq_lseek,  \
+   .release = single_release,\
+}
+
+DEFINE_IMAGE_OPS(name);
+DEFINE_IMAGE_OPS(variant);
+DEFINE_IMAGE_OPS(oem);
+
 static void socinfo_debugfs_init(struct qcom_socinfo *qcom_socinfo,
 struct socinfo *info)
 {
+   struct smem_image_version *versions;
+   struct dentry *dentry;
size_t size;
+   int i;
 
qcom_socinfo->dbg_root = debugfs_create_dir("qcom_socinfo", NULL);
 
@@ -302,6 +369,23 @@ static void socinfo_debugfs_init(struct qcom_socinfo 
*qcom_socinfo,
DEBUGFS_ADD(info, build_id);
break;
}
+
+   versions = qcom_smem_get(QCOM_SMEM_HOST_ANY, SMEM_IMAGE_VERSION_TABLE,
+);
+
+   f

[PATCH v6 2/5] base: soc: Export soc_device_register/unregister APIs

2019-07-23 Thread Vaishali Thakkar
From: Vinod Koul 

Qcom Socinfo driver can be built as a module, so
export these two APIs.

Signed-off-by: Vinod Koul 
Signed-off-by: Vaishali Thakkar 
Reviewed-by: Greg Kroah-Hartman 
Reviewed-by: Stephen Boyd 
Reviewed-by: Bjorn Andersson 
---
Changes since v5:
- No code changes, fix diff.context setting for formatting
  patches. Version 5 was adding context at the bottom of
  the file with 'git am'.
Changes since v4:
- Add Bjorn and Stephen's Reviewed-by
Changes since v3:
- Add Greg's Reviewed-by
Changes since v2:
- None
Changes since v1:
- Make comment more clear for the case when serial
  number is not available
---
 drivers/base/soc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/base/soc.c b/drivers/base/soc.c
index b0933b9fe67f..7c0c5ca5953d 100644
--- a/drivers/base/soc.c
+++ b/drivers/base/soc.c
@@ -164,6 +164,7 @@ struct soc_device *soc_device_register(struct 
soc_device_attribute *soc_dev_attr
 out1:
return ERR_PTR(ret);
 }
+EXPORT_SYMBOL_GPL(soc_device_register);
 
 /* Ensure soc_dev->attr is freed prior to calling soc_device_unregister. */
 void soc_device_unregister(struct soc_device *soc_dev)
@@ -173,6 +174,7 @@ void soc_device_unregister(struct soc_device *soc_dev)
device_unregister(_dev->dev);
early_soc_dev_attr = NULL;
 }
+EXPORT_SYMBOL_GPL(soc_device_unregister);
 
 static int __init soc_bus_register(void)
 {
-- 
2.17.1



[PATCH v6 4/5] soc: qcom: socinfo: Expose custom attributes

2019-07-23 Thread Vaishali Thakkar
The Qualcomm socinfo provides a number of additional attributes,
add these to the socinfo driver and expose them via debugfs
functionality.

Signed-off-by: Vaishali Thakkar 
---
Changes since v5:
- No code changes, fix my diff.context setting for formatting
  patches. Version 5 was adding context at the bottom of
  the file with 'git am'.
Changes since v4:
- Introduce socinfo_params and use create_debugfs_{u32,x32}
  instead of driver specific macros
- Remove some unnecessary separate functions
  [qcom_show_{platform_subtype,accessory_chip}] and use
  debugfs core functions to expose their values
- Use switch to expose custom attributes based on the
  firmware version
- Misc: Drop unnecessory comments, pmic_model->pmic_models,
don't pass socinfo pointer in qcom_socinfo
- Note: I didn't introduce any new debugfs core functions
for printing string values because it wasn't
possible to cover both cases of string arrays in this
file - pmic_model and build_id by introducing a single
function. Morever, I still needed QCOM_OPEN and DEBUGFS_ADD
to cover the case of pmic_die_rev so introducing the
'debugfs create string array function' wasn't completely
eliminating extra macro code. So, I'm just using the
above mentioned macros to print string array values for
now. Feel free to on this matter. Thanks!
Changes since v3:
- Fix compilation error in function signatures when
  debugfs is disabled
Changes since v2:
- None
Changes since v1:
- Remove unnecessary debugfs dir creation check
- Align ifdefs to left
- Fix function signatures for debugfs init/exit
---
 drivers/soc/qcom/socinfo.c | 190 +
 1 file changed, 190 insertions(+)

diff --git a/drivers/soc/qcom/socinfo.c b/drivers/soc/qcom/socinfo.c
index 1b9eb44df7fe..6a4795433d57 100644
--- a/drivers/soc/qcom/socinfo.c
+++ b/drivers/soc/qcom/socinfo.c
@@ -4,6 +4,7 @@
  * Copyright (c) 2017-2019, Linaro Ltd.
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -20,6 +21,7 @@
  */
 #define SOCINFO_MAJOR(ver) (((ver) >> 16) & 0x)
 #define SOCINFO_MINOR(ver) ((ver) & 0x)
+#define SOCINFO_VERSION(maj, min)  maj) & 0x) << 16)|((min) & 0x))
 
 #define SMEM_SOCINFO_BUILD_ID_LENGTH   32
 
@@ -29,6 +31,27 @@
  */
 #define SMEM_HW_SW_BUILD_ID137
 
+#ifdef CONFIG_DEBUG_FS
+static const char *const pmic_models[] = {
+   [0]  = "Unknown PMIC model",
+   [9]  = "PM8994",
+   [11] = "PM8916",
+   [13] = "PM8058",
+   [14] = "PM8028",
+   [15] = "PM8901",
+   [16] = "PM8027",
+   [17] = "ISL9519",
+   [18] = "PM8921",
+   [19] = "PM8018",
+   [20] = "PM8015",
+   [21] = "PM8014",
+   [22] = "PM8821",
+   [23] = "PM8038",
+   [24] = "PM8922",
+   [25] = "PM8917",
+};
+#endif /* CONFIG_DEBUG_FS */
+
 /* Socinfo SMEM item structure */
 struct socinfo {
__le32 fmt;
@@ -67,9 +90,28 @@ struct socinfo {
__le32 raw_device_num;
 };
 
+#ifdef CONFIG_DEBUG_FS
+struct socinfo_params {
+   u32 raw_device_family;
+   u32 hw_plat_subtype;
+   u32 accessory_chip;
+   u32 raw_device_num;
+   u32 chip_family;
+   u32 foundry_id;
+   u32 plat_ver;
+   u32 raw_ver;
+   u32 hw_plat;
+   u32 fmt;
+};
+#endif /* CONFIG_DEBUG_FS */
+
 struct qcom_socinfo {
struct soc_device *soc_dev;
struct soc_device_attribute attr;
+#ifdef CONFIG_DEBUG_FS
+   struct dentry *dbg_root;
+   struct socinfo_params info;
+#endif /* CONFIG_DEBUG_FS */
 };
 
 struct soc_id {
@@ -130,6 +172,150 @@ static const char *socinfo_machine(struct device *dev, 
unsigned int id)
return NULL;
 }
 
+#ifdef CONFIG_DEBUG_FS
+
+#define QCOM_OPEN(name, _func) \
+static int qcom_open_##name(struct inode *inode, struct file *file)\
+{  \
+   return single_open(file, _func, inode->i_private);  \
+}  \
+   \
+static const struct file_operations qcom_ ##name## _ops = {\
+   .open = qcom_open_##name,   \
+   .read = seq_read,   \
+   .llseek = seq_lseek,\
+   .release = single_release,  \
+}
+
+#d

[PATCH v6 1/5] base: soc: Add serial_number attribute to soc

2019-07-23 Thread Vaishali Thakkar
From: Bjorn Andersson 

Add new attribute named "serial_number" as a standard interface for
user space to acquire the serial number of the device.

For ST-Ericsson SoCs this is exposed by the cryptically named "soc_id"
attribute, but this provides a human readable standardized name for this
property.

Signed-off-by: Bjorn Andersson 
Signed-off-by: Vaishali Thakkar 
Reviewed-by: Greg Kroah-Hartman 
Reviewed-by: Stephen Boyd 
---
Changes since v5:
- No code changes, fix diff.context setting for formatting
  patches. Version 5 was adding context at the bottom of
  the file with 'git am'.
Changes since v4:
- Add Stephen's reviewed-by
Changes since v3:
- Add Greg's Reviewed-by
Changes since v2:
- None
Changes since v1:
- Make comment more clear for the case when serial
  number is not available
---
 Documentation/ABI/testing/sysfs-devices-soc | 7 +++
 drivers/base/soc.c  | 7 +++
 include/linux/sys_soc.h | 1 +
 3 files changed, 15 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-devices-soc 
b/Documentation/ABI/testing/sysfs-devices-soc
index 6d9cc253f2b2..ba3a3fac0ee1 100644
--- a/Documentation/ABI/testing/sysfs-devices-soc
+++ b/Documentation/ABI/testing/sysfs-devices-soc
@@ -26,6 +26,13 @@ Description:
Read-only attribute common to all SoCs. Contains SoC family name
(e.g. DB8500).
 
+What:  /sys/devices/socX/serial_number
+Date:  January 2019
+contact:   Bjorn Andersson 
+Description:
+   Read-only attribute supported by most SoCs. Contains the SoC's
+   serial number, if available.
+
 What:  /sys/devices/socX/soc_id
 Date:  January 2012
 contact:   Lee Jones 
diff --git a/drivers/base/soc.c b/drivers/base/soc.c
index 10b280f30217..b0933b9fe67f 100644
--- a/drivers/base/soc.c
+++ b/drivers/base/soc.c
@@ -33,6 +33,7 @@ static struct bus_type soc_bus_type = {
 
 static DEVICE_ATTR(machine,  S_IRUGO, soc_info_get,  NULL);
 static DEVICE_ATTR(family,   S_IRUGO, soc_info_get,  NULL);
+static DEVICE_ATTR(serial_number, S_IRUGO, soc_info_get,  NULL);
 static DEVICE_ATTR(soc_id,   S_IRUGO, soc_info_get,  NULL);
 static DEVICE_ATTR(revision, S_IRUGO, soc_info_get,  NULL);
 
@@ -57,6 +58,9 @@ static umode_t soc_attribute_mode(struct kobject *kobj,
if ((attr == _attr_revision.attr)
&& (soc_dev->attr->revision != NULL))
return attr->mode;
+   if ((attr == _attr_serial_number.attr)
+   && (soc_dev->attr->serial_number != NULL))
+   return attr->mode;
if ((attr == _attr_soc_id.attr)
&& (soc_dev->attr->soc_id != NULL))
return attr->mode;
@@ -77,6 +81,8 @@ static ssize_t soc_info_get(struct device *dev,
return sprintf(buf, "%s\n", soc_dev->attr->family);
if (attr == _attr_revision)
return sprintf(buf, "%s\n", soc_dev->attr->revision);
+   if (attr == _attr_serial_number)
+   return sprintf(buf, "%s\n", soc_dev->attr->serial_number);
if (attr == _attr_soc_id)
return sprintf(buf, "%s\n", soc_dev->attr->soc_id);
 
@@ -87,6 +93,7 @@ static ssize_t soc_info_get(struct device *dev,
 static struct attribute *soc_attr[] = {
_attr_machine.attr,
_attr_family.attr,
+   _attr_serial_number.attr,
_attr_soc_id.attr,
_attr_revision.attr,
NULL,
diff --git a/include/linux/sys_soc.h b/include/linux/sys_soc.h
index b7c70c3e953f..48ceea867dd6 100644
--- a/include/linux/sys_soc.h
+++ b/include/linux/sys_soc.h
@@ -12,6 +12,7 @@ struct soc_device_attribute {
const char *machine;
const char *family;
const char *revision;
+   const char *serial_number;
const char *soc_id;
const void *data;
 };
-- 
2.17.1



[PATCH v6 0/5] soc: qcom: Add SoC info driver

2019-07-23 Thread Vaishali Thakkar
This patchset adds SoC info driver which can provide information
such as Chip ID, Chip family and serial number about Qualcomm SoCs
to user space via sysfs. Furthermore, it allows userspace to get
information about custom attributes and various image version
information via debugfs.

The patchset cleanly applies on top of v5.2-rc7.

Changes since v1:
- Align ifdefs to left, remove unnecessary debugfs dir
  creation check and fix function signatures in patch 3
- Fix comment for teh case when serial number is not
  available in patch 1

Changes since v2:
- Reorder patches [patch five -> patch two]

Changes since v3:
- Add reviewed-bys from Greg
- Fix build warning when debugfs is disabled
- Remove extra checks for dir creations in patch 5

Changes since v4:
- Added Reviewed-bys in multiple patches
- Bunch of nitpick fixes in patch 3
- Major refactoring for using core debugfs functions and
  eliminating duplicate code in patch 4 and 5 [detailed info
  can be found under --- in each patch]

Changes since v5:
- No code changes, fix diff.context setting for formatting
  patches. Version 4 was adding context at the bottom of
  the file with 'git am'. 

Vaishali Thakkar (5):
  base: soc: Add serial_number attribute to soc
  base: soc: Export soc_device_register/unregister APIs
  soc: qcom: Add socinfo driver
  soc: qcom: socinfo: Expose custom attributes
  soc: qcom: socinfo: Expose image information

 Documentation/ABI/testing/sysfs-devices-soc |   7 +
 drivers/base/soc.c  |   9 +
 drivers/soc/qcom/Kconfig|   8 +
 drivers/soc/qcom/Makefile   |   1 +
 drivers/soc/qcom/smem.c |   9 +
 drivers/soc/qcom/socinfo.c  | 468 
 include/linux/sys_soc.h |   1 +
 7 files changed, 503 insertions(+)
 create mode 100644 drivers/soc/qcom/socinfo.c

-- 
2.17.1



[PATCH v5 0/5] soc: qcom: Add SoC info driver

2019-07-11 Thread Vaishali Thakkar
This patchset adds SoC info driver which can provide information
such as Chip ID, Chip family and serial number about Qualcomm SoCs
to user space via sysfs. Furthermore, it allows userspace to get
information about custom attributes and various image version
information via debugfs.

The patchset cleanly applies on top of v5.2-rc7.

Changes since v1:
- Align ifdefs to left, remove unnecessary debugfs dir
  creation check and fix function signatures in patch 3
- Fix comment for teh case when serial number is not
  available in patch 1

Changes since v2:
- Reorder patches [patch five -> patch two]

Changes since v3:
- Add reviewed-bys from Greg
- Fix build warning when debugfs is disabled
- Remove extra checks for dir creations in patch 5

Changes since v4:
- Added Reviewed-bys in multiple patches
- Bunch of nitpick fixes in patch 3
- Major refactoring for using core debugfs functions and
  eliminating duplicate code in patch 4 and 5 [detailed info
  can be found under --- in each patch]

Vaishali Thakkar (5):
  base: soc: Add serial_number attribute to soc
  base: soc: Export soc_device_register/unregister APIs
  soc: qcom: Add socinfo driver
  soc: qcom: socinfo: Expose custom attributes
  soc: qcom: socinfo: Expose image information

 Documentation/ABI/testing/sysfs-devices-soc |   7 +
 drivers/base/soc.c  |   9 +
 drivers/soc/qcom/Kconfig|   8 +
 drivers/soc/qcom/Makefile   |   1 +
 drivers/soc/qcom/smem.c |   9 +
 drivers/soc/qcom/socinfo.c  | 468 
 include/linux/sys_soc.h |   1 +
 7 files changed, 503 insertions(+)
 create mode 100644 drivers/soc/qcom/socinfo.c

-- 
2.17.1



[PATCH v5 5/5] soc: qcom: socinfo: Expose image information

2019-07-11 Thread Vaishali Thakkar
The socinfo driver provides information about version of the various
images loaded in the system. Expose this to user space for debugging
purpose.

Signed-off-by: Vaishali Thakkar 
---
Changes since v4:
- Reduce number of duplicate image macros and functions
- Introduce array for image info debugfs entries and use it
  instead of open coding
Changes since v3:
- Remove extra debugfs directory creation checks
Changes since v2:
- None
Changes since v1:
- None
---
 drivers/soc/qcom/socinfo.c | 84 ++
 1 file changed, 84 insertions(+)

diff --git a/drivers/soc/qcom/socinfo.c b/drivers/soc/qcom/socinfo.c
index 6a4795433d57..855353bed19e 100644
--- a/drivers/soc/qcom/socinfo.c
+++ b/drivers/soc/qcom/socinfo.c
@@ -34,0 +35,33 @@
+#define SMEM_IMAGE_VERSION_BLOCKS_COUNT32
+#define SMEM_IMAGE_VERSION_SIZE4096
+#define SMEM_IMAGE_VERSION_NAME_SIZE   75
+#define SMEM_IMAGE_VERSION_VARIANT_SIZE20
+#define SMEM_IMAGE_VERSION_OEM_SIZE32
+
+/*
+ * SMEM Image table indices
+ */
+#define SMEM_IMAGE_TABLE_BOOT_INDEX 0
+#define SMEM_IMAGE_TABLE_TZ_INDEX   1
+#define SMEM_IMAGE_TABLE_RPM_INDEX  3
+#define SMEM_IMAGE_TABLE_APPS_INDEX 10
+#define SMEM_IMAGE_TABLE_MPSS_INDEX 11
+#define SMEM_IMAGE_TABLE_ADSP_INDEX 12
+#define SMEM_IMAGE_TABLE_CNSS_INDEX 13
+#define SMEM_IMAGE_TABLE_VIDEO_INDEX14
+#define SMEM_IMAGE_VERSION_TABLE   469
+
+/*
+ * SMEM Image table names
+ */
+static const char *const socinfo_image_names[] = {
+   [SMEM_IMAGE_TABLE_ADSP_INDEX] = "adsp",
+   [SMEM_IMAGE_TABLE_APPS_INDEX] = "apps",
+   [SMEM_IMAGE_TABLE_BOOT_INDEX] = "boot",
+   [SMEM_IMAGE_TABLE_CNSS_INDEX] = "cnss",
+   [SMEM_IMAGE_TABLE_MPSS_INDEX] = "mpss",
+   [SMEM_IMAGE_TABLE_RPM_INDEX] = "rpm",
+   [SMEM_IMAGE_TABLE_TZ_INDEX] = "tz",
+   [SMEM_IMAGE_TABLE_VIDEO_INDEX] = "video",
+};
+
@@ -105,0 +139,7 @@ struct socinfo_params {
+
+struct smem_image_version {
+   char name[SMEM_IMAGE_VERSION_NAME_SIZE];
+   char variant[SMEM_IMAGE_VERSION_VARIANT_SIZE];
+   char pad;
+   char oem[SMEM_IMAGE_VERSION_OEM_SIZE];
+};
@@ -232,0 +273,24 @@ QCOM_OPEN(pmic_die_rev, qcom_show_pmic_die_revision);
+#define DEFINE_IMAGE_OPS(type) \
+static int show_image_##type(struct seq_file *seq, void *p)  \
+{\
+   struct smem_image_version *image_version = seq->private;  \
+   seq_puts(seq, image_version->type);   \
+   seq_puts(seq, "\n");  \
+   return 0; \
+}\
+static int open_image_##type(struct inode *inode, struct file *file) \
+{\
+   return single_open(file, show_image_##type, inode->i_private); \
+}\
+ \
+static const struct file_operations qcom_image_##type##_ops = {  \
+   .open = open_image_##type,\
+   .read = seq_read, \
+   .llseek = seq_lseek,  \
+   .release = single_release,\
+}
+
+DEFINE_IMAGE_OPS(name);
+DEFINE_IMAGE_OPS(variant);
+DEFINE_IMAGE_OPS(oem);
+
@@ -235,0 +300,2 @@ static void socinfo_debugfs_init(struct qcom_socinfo 
*qcom_socinfo,
+   struct smem_image_version *versions;
+   struct dentry *dentry;
@@ -236,0 +303 @@ static void socinfo_debugfs_init(struct qcom_socinfo 
*qcom_socinfo,
+   int i;
@@ -304,0 +372,17 @@ static void socinfo_debugfs_init(struct qcom_socinfo 
*qcom_socinfo,
+
+   versions = qcom_smem_get(QCOM_SMEM_HOST_ANY, SMEM_IMAGE_VERSION_TABLE,
+);
+
+   for (i = 0; i < ARRAY_SIZE(socinfo_image_names); i++) {
+   if (!socinfo_image_names[i])
+   continue;
+
+   dentry = debugfs_create_dir(socinfo_image_names[i],
+   qcom_socinfo->dbg_root);
+   debugfs_create_file("name", 0400, dentry, [i],
+   _image_name_ops);
+   debugfs_create_file("variant", 0400, dentry, [i],
+   _image_variant_ops);
+   debugfs_create_file("oem", 0400, dentry, [i],
+   _image_oem_ops);
+   }
-- 
2.17.1



[PATCH v5 2/5] base: soc: Export soc_device_register/unregister APIs

2019-07-11 Thread Vaishali Thakkar
From: Vinod Koul 

Qcom Socinfo driver can be built as a module, so
export these two APIs.

Signed-off-by: Vinod Koul 
Signed-off-by: Vaishali Thakkar 
Reviewed-by: Greg Kroah-Hartman 
Reviewed-by: Stephen Boyd 
Reviewed-by: Bjorn Andersson 
---
Changes since v4:
- Add Bjorn and Stephen's Reviewed-by
Changes since v3:
- Add Greg's Reviewed-by
Changes since v2:
- None
Changes since v1:
- Make comment more clear for the case when serial
  number is not available
---
 drivers/base/soc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/base/soc.c b/drivers/base/soc.c
index b0933b9fe67f..7c0c5ca5953d 100644
--- a/drivers/base/soc.c
+++ b/drivers/base/soc.c
@@ -166,0 +167 @@ struct soc_device *soc_device_register(struct 
soc_device_attribute *soc_dev_attr
+EXPORT_SYMBOL_GPL(soc_device_register);
@@ -175,0 +177 @@ void soc_device_unregister(struct soc_device *soc_dev)
+EXPORT_SYMBOL_GPL(soc_device_unregister);
-- 
2.17.1



[PATCH v5 3/5] soc: qcom: Add socinfo driver

2019-07-11 Thread Vaishali Thakkar
From: Imran Khan 

The Qualcomm socinfo driver exposes information about the SoC, its
version and its serial number to user space.

Signed-off-by: Imran Khan 
[Bjorn: Extract code to platform_driver, split patch in multiple]
Signed-off-by: Bjorn Andersson 
[Vaishali: Simplify declarations, introduce qcom_socinfo struct, Fix
   memory leak, Remove extra code and Misc code refactoring]
Signed-off-by: Vaishali Thakkar 
---
Changes since v4:
- Return PTR_ERR in qcom_socinfo_probe instead of error value
- Return PTR_ERR in smem probe to print proper error message
  when we fail to register the socinfo device
- Use dev_dbg instead of dev_err in qcom_smem_probe
- Use offset_of for exposing the value of serial_number
- Unregister the platform device in smem remove function
- Drop error message in socinfo_machine
- Misc: Add spaces between brackets and strings/numbers in
soc_of_id, item ids->item id, socinfo->SoCinfo,
soc_of_id->soc_id
Changes since v3:
- None
Changes since v2:
- Fix typo in the work log under signed off by s
Changes since v1:
- None
---
 drivers/soc/qcom/Kconfig   |   8 ++
 drivers/soc/qcom/Makefile  |   1 +
 drivers/soc/qcom/smem.c|   9 ++
 drivers/soc/qcom/socinfo.c | 194 +
 4 files changed, 212 insertions(+)
 create mode 100644 drivers/soc/qcom/socinfo.c

diff --git a/drivers/soc/qcom/Kconfig b/drivers/soc/qcom/Kconfig
index 880cf0290962..834faea78dd6 100644
--- a/drivers/soc/qcom/Kconfig
+++ b/drivers/soc/qcom/Kconfig
@@ -165,0 +166,8 @@ config QCOM_SMSM
+config QCOM_SOCINFO
+   tristate "Qualcomm socinfo driver"
+   depends on QCOM_SMEM
+   select SOC_BUS
+   help
+Say yes here to support the Qualcomm socinfo driver, providing
+information about the SoC to user space.
+
diff --git a/drivers/soc/qcom/Makefile b/drivers/soc/qcom/Makefile
index ffe519b0cb66..4da51b14d9d2 100644
--- a/drivers/soc/qcom/Makefile
+++ b/drivers/soc/qcom/Makefile
@@ -19,0 +20 @@ obj-$(CONFIG_QCOM_SMSM) += smsm.o
+obj-$(CONFIG_QCOM_SOCINFO) += socinfo.o
diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c
index f27c00d82ae4..0caf67e2f037 100644
--- a/drivers/soc/qcom/smem.c
+++ b/drivers/soc/qcom/smem.c
@@ -270,0 +271 @@ struct qcom_smem {
+   struct platform_device *socinfo;
@@ -965,0 +967,6 @@ static int qcom_smem_probe(struct platform_device *pdev)
+   smem->socinfo = platform_device_register_data(>dev, 
"qcom-socinfo",
+ PLATFORM_DEVID_NONE, NULL,
+ 0);
+   if (IS_ERR(smem->socinfo))
+   dev_dbg(>dev, "failed to register socinfo device\n");
+
@@ -970,0 +978,2 @@ static int qcom_smem_remove(struct platform_device *pdev)
+   platform_device_unregister(__smem->socinfo);
+
diff --git a/drivers/soc/qcom/socinfo.c b/drivers/soc/qcom/socinfo.c
new file mode 100644
index ..1b9eb44df7fe
--- /dev/null
+++ b/drivers/soc/qcom/socinfo.c
@@ -0,0 +1,194 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2009-2017, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2017-2019, Linaro Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * SoC version type with major number in the upper 16 bits and minor
+ * number in the lower 16 bits.
+ */
+#define SOCINFO_MAJOR(ver) (((ver) >> 16) & 0x)
+#define SOCINFO_MINOR(ver) ((ver) & 0x)
+
+#define SMEM_SOCINFO_BUILD_ID_LENGTH   32
+
+/*
+ * SMEM item id, used to acquire handles to respective
+ * SMEM region.
+ */
+#define SMEM_HW_SW_BUILD_ID137
+
+/* Socinfo SMEM item structure */
+struct socinfo {
+   __le32 fmt;
+   __le32 id;
+   __le32 ver;
+   char build_id[SMEM_SOCINFO_BUILD_ID_LENGTH];
+   /* Version 2 */
+   __le32 raw_id;
+   __le32 raw_ver;
+   /* Version 3 */
+   __le32 hw_plat;
+   /* Version 4 */
+   __le32 plat_ver;
+   /* Version 5 */
+   __le32 accessory_chip;
+   /* Version 6 */
+   __le32 hw_plat_subtype;
+   /* Version 7 */
+   __le32 pmic_model;
+   __le32 pmic_die_rev;
+   /* Version 8 */
+   __le32 pmic_model_1;
+   __le32 pmic_die_rev_1;
+   __le32 pmic_model_2;
+   __le32 pmic_die_rev_2;
+   /* Version 9 */
+   __le32 foundry_id;
+   /* Version 10 */
+   __le32 serial_num;
+   /* Version 11 */
+   __le32 num_pmics;
+   __le32 pmic_array_offset;
+   /* Version 12 */
+   __le32 chip_family;
+   __le32 raw_device_family;
+   __le32 raw_device_num;
+};
+
+struct qcom_socinfo {
+   struct soc_device *soc_dev;
+   struct soc_device_attribute attr;
+};
+
+struct soc_id {
+   unsigned int id

[PATCH v5 4/5] soc: qcom: socinfo: Expose custom attributes

2019-07-11 Thread Vaishali Thakkar
The Qualcomm socinfo provides a number of additional attributes,
add these to the socinfo driver and expose them via debugfs
functionality.

Signed-off-by: Vaishali Thakkar 
---
Changes since v4:
- Introduce socinfo_params and use create_debugfs_{u32,x32}
  instead of driver specific macros
- Remove some unnecessary separate functions
  [qcom_show_{platform_subtype,accessory_chip}] and use
  debugfs core functions to expose their values
- Use switch to expose custom attributes based on the
  firmware version
- Misc: Drop unnecessory comments, pmic_model->pmic_models,
don't pass socinfo pointer in qcom_socinfo
- Note: I didn't introduce any new debugfs core functions
for printing string values because it wasn't
possible to cover both cases of string arrays in this
file - pmic_model and build_id by introducing a single
function. Morever, I still needed QCOM_OPEN and DEBUGFS_ADD
to cover the case of pmic_die_rev so introducing the
'debugfs create string array function' wasn't completely
eliminating extra macro code. So, I'm just using the
above mentioned macros to print string array values for
now. Feel free to on this matter. Thanks!
Changes since v3:
- Fix compilation error in function signatures when
  debugfs is disabled
Changes since v2:
- None
Changes since v1:
- Remove unnecessary debugfs dir creation check
- Align ifdefs to left
- Fix function signatures for debugfs init/exit
---
 drivers/soc/qcom/socinfo.c | 190 +
 1 file changed, 190 insertions(+)

diff --git a/drivers/soc/qcom/socinfo.c b/drivers/soc/qcom/socinfo.c
index 1b9eb44df7fe..6a4795433d57 100644
--- a/drivers/soc/qcom/socinfo.c
+++ b/drivers/soc/qcom/socinfo.c
@@ -6,0 +7 @@
+#include 
@@ -22,0 +24 @@
+#define SOCINFO_VERSION(maj, min)  maj) & 0x) << 16)|((min) & 0x))
@@ -31,0 +34,21 @@
+#ifdef CONFIG_DEBUG_FS
+static const char *const pmic_models[] = {
+   [0]  = "Unknown PMIC model",
+   [9]  = "PM8994",
+   [11] = "PM8916",
+   [13] = "PM8058",
+   [14] = "PM8028",
+   [15] = "PM8901",
+   [16] = "PM8027",
+   [17] = "ISL9519",
+   [18] = "PM8921",
+   [19] = "PM8018",
+   [20] = "PM8015",
+   [21] = "PM8014",
+   [22] = "PM8821",
+   [23] = "PM8038",
+   [24] = "PM8922",
+   [25] = "PM8917",
+};
+#endif /* CONFIG_DEBUG_FS */
+
@@ -69,0 +93,15 @@ struct socinfo {
+#ifdef CONFIG_DEBUG_FS
+struct socinfo_params {
+   u32 raw_device_family;
+   u32 hw_plat_subtype;
+   u32 accessory_chip;
+   u32 raw_device_num;
+   u32 chip_family;
+   u32 foundry_id;
+   u32 plat_ver;
+   u32 raw_ver;
+   u32 hw_plat;
+   u32 fmt;
+};
+#endif /* CONFIG_DEBUG_FS */
+
@@ -72,0 +111,4 @@ struct qcom_socinfo {
+#ifdef CONFIG_DEBUG_FS
+   struct dentry *dbg_root;
+   struct socinfo_params info;
+#endif /* CONFIG_DEBUG_FS */
@@ -132,0 +175,144 @@ static const char *socinfo_machine(struct device *dev, 
unsigned int id)
+#ifdef CONFIG_DEBUG_FS
+
+#define QCOM_OPEN(name, _func) \
+static int qcom_open_##name(struct inode *inode, struct file *file)\
+{  \
+   return single_open(file, _func, inode->i_private);  \
+}  \
+   \
+static const struct file_operations qcom_ ##name## _ops = {\
+   .open = qcom_open_##name,   \
+   .read = seq_read,   \
+   .llseek = seq_lseek,\
+   .release = single_release,  \
+}
+
+#define DEBUGFS_ADD(info, name)
\
+   debugfs_create_file(__stringify(name), 0400,\
+   qcom_socinfo->dbg_root, \
+   info, _ ##name## _ops)
+
+
+static int qcom_show_build_id(struct seq_file *seq, void *p)
+{
+   struct socinfo *socinfo = seq->private;
+
+   seq_printf(seq, "%s\n", socinfo->build_id);
+
+   return 0;
+}
+
+static int qcom_show_pmic_model(struct seq_file *seq, void *p)
+{
+   struct socinfo *socinfo = seq->private;
+   int model = SOCINFO_MINOR(le32_to_cpu(socinfo->pmic_model));
+
+   if (model < 0)

[PATCH v5 1/5] base: soc: Add serial_number attribute to soc

2019-07-11 Thread Vaishali Thakkar
From: Bjorn Andersson 

Add new attribute named "serial_number" as a standard interface for
user space to acquire the serial number of the device.

For ST-Ericsson SoCs this is exposed by the cryptically named "soc_id"
attribute, but this provides a human readable standardized name for this
property.

Signed-off-by: Bjorn Andersson 
Signed-off-by: Vaishali Thakkar 
Reviewed-by: Greg Kroah-Hartman 
Reviewed-by: Stephen Boyd 
---
Changes since v4:
- Add Stephen's reviewed-by
Changes since v3:
- Add Greg's Reviewed-by
Changes since v2:
- None
Changes since v1:
- Make comment more clear for the case when serial
  number is not available
---
 Documentation/ABI/testing/sysfs-devices-soc | 7 +++
 drivers/base/soc.c  | 7 +++
 include/linux/sys_soc.h | 1 +
 3 files changed, 15 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-devices-soc 
b/Documentation/ABI/testing/sysfs-devices-soc
index 6d9cc253f2b2..ba3a3fac0ee1 100644
--- a/Documentation/ABI/testing/sysfs-devices-soc
+++ b/Documentation/ABI/testing/sysfs-devices-soc
@@ -28,0 +29,7 @@ Description:
+What:  /sys/devices/socX/serial_number
+Date:  January 2019
+contact:   Bjorn Andersson 
+Description:
+   Read-only attribute supported by most SoCs. Contains the SoC's
+   serial number, if available.
+
diff --git a/drivers/base/soc.c b/drivers/base/soc.c
index 10b280f30217..b0933b9fe67f 100644
--- a/drivers/base/soc.c
+++ b/drivers/base/soc.c
@@ -35,0 +36 @@ static DEVICE_ATTR(family,   S_IRUGO, soc_info_get,  NULL);
+static DEVICE_ATTR(serial_number, S_IRUGO, soc_info_get,  NULL);
@@ -59,0 +61,3 @@ static umode_t soc_attribute_mode(struct kobject *kobj,
+   if ((attr == _attr_serial_number.attr)
+   && (soc_dev->attr->serial_number != NULL))
+   return attr->mode;
@@ -79,0 +84,2 @@ static ssize_t soc_info_get(struct device *dev,
+   if (attr == _attr_serial_number)
+   return sprintf(buf, "%s\n", soc_dev->attr->serial_number);
@@ -89,0 +96 @@ static struct attribute *soc_attr[] = {
+   _attr_serial_number.attr,
diff --git a/include/linux/sys_soc.h b/include/linux/sys_soc.h
index b7c70c3e953f..48ceea867dd6 100644
--- a/include/linux/sys_soc.h
+++ b/include/linux/sys_soc.h
@@ -14,0 +15 @@ struct soc_device_attribute {
+   const char *serial_number;
-- 
2.17.1



Re: [PATCH v4 4/5] soc: qcom: socinfo: Expose custom attributes

2019-03-25 Thread Vaishali Thakkar
On Mon, 25 Mar 2019 at 21:31, Stephen Boyd  wrote:
>
> Quoting Vaishali Thakkar (2019-03-24 10:42:36)
> > On Sat, 23 Mar 2019 at 05:31, Stephen Boyd  wrote:
> >
> > > debugfs_create_devm_seqfile() which may work to print a string from some
> > > struct member. I'm not sure why you're using simple_attr_read(). Where
> > > does that become important?
> >
> > DEFINE_DEBUGFS_ATTRIBUTE has simple_attr helpers which
> > expects int value. So, in the case of a string it requires to implement
> > similar macro and separate helpers for the same.
>
> Why does DEFINE_DEBUGFS_ATTRIBUTE need to be used?

For defining files inside the debugfs code [with get/set functions].
Also, most of the similar functions in the debugfs core seems to be
using it.

>


Re: [PATCH v4 4/5] soc: qcom: socinfo: Expose custom attributes

2019-03-24 Thread Vaishali Thakkar
On Sat, 23 Mar 2019 at 05:31, Stephen Boyd  wrote:
>
> Quoting Vaishali Thakkar (2019-03-20 22:51:20)
> > On Thu, 14 Mar 2019 at 21:28, Stephen Boyd  wrote:
> > >
> > > Quoting Vaishali Thakkar (2019-03-14 04:25:16)
> > > > On Fri, 1 Mar 2019 at 03:02, Stephen Boyd  wrote:
> > >
> > > >
> > > > In the case of converting it to cpu native during probe, I'll need to
> > > > declare an extra struct with u32 being the parsed version for it to be
> > > > correct. Wouldn't it add extra overhead?
> > >
> > > Yes it would be some small extra overhead that could be allocated on the
> > > kernel's heap. What's the maximum size? A hundred bytes or so?
> > >
> > > I don't see much of a problem with this approach. It simplifies the
> > > patch series because nothing new is introduced in debugfs core and the
> > > endian conversion is done once in one place instead of being scattered
> > > throughout the code. Sounds like a good improvement to me.
> > >
> >
> > Yes, it's true that this approach is better than introducing new endian
> > functions in debugfs core but we should also keep in mind that this is
> > applicable only for 4 use cases. For other usecases, we want to print
> > string and hex values. So, I would either need new debugfs core
> > functions for the same. I tried introducing debugfs_create_str for string
> > values but we're ending up with introducing bunch of other helpers in
> > the core as simple_attr_read expects integer values. Similarly, for hex
> > values , I can't use debugfs_create_u32 as defined attributes in the
> > core has unsigned int as a specifier, will need to introduce some extra
> > helpers over there again.
>
> I imagine there are other uses of printing a string and hex value in
> debugfs. There's debugfs_create_x32() and debugfs_create_x64() for the
> hex value printing part (if you want that format). There's also

Ok.

> debugfs_create_devm_seqfile() which may work to print a string from some
> struct member. I'm not sure why you're using simple_attr_read(). Where
> does that become important?

DEFINE_DEBUGFS_ATTRIBUTE has simple_attr helpers which
expects int value. So, in the case of a string it requires to implement
similar macro and separate helpers for the same.

> >
> > Also, in case of keeping all other cases as it is, it'll look quite
> > asymmetric to use debugfs u32 function in init and using local macros
> > for other cases. I can have DEBUGFS_UINT_ADD like wrapper
> > macro for debugfs_create_u32 but again not sure if doing
> > all of this looks better than what we have at the moment as just having
> > 3 local macros covering our all cases without having lot of duplicated
> > code.
> >
> >  Let me know if about your opinion on the same. Thanks.
>
> My opinion is still that it would be best to push things that aren't SoC
> specific into the debugfs core and try to use as much from the core as
> possible. There doesn't seem to be anything very SoC specific here so
> I'm lost why this isn't doable.

Yes, that's true. We don't have much of SoC specific code here.

>


Re: [PATCH v4 4/5] soc: qcom: socinfo: Expose custom attributes

2019-03-20 Thread Vaishali Thakkar
On Thu, 14 Mar 2019 at 21:28, Stephen Boyd  wrote:
>
> Quoting Vaishali Thakkar (2019-03-14 04:25:16)
> > On Fri, 1 Mar 2019 at 03:02, Stephen Boyd  wrote:
> > >
> > > Why can't we use the debugfs_create_u32 function? It would make things
> > > clearer if there was either a debugfs_create_le32() function or if the
> > > socinfo structure stored in smem was unmarshalled from little endian
> > > to the cpu native endian format during probe time and then all the rest
> > > of the code can treat it as a native endian u32 values.
> >
> > Thanks for the review. I've worked on the next version with all the
> > changes you suggested in the patchset but I'm kind of not sure
> > what would be the best solution in this case.
>
> Alright, thanks.
>
> >
> > I'm bit skeptical about introducing debugfs_create_le32 as we don't
> > really have any endian specific functions in the debugfs core at the
> > moment. And if I do that, should I also introduce debugfs_create_be32
> > [and to an extent debugfs_create_le{16,64}]? More importantly, would
> > it be useful to introduce them in core?
>
> I suppose it's ambiguous if the endianness should be swapped to be CPU
> native, or if it should just export them as little endian or big endian
> to userspace. I wouldn't introduce any APIs that aren't used, because
> it's just dead code. If the code is documented clearly and indicates
> what it does then it should be fine. This patch has pretty much already
> written the code, so it's just a matter of moving it into debugfs core
> now and getting gregkh to approve.
>
> >
> > In the case of converting it to cpu native during probe, I'll need to
> > declare an extra struct with u32 being the parsed version for it to be
> > correct. Wouldn't it add extra overhead?
>
> Yes it would be some small extra overhead that could be allocated on the
> kernel's heap. What's the maximum size? A hundred bytes or so?
>
> I don't see much of a problem with this approach. It simplifies the
> patch series because nothing new is introduced in debugfs core and the
> endian conversion is done once in one place instead of being scattered
> throughout the code. Sounds like a good improvement to me.
>

Yes, it's true that this approach is better than introducing new endian
functions in debugfs core but we should also keep in mind that this is
applicable only for 4 use cases. For other usecases, we want to print
string and hex values. So, I would either need new debugfs core
functions for the same. I tried introducing debugfs_create_str for string
values but we're ending up with introducing bunch of other helpers in
the core as simple_attr_read expects integer values. Similarly, for hex
values , I can't use debugfs_create_u32 as defined attributes in the
core has unsigned int as a specifier, will need to introduce some extra
helpers over there again.

Also, in case of keeping all other cases as it is, it'll look quite
asymmetric to use debugfs u32 function in init and using local macros
for other cases. I can have DEBUGFS_UINT_ADD like wrapper
macro for debugfs_create_u32 but again not sure if doing
all of this looks better than what we have at the moment as just having
3 local macros covering our all cases without having lot of duplicated
code.

 Let me know if about your opinion on the same. Thanks.


Re: [PATCH v4 4/5] soc: qcom: socinfo: Expose custom attributes

2019-03-14 Thread Vaishali Thakkar
On Fri, 1 Mar 2019 at 03:02, Stephen Boyd  wrote:
>
> Quoting Vaishali Thakkar (2019-02-24 22:50:43)
> > diff --git a/drivers/soc/qcom/socinfo.c b/drivers/soc/qcom/socinfo.c
> > index 02078049fac7..ccadeba69a81 100644
> > --- a/drivers/soc/qcom/socinfo.c
> > +++ b/drivers/soc/qcom/socinfo.c
> > @@ -70,6 +93,10 @@ struct socinfo {
> >  struct qcom_socinfo {
> > struct soc_device *soc_dev;
> > struct soc_device_attribute attr;
> > +#ifdef CONFIG_DEBUG_FS
> > +   struct dentry *dbg_root;
> > +#endif /* CONFIG_DEBUG_FS */
> > +   struct socinfo *socinfo;
>
> This doesn't look necessary, instead just pass it through to the
> functions that need the pointer.
>
> >  };
> >
> >  struct soc_of_id {
> > @@ -133,6 +160,171 @@ static const char *socinfo_machine(struct device 
> > *dev, unsigned int id)
> > return NULL;
> >  }
> >
> > +#ifdef CONFIG_DEBUG_FS
> > +
> > +#define UINT_SHOW(name, attr)  \
> > +static int qcom_show_##name(struct seq_file *seq, void *p) \
> > +{  \
> > +   struct socinfo *socinfo = seq->private; \
> > +   seq_printf(seq, "%u\n", le32_to_cpu(socinfo->attr));\
> > +   return 0;   \
> > +}  \
> > +static int qcom_open_##name(struct inode *inode, struct file *file)\
> > +{  \
> > +   return single_open(file, qcom_show_##name, inode->i_private);   \
> > +}  \
> > +   \
> > +static const struct file_operations qcom_ ##name## _ops = {\
> > +   .open = qcom_open_##name,   \
> > +   .read = seq_read,   \
> > +   .llseek = seq_lseek,\
> > +   .release = single_release,  \
> > +}
>
> Why can't we use the debugfs_create_u32 function? It would make things
> clearer if there was either a debugfs_create_le32() function or if the
> socinfo structure stored in smem was unmarshalled from little endian
> to the cpu native endian format during probe time and then all the rest
> of the code can treat it as a native endian u32 values.

Thanks for the review. I've worked on the next version with all the
changes you suggested in the patchset but I'm kind of not sure
what would be the best solution in this case.

I'm bit skeptical about introducing debugfs_create_le32 as we don't
really have any endian specific functions in the debugfs core at the
moment. And if I do that, should I also introduce debugfs_create_be32
[and to an extent debugfs_create_le{16,64}]? More importantly, would
it be useful to introduce them in core?

In the case of converting it to cpu native during probe, I'll need to
declare an extra struct with u32 being the parsed version for it to be
correct. Wouldn't it add extra overhead?

> > +
> > +#define DEBUGFS_UINT_ADD(name) \
> > +   debugfs_create_file(__stringify(name), 0400,\
> > +   qcom_socinfo->dbg_root, \
> > +   qcom_socinfo->socinfo, _ ##name## _ops)
> > +
> > +#define HEX_SHOW(name, attr)   \
> > +static int qcom_show_##name(struct seq_file *seq, void *p) \
> > +{  \
> > +   struct socinfo *socinfo = seq->private; \
> > +   seq_printf(seq, "0x%x\n", le32_to_cpu(socinfo->attr));  \
>
> Use "%#x\n" format?
>
> > +   return 0;   \
> > +}  \
> > +static int qcom_open_##name(struct inode *inode, struct file *file)\
> > +{  \
> > +   return single_open(file, qcom_show_##name, inode->i_private);   \
> > +}  \
> > +  

[PATCH v4 0/5] soc: qcom: Add SoC info driver

2019-02-24 Thread Vaishali Thakkar
This patchset adds SoC info driver which can provide information
such as Chip ID, Chip family and serial number about Qualcomm SoCs
to user space via sysfs. Furthermore, it allows userspace to get
information about custom attributes and various image version
information via debugfs.

The patchset cleanly applies on top of v5.0-rc6.

Changes since v1:
- Align ifdefs to left, remove unnecessary debugfs dir
  creation check and fix function signatures in patch 3
- Fix comment for teh case when serial number is not
  available in patch 1
Changes since v2:
- Reorder patches [patch five -> patch two]

Changes since v3:
- Add reviewed-bys from Greg
- Fix build warning when debugfs is disabled
- Remove extra checks for dir creations in patch 5

Vaishali Thakkar (5):
  base: soc: Add serial_number attribute to soc
  base: soc: Export soc_device_register/unregister APIs
  soc: qcom: Add socinfo driver
  soc: qcom: socinfo: Expose custom attributes
  soc: qcom: socinfo: Expose image information

 Documentation/ABI/testing/sysfs-devices-soc |   7 +
 drivers/base/soc.c  |   9 +
 drivers/soc/qcom/Kconfig|   8 +
 drivers/soc/qcom/Makefile   |   1 +
 drivers/soc/qcom/smem.c |   8 +
 drivers/soc/qcom/socinfo.c  | 573 
 include/linux/sys_soc.h |   1 +
 7 files changed, 607 insertions(+)
 create mode 100644 drivers/soc/qcom/socinfo.c

-- 
2.17.1



[PATCH v4 2/5] base: soc: Export soc_device_register/unregister APIs

2019-02-24 Thread Vaishali Thakkar
From: Vinod Koul 

Qcom Socinfo driver can be built as a module, so
export these two APIs.

Signed-off-by: Vinod Koul 
Signed-off-by: Vaishali Thakkar 
Reviewed-by: Greg Kroah-Hartman 
---
Changes since v3:
- Add Greg's reviewed-by
Changes since v2:
- Reorder patches [patch 5->patch 2]
Changes since v1:
- None
---
 drivers/base/soc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/base/soc.c b/drivers/base/soc.c
index b0933b9fe67f..7c0c5ca5953d 100644
--- a/drivers/base/soc.c
+++ b/drivers/base/soc.c
@@ -164,6 +164,7 @@ struct soc_device *soc_device_register(struct 
soc_device_attribute *soc_dev_attr
 out1:
return ERR_PTR(ret);
 }
+EXPORT_SYMBOL_GPL(soc_device_register);
 
 /* Ensure soc_dev->attr is freed prior to calling soc_device_unregister. */
 void soc_device_unregister(struct soc_device *soc_dev)
@@ -173,6 +174,7 @@ void soc_device_unregister(struct soc_device *soc_dev)
device_unregister(_dev->dev);
early_soc_dev_attr = NULL;
 }
+EXPORT_SYMBOL_GPL(soc_device_unregister);
 
 static int __init soc_bus_register(void)
 {
-- 
2.17.1



[PATCH v4 5/5] soc: qcom: socinfo: Expose image information

2019-02-24 Thread Vaishali Thakkar
The socinfo driver provides information about version of the various
images loaded in the system. Expose this to user space for debugging
purpose.

Signed-off-by: Vaishali Thakkar 
---
Changes since v3:
- Remove extra debugfs directory creation checks
Changes since v2:
- None
Changes since v1:
- None
---
 drivers/soc/qcom/socinfo.c | 178 +
 1 file changed, 178 insertions(+)

diff --git a/drivers/soc/qcom/socinfo.c b/drivers/soc/qcom/socinfo.c
index ccadeba69a81..5d77265054a3 100644
--- a/drivers/soc/qcom/socinfo.c
+++ b/drivers/soc/qcom/socinfo.c
@@ -31,6 +31,25 @@
 #define SMEM_HW_SW_BUILD_ID137
 
 #ifdef CONFIG_DEBUG_FS
+#define SMEM_IMAGE_VERSION_BLOCKS_COUNT32
+#define SMEM_IMAGE_VERSION_SIZE4096
+#define SMEM_IMAGE_VERSION_NAME_SIZE   75
+#define SMEM_IMAGE_VERSION_VARIANT_SIZE20
+#define SMEM_IMAGE_VERSION_OEM_SIZE32
+
+/*
+ * SMEM Image table indices
+ */
+#define SMEM_IMAGE_TABLE_BOOT_INDEX 0
+#define SMEM_IMAGE_TABLE_TZ_INDEX   1
+#define SMEM_IMAGE_TABLE_RPM_INDEX  3
+#define SMEM_IMAGE_TABLE_APPS_INDEX 10
+#define SMEM_IMAGE_TABLE_MPSS_INDEX 11
+#define SMEM_IMAGE_TABLE_ADSP_INDEX 12
+#define SMEM_IMAGE_TABLE_CNSS_INDEX 13
+#define SMEM_IMAGE_TABLE_VIDEO_INDEX14
+#define SMEM_IMAGE_VERSION_TABLE   469
+
 /* pmic model info */
 static const char *const pmic_model[] = {
[0]  = "Unknown PMIC model",
@@ -90,11 +109,21 @@ struct socinfo {
__le32 raw_device_num;
 };
 
+#ifdef CONFIG_DEBUG_FS
+struct smem_image_version {
+   char name[SMEM_IMAGE_VERSION_NAME_SIZE];
+   char variant[SMEM_IMAGE_VERSION_VARIANT_SIZE];
+   char pad;
+   char oem[SMEM_IMAGE_VERSION_OEM_SIZE];
+};
+#endif /* CONFIG_DEBUG_FS */
+
 struct qcom_socinfo {
struct soc_device *soc_dev;
struct soc_device_attribute attr;
 #ifdef CONFIG_DEBUG_FS
struct dentry *dbg_root;
+   struct dentry *boot, *tz, *rpm, *apps, *mpss, *adsp, *cnss, *video;
 #endif /* CONFIG_DEBUG_FS */
struct socinfo *socinfo;
 };
@@ -298,8 +327,97 @@ QCOM_OPEN(pmic_model, qcom_show_pmic_model);
 QCOM_OPEN(platform_subtype, qcom_show_platform_subtype);
 QCOM_OPEN(pmic_die_revision, qcom_show_pmic_die_revision);
 
+#define IMAGE_SHOW_NAME(attr)\
+static int show_ ##attr## _name(struct seq_file *seq, void *p)   \
+{\
+   struct smem_image_version *image_version = seq->private;  \
+   seq_puts(seq, image_version->name);   \
+   seq_puts(seq, "\n");  \
+   return 0; \
+}\
+static int open_ ##attr## _name(struct inode *inode, struct file *file)
  \
+{\
+   return single_open(file, show_ ##attr## _name, inode->i_private); \
+}\
+ \
+static const struct file_operations qcom_ ##attr## _name_ops = { \
+   .open = open_ ##attr## _name, \
+   .read = seq_read, \
+   .llseek = seq_lseek,  \
+   .release = single_release,\
+}\
+
+#define DEBUGFS_IMAGE_NAME(fname, attr, index)   \
+debugfs_create_file(__stringify(fname), 0400, qcom_socinfo->attr,\
+   _image_version[index], _ ##attr## _name_ops)
+
+#define IMAGE_SHOW_VARIANT(attr)\
+static int show_ ##attr## _variant(struct seq_file *seq, void *p)   \
+{   \
+   struct smem_image_version *image_version = seq->private; \
+   seq_puts(seq, image_version->variant);   \
+   seq_puts(seq, "\n"); \
+   return 0;\
+}   \
+static int open_ ##attr## _variant(struct inode *inode, struct file *file)   \
+{\
+   return single_open

[PATCH v4 3/5] soc: qcom: Add socinfo driver

2019-02-24 Thread Vaishali Thakkar
From: Imran Khan 

The Qualcomm socinfo driver exposes information about the SoC, its
version and its serial number to user space.

Signed-off-by: Imran Khan 
[Bjorn: Extract code to platform_driver, split patch in multiple]
Signed-off-by: Bjorn Andersson 
[Vaishali: Simplify declarations, introduce qcom_socinfo struc, Fix
   memory leak, Remove extra code and Misc code refactoring]
Signed-off-by: Vaishali Thakkar 
---
Changes since v3:
- None
Changes since v2:
- Fix typo in the work log under signed off by s
Changes since v1:
- None
---
 drivers/soc/qcom/Kconfig   |   8 ++
 drivers/soc/qcom/Makefile  |   1 +
 drivers/soc/qcom/smem.c|   8 ++
 drivers/soc/qcom/socinfo.c | 197 +
 4 files changed, 214 insertions(+)
 create mode 100644 drivers/soc/qcom/socinfo.c

diff --git a/drivers/soc/qcom/Kconfig b/drivers/soc/qcom/Kconfig
index fcbf8a2e4080..1e31eda07934 100644
--- a/drivers/soc/qcom/Kconfig
+++ b/drivers/soc/qcom/Kconfig
@@ -144,6 +144,14 @@ config QCOM_SMSM
  Say yes here to support the Qualcomm Shared Memory State Machine.
  The state machine is represented by bits in shared memory.
 
+config QCOM_SOCINFO
+   tristate "Qualcomm socinfo driver"
+   depends on QCOM_SMEM
+   select SOC_BUS
+   help
+Say yes here to support the Qualcomm socinfo driver, providing
+information about the SoC to user space.
+
 config QCOM_WCNSS_CTRL
tristate "Qualcomm WCNSS control driver"
depends on ARCH_QCOM || COMPILE_TEST
diff --git a/drivers/soc/qcom/Makefile b/drivers/soc/qcom/Makefile
index f25b54cd6cf8..c817da4f4140 100644
--- a/drivers/soc/qcom/Makefile
+++ b/drivers/soc/qcom/Makefile
@@ -14,6 +14,7 @@ qcom_rpmh-y   += rpmh-rsc.o
 qcom_rpmh-y+= rpmh.o
 obj-$(CONFIG_QCOM_SMD_RPM) += smd-rpm.o
 obj-$(CONFIG_QCOM_SMEM) += smem.o
+obj-$(CONFIG_QCOM_SOCINFO) += socinfo.o
 obj-$(CONFIG_QCOM_SMEM_STATE) += smem_state.o
 obj-$(CONFIG_QCOM_SMP2P)   += smp2p.o
 obj-$(CONFIG_QCOM_SMSM)+= smsm.o
diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c
index f80d040601fd..efe0b053ef82 100644
--- a/drivers/soc/qcom/smem.c
+++ b/drivers/soc/qcom/smem.c
@@ -276,6 +276,7 @@ struct qcom_smem {
struct smem_partition_header *partitions[SMEM_HOST_COUNT];
size_t cacheline[SMEM_HOST_COUNT];
u32 item_count;
+   struct platform_device *socinfo;
 
unsigned num_regions;
struct smem_region regions[];
@@ -971,11 +972,18 @@ static int qcom_smem_probe(struct platform_device *pdev)
 
__smem = smem;
 
+   smem->socinfo = platform_device_register_data(>dev, 
"qcom-socinfo",
+ PLATFORM_DEVID_NONE, NULL,
+ 0);
+   if (IS_ERR(smem->socinfo))
+   dev_err(>dev, "failed to register socinfo device\n");
+
return 0;
 }
 
 static int qcom_smem_remove(struct platform_device *pdev)
 {
+
hwspin_lock_free(__smem->hwlock);
__smem = NULL;
 
diff --git a/drivers/soc/qcom/socinfo.c b/drivers/soc/qcom/socinfo.c
new file mode 100644
index ..02078049fac7
--- /dev/null
+++ b/drivers/soc/qcom/socinfo.c
@@ -0,0 +1,197 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2009-2017, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2017-2019, Linaro Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * SoC version type with major number in the upper 16 bits and minor
+ * number in the lower 16 bits.
+ */
+#define SOCINFO_MAJOR(ver) (((ver) >> 16) & 0x)
+#define SOCINFO_MINOR(ver) ((ver) & 0x)
+
+#define SMEM_SOCINFO_BUILD_ID_LENGTH   32
+
+/*
+ * SMEM item ids, used to acquire handles to respective
+ * SMEM region.
+ */
+#define SMEM_HW_SW_BUILD_ID137
+
+/* Socinfo SMEM item structure */
+struct socinfo {
+   __le32 fmt;
+   __le32 id;
+   __le32 ver;
+   char build_id[SMEM_SOCINFO_BUILD_ID_LENGTH];
+   /* Version 2 */
+   __le32 raw_id;
+   __le32 raw_ver;
+   /* Version 3 */
+   __le32 hw_plat;
+   /* Version 4 */
+   __le32 plat_ver;
+   /* Version 5 */
+   __le32 accessory_chip;
+   /* Version 6 */
+   __le32 hw_plat_subtype;
+   /* Version 7 */
+   __le32 pmic_model;
+   __le32 pmic_die_rev;
+   /* Version 8 */
+   __le32 pmic_model_1;
+   __le32 pmic_die_rev_1;
+   __le32 pmic_model_2;
+   __le32 pmic_die_rev_2;
+   /* Version 9 */
+   __le32 foundry_id;
+   /* Version 10 */
+   __le32 serial_num;
+   /* Version 11 */
+   __le32 num_pmics;
+   __le32 pmic_array_offset;
+   /* Version 12 */
+   __le32 chip_family;
+   __le32 raw_device_family;
+

[PATCH v4 1/5] base: soc: Add serial_number attribute to soc

2019-02-24 Thread Vaishali Thakkar
From: Bjorn Andersson 

Add new attribute named "serial_number" as a standard interface for
user space to acquire the serial number of the device.

For ST-Ericsson SoCs this is exposed by the cryptically named "soc_id"
attribute, but this provides a human readable standardized name for this
property.

Signed-off-by: Bjorn Andersson 
Signed-off-by: Vaishali Thakkar 
Reviewed-by: Greg Kroah-Hartman 
---
Changes since v3:
- Add Greg's Reviewed-by
Changes since v2:
- None
Changes since v1:
- Make comment more clear for the case when serial
  number is not available
---
 Documentation/ABI/testing/sysfs-devices-soc | 7 +++
 drivers/base/soc.c  | 7 +++
 include/linux/sys_soc.h | 1 +
 3 files changed, 15 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-devices-soc 
b/Documentation/ABI/testing/sysfs-devices-soc
index 6d9cc253f2b2..ba3a3fac0ee1 100644
--- a/Documentation/ABI/testing/sysfs-devices-soc
+++ b/Documentation/ABI/testing/sysfs-devices-soc
@@ -26,6 +26,13 @@ Description:
Read-only attribute common to all SoCs. Contains SoC family name
(e.g. DB8500).
 
+What:  /sys/devices/socX/serial_number
+Date:  January 2019
+contact:   Bjorn Andersson 
+Description:
+   Read-only attribute supported by most SoCs. Contains the SoC's
+   serial number, if available.
+
 What:  /sys/devices/socX/soc_id
 Date:  January 2012
 contact:   Lee Jones 
diff --git a/drivers/base/soc.c b/drivers/base/soc.c
index 10b280f30217..b0933b9fe67f 100644
--- a/drivers/base/soc.c
+++ b/drivers/base/soc.c
@@ -33,6 +33,7 @@ static struct bus_type soc_bus_type = {
 
 static DEVICE_ATTR(machine,  S_IRUGO, soc_info_get,  NULL);
 static DEVICE_ATTR(family,   S_IRUGO, soc_info_get,  NULL);
+static DEVICE_ATTR(serial_number, S_IRUGO, soc_info_get,  NULL);
 static DEVICE_ATTR(soc_id,   S_IRUGO, soc_info_get,  NULL);
 static DEVICE_ATTR(revision, S_IRUGO, soc_info_get,  NULL);
 
@@ -57,6 +58,9 @@ static umode_t soc_attribute_mode(struct kobject *kobj,
if ((attr == _attr_revision.attr)
&& (soc_dev->attr->revision != NULL))
return attr->mode;
+   if ((attr == _attr_serial_number.attr)
+   && (soc_dev->attr->serial_number != NULL))
+   return attr->mode;
if ((attr == _attr_soc_id.attr)
&& (soc_dev->attr->soc_id != NULL))
return attr->mode;
@@ -77,6 +81,8 @@ static ssize_t soc_info_get(struct device *dev,
return sprintf(buf, "%s\n", soc_dev->attr->family);
if (attr == _attr_revision)
return sprintf(buf, "%s\n", soc_dev->attr->revision);
+   if (attr == _attr_serial_number)
+   return sprintf(buf, "%s\n", soc_dev->attr->serial_number);
if (attr == _attr_soc_id)
return sprintf(buf, "%s\n", soc_dev->attr->soc_id);
 
@@ -87,6 +93,7 @@ static ssize_t soc_info_get(struct device *dev,
 static struct attribute *soc_attr[] = {
_attr_machine.attr,
_attr_family.attr,
+   _attr_serial_number.attr,
_attr_soc_id.attr,
_attr_revision.attr,
NULL,
diff --git a/include/linux/sys_soc.h b/include/linux/sys_soc.h
index bed223b70217..2a13bc033bd6 100644
--- a/include/linux/sys_soc.h
+++ b/include/linux/sys_soc.h
@@ -12,6 +12,7 @@ struct soc_device_attribute {
const char *machine;
const char *family;
const char *revision;
+   const char *serial_number;
const char *soc_id;
const void *data;
 };
-- 
2.17.1



[PATCH v4 4/5] soc: qcom: socinfo: Expose custom attributes

2019-02-24 Thread Vaishali Thakkar
The Qualcomm socinfo provides a number of additional attributes,
add these to the socinfo driver and expose them via debugfs
functionality.

Signed-off-by: Vaishali Thakkar 
---
Changes since v3:
- Fix compilation error in function signatures when
  debugfs is disabled
Changes since v2:
- None
Changes since v1:
- Remove unnecessary debugfs dir creation check
- Align ifdefs to left
- Fix function signatures for debugfs init/exit
---
 drivers/soc/qcom/socinfo.c | 198 +
 1 file changed, 198 insertions(+)

diff --git a/drivers/soc/qcom/socinfo.c b/drivers/soc/qcom/socinfo.c
index 02078049fac7..ccadeba69a81 100644
--- a/drivers/soc/qcom/socinfo.c
+++ b/drivers/soc/qcom/socinfo.c
@@ -4,6 +4,7 @@
  * Copyright (c) 2017-2019, Linaro Ltd.
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -29,6 +30,28 @@
  */
 #define SMEM_HW_SW_BUILD_ID137
 
+#ifdef CONFIG_DEBUG_FS
+/* pmic model info */
+static const char *const pmic_model[] = {
+   [0]  = "Unknown PMIC model",
+   [9]  = "PM8994",
+   [11] = "PM8916",
+   [13] = "PM8058",
+   [14] = "PM8028",
+   [15] = "PM8901",
+   [16] = "PM8027",
+   [17] = "ISL9519",
+   [18] = "PM8921",
+   [19] = "PM8018",
+   [20] = "PM8015",
+   [21] = "PM8014",
+   [22] = "PM8821",
+   [23] = "PM8038",
+   [24] = "PM8922",
+   [25] = "PM8917",
+};
+#endif /* CONFIG_DEBUG_FS */
+
 /* Socinfo SMEM item structure */
 struct socinfo {
__le32 fmt;
@@ -70,6 +93,10 @@ struct socinfo {
 struct qcom_socinfo {
struct soc_device *soc_dev;
struct soc_device_attribute attr;
+#ifdef CONFIG_DEBUG_FS
+   struct dentry *dbg_root;
+#endif /* CONFIG_DEBUG_FS */
+   struct socinfo *socinfo;
 };
 
 struct soc_of_id {
@@ -133,6 +160,171 @@ static const char *socinfo_machine(struct device *dev, 
unsigned int id)
return NULL;
 }
 
+#ifdef CONFIG_DEBUG_FS
+
+#define UINT_SHOW(name, attr)  \
+static int qcom_show_##name(struct seq_file *seq, void *p) \
+{  \
+   struct socinfo *socinfo = seq->private; \
+   seq_printf(seq, "%u\n", le32_to_cpu(socinfo->attr));\
+   return 0;   \
+}  \
+static int qcom_open_##name(struct inode *inode, struct file *file)\
+{  \
+   return single_open(file, qcom_show_##name, inode->i_private);   \
+}  \
+   \
+static const struct file_operations qcom_ ##name## _ops = {\
+   .open = qcom_open_##name,   \
+   .read = seq_read,   \
+   .llseek = seq_lseek,\
+   .release = single_release,  \
+}
+
+#define DEBUGFS_UINT_ADD(name) \
+   debugfs_create_file(__stringify(name), 0400,\
+   qcom_socinfo->dbg_root, \
+   qcom_socinfo->socinfo, _ ##name## _ops)
+
+#define HEX_SHOW(name, attr)   \
+static int qcom_show_##name(struct seq_file *seq, void *p) \
+{  \
+   struct socinfo *socinfo = seq->private; \
+   seq_printf(seq, "0x%x\n", le32_to_cpu(socinfo->attr));  \
+   return 0;   \
+}  \
+static int qcom_open_##name(struct inode *inode, struct file *file)\
+{  \
+   return single_open(file, qcom_show_##name, inode->i_private);   \
+}  \
+   \
+static const struct file_operations qcom_ ##name## _ops = {\
+   .open = qcom_open_##name,   \
+   .read = seq_read,   \
+   .llseek = seq_lseek,\
+   .release = single_release, 

Re: [PATCH v3 5/5] soc: qcom: socinfo: Expose image information

2019-02-21 Thread Vaishali Thakkar
On Thu, 21 Feb 2019 at 22:04, Greg KH  wrote:
>
> On Thu, Feb 21, 2019 at 09:54:19PM +0530, Vaishali Thakkar wrote:
> >  static void socinfo_debugfs_init(struct qcom_socinfo *qcom_socinfo)
> >  {
> > + struct smem_image_version *smem_image_version;
> > + size_t size;
> > +
> >   qcom_socinfo->dbg_root = debugfs_create_dir("qcom_socinfo", NULL);
> >
> >   DEBUGFS_UINT_ADD(raw_version);
> > @@ -314,6 +432,98 @@ static void socinfo_debugfs_init(struct qcom_socinfo 
> > *qcom_socinfo)
> >   DEBUGFS_ADD(pmic_model);
> >   DEBUGFS_ADD(platform_subtype);
> >   DEBUGFS_ADD(pmic_die_revision);
> > +
> > + smem_image_version = qcom_smem_get(QCOM_SMEM_HOST_ANY,
> > +SMEM_IMAGE_VERSION_TABLE,
> > +);
> > +
> > + qcom_socinfo->boot = debugfs_create_dir("boot",
> > + qcom_socinfo->dbg_root);
> > + if (!qcom_socinfo->boot) {
> > + pr_err("Cannot create boot image directory\n");
> > + return;
> > + }
>
> You do not care, do not check please.  Also, even if you wanted to
> check, your error checking was wrong :)

I missed to remove all those checks in this patch. Will do. :)

> > + DEBUGFS_IMAGE_NAME(name, boot, SMEM_IMAGE_TABLE_BOOT_INDEX);
> > + DEBUGFS_IMAGE_VARIANT(variant, boot, SMEM_IMAGE_TABLE_BOOT_INDEX);
> > + DEBUGFS_IMAGE_OEM(oem, boot, SMEM_IMAGE_TABLE_BOOT_INDEX);
> > +
> > + qcom_socinfo->tz = debugfs_create_dir("tz",
> > +   qcom_socinfo->dbg_root);
> > + if (!qcom_socinfo->tz) {
> > + pr_err("Cannot create tz image directory\n");
> > + return;
> > + }
>
> Same here, no error checking please.
>
> > + DEBUGFS_IMAGE_NAME(name, tz, SMEM_IMAGE_TABLE_TZ_INDEX);
> > + DEBUGFS_IMAGE_VARIANT(variant, tz, SMEM_IMAGE_TABLE_TZ_INDEX);
> > + DEBUGFS_IMAGE_OEM(oem, tz, SMEM_IMAGE_TABLE_TZ_INDEX);
> > +
> > + qcom_socinfo->rpm = debugfs_create_dir("rpm",
> > +qcom_socinfo->dbg_root);
> > + if (!qcom_socinfo->rpm) {
> > + pr_err("Cannot create rpm image directory\n");
> > + return;
> > + }
>
> And here.
>
> > + DEBUGFS_IMAGE_NAME(name, rpm, SMEM_IMAGE_TABLE_RPM_INDEX);
> > + DEBUGFS_IMAGE_VARIANT(variant, rpm, SMEM_IMAGE_TABLE_RPM_INDEX);
> > + DEBUGFS_IMAGE_OEM(oem, rpm, SMEM_IMAGE_TABLE_RPM_INDEX);
> > +
> > + qcom_socinfo->apps = debugfs_create_dir("apps",
> > + qcom_socinfo->dbg_root);
> > + if (!qcom_socinfo->apps) {
> > + pr_err("Cannot create apps image directory\n");
> > + return;
> > + }
>
> And here.
>
> > + DEBUGFS_IMAGE_NAME(name, apps, SMEM_IMAGE_TABLE_APPS_INDEX);
> > + DEBUGFS_IMAGE_VARIANT(variant, apps, SMEM_IMAGE_TABLE_APPS_INDEX);
> > + DEBUGFS_IMAGE_OEM(oem, apps, SMEM_IMAGE_TABLE_APPS_INDEX);
> > +
> > + qcom_socinfo->mpss = debugfs_create_dir("mpss",
> > + qcom_socinfo->dbg_root);
> > + if (!qcom_socinfo->mpss) {
> > + pr_err("Cannot create mpss image directory\n");
> > + return;
> > + }
>
> Yet again...
>
> > +
> > + DEBUGFS_IMAGE_NAME(name, mpss, SMEM_IMAGE_TABLE_MPSS_INDEX);
> > + DEBUGFS_IMAGE_VARIANT(variant, mpss, SMEM_IMAGE_TABLE_MPSS_INDEX);
> > + DEBUGFS_IMAGE_OEM(oem, mpss, SMEM_IMAGE_TABLE_MPSS_INDEX);
> > +
> > + qcom_socinfo->adsp = debugfs_create_dir("adsp",
> > + qcom_socinfo->dbg_root);
> > + if (!qcom_socinfo->adsp) {
> > + pr_err("Cannot create adsp image directory\n");
> > + return;
> > + }
>
> And again...
>
> > +
> > + DEBUGFS_IMAGE_NAME(name, adsp, SMEM_IMAGE_TABLE_ADSP_INDEX);
> > + DEBUGFS_IMAGE_VARIANT(variant, adsp, SMEM_IMAGE_TABLE_ADSP_INDEX);
> > + DEBUGFS_IMAGE_OEM(oem, adsp, SMEM_IMAGE_TABLE_ADSP_INDEX);
> > +
> > + qcom_socinfo->cnss = debugfs_create_dir("cnss",
> > + qcom_socinfo->dbg_root);
> > + if (!qcom_socinfo->cnss) {
> > + pr_err("Cannot create cnss image directory\n");
> > + return;
> > + }
>
> And again...
>
> > +
> > + DEBUGFS_IMAGE_NAME(name, cnss, SMEM_IMAGE_TABLE_CNSS_INDEX);
> > + DEBUGFS_IMAGE_VARIANT(variant, cnss, SMEM_IMAGE_TABLE_CNSS_INDEX);
> > + DEBUGFS_IMAGE_OEM(oem, cnss, SMEM_IMAGE_TABLE_CNSS_INDEX);
> > +
> > + qcom_socinfo->video = debugfs_create_dir("video",
> > +  qcom_socinfo->dbg_root);
> > + if (!qcom_socinfo->video) {
> > + pr_err("Cannot create video image directory\n");
> > + return;
> > + }
>
> And one last time.
>
> There, you get to delete a bunch of code, that's always fun :)
>
> thanks,
>
> greg k-h


[PATCH v3 0/5] soc: qcom: Add SoC info driver

2019-02-21 Thread Vaishali Thakkar
This patchset adds SoC info driver which can provide information
such as Chip ID, Chip family and serial number about Qualcomm SoCs
to user space via sysfs. Furthermore, it allows userspace to get
information about custom attributes and various image version
information via debugfs.

The patchset cleanly applies on top of v5.0-rc6.

Changes since v1:
- Align ifdefs to left, remove unnecessary debugfs dir
  creation check and fix function signatures in patch 3
- Fix comment for teh case when serial number is not
  available in patch 1
Changes since v2:
- Reorder patches [patch five -> patch two]

Vaishali Thakkar (5):
  base: soc: Add serial_number attribute to soc
  base: soc: Export soc_device_register/unregister APIs
  soc: qcom: Add socinfo driver
  soc: qcom: socinfo: Expose custom attributes
  soc: qcom: socinfo: Expose image information

 Documentation/ABI/testing/sysfs-devices-soc |   7 +
 drivers/base/soc.c  |   9 +
 drivers/soc/qcom/Kconfig|   8 +
 drivers/soc/qcom/Makefile   |   1 +
 drivers/soc/qcom/smem.c |   8 +
 drivers/soc/qcom/socinfo.c  | 605 
 include/linux/sys_soc.h |   1 +
 7 files changed, 639 insertions(+)
 create mode 100644 drivers/soc/qcom/socinfo.c

-- 
2.17.1



[PATCH v3 5/5] soc: qcom: socinfo: Expose image information

2019-02-21 Thread Vaishali Thakkar
The socinfo driver provides information about version of the various
images loaded in the system. Expose this to user space for debugging
purpose.

Signed-off-by: Vaishali Thakkar 
---
Changes since v2:
- None
Changes since v1:
- None
---
 drivers/soc/qcom/socinfo.c | 210 +
 1 file changed, 210 insertions(+)

diff --git a/drivers/soc/qcom/socinfo.c b/drivers/soc/qcom/socinfo.c
index 5f4bef216ae1..f6a931ca8953 100644
--- a/drivers/soc/qcom/socinfo.c
+++ b/drivers/soc/qcom/socinfo.c
@@ -31,6 +31,25 @@
 #define SMEM_HW_SW_BUILD_ID137
 
 #ifdef CONFIG_DEBUG_FS
+#define SMEM_IMAGE_VERSION_BLOCKS_COUNT32
+#define SMEM_IMAGE_VERSION_SIZE4096
+#define SMEM_IMAGE_VERSION_NAME_SIZE   75
+#define SMEM_IMAGE_VERSION_VARIANT_SIZE20
+#define SMEM_IMAGE_VERSION_OEM_SIZE32
+
+/*
+ * SMEM Image table indices
+ */
+#define SMEM_IMAGE_TABLE_BOOT_INDEX 0
+#define SMEM_IMAGE_TABLE_TZ_INDEX   1
+#define SMEM_IMAGE_TABLE_RPM_INDEX  3
+#define SMEM_IMAGE_TABLE_APPS_INDEX 10
+#define SMEM_IMAGE_TABLE_MPSS_INDEX 11
+#define SMEM_IMAGE_TABLE_ADSP_INDEX 12
+#define SMEM_IMAGE_TABLE_CNSS_INDEX 13
+#define SMEM_IMAGE_TABLE_VIDEO_INDEX14
+#define SMEM_IMAGE_VERSION_TABLE   469
+
 /* pmic model info */
 static const char *const pmic_model[] = {
[0]  = "Unknown PMIC model",
@@ -90,11 +109,21 @@ struct socinfo {
__le32 raw_device_num;
 };
 
+#ifdef CONFIG_DEBUG_FS
+struct smem_image_version {
+   char name[SMEM_IMAGE_VERSION_NAME_SIZE];
+   char variant[SMEM_IMAGE_VERSION_VARIANT_SIZE];
+   char pad;
+   char oem[SMEM_IMAGE_VERSION_OEM_SIZE];
+};
+#endif /* CONFIG_DEBUG_FS */
+
 struct qcom_socinfo {
struct soc_device *soc_dev;
struct soc_device_attribute attr;
 #ifdef CONFIG_DEBUG_FS
struct dentry *dbg_root;
+   struct dentry *boot, *tz, *rpm, *apps, *mpss, *adsp, *cnss, *video;
 #endif /* CONFIG_DEBUG_FS */
struct socinfo *socinfo;
 };
@@ -298,8 +327,97 @@ QCOM_OPEN(pmic_model, qcom_show_pmic_model);
 QCOM_OPEN(platform_subtype, qcom_show_platform_subtype);
 QCOM_OPEN(pmic_die_revision, qcom_show_pmic_die_revision);
 
+#define IMAGE_SHOW_NAME(attr)\
+static int show_ ##attr## _name(struct seq_file *seq, void *p)   \
+{\
+   struct smem_image_version *image_version = seq->private;  \
+   seq_puts(seq, image_version->name);   \
+   seq_puts(seq, "\n");  \
+   return 0; \
+}\
+static int open_ ##attr## _name(struct inode *inode, struct file *file)
  \
+{\
+   return single_open(file, show_ ##attr## _name, inode->i_private); \
+}\
+ \
+static const struct file_operations qcom_ ##attr## _name_ops = { \
+   .open = open_ ##attr## _name, \
+   .read = seq_read, \
+   .llseek = seq_lseek,  \
+   .release = single_release,\
+}\
+
+#define DEBUGFS_IMAGE_NAME(fname, attr, index)   \
+debugfs_create_file(__stringify(fname), 0400, qcom_socinfo->attr,\
+   _image_version[index], _ ##attr## _name_ops)
+
+#define IMAGE_SHOW_VARIANT(attr)\
+static int show_ ##attr## _variant(struct seq_file *seq, void *p)   \
+{   \
+   struct smem_image_version *image_version = seq->private; \
+   seq_puts(seq, image_version->variant);   \
+   seq_puts(seq, "\n"); \
+   return 0;\
+}   \
+static int open_ ##attr## _variant(struct inode *inode, struct file *file)   \
+{\
+   return single_open(file, show_ ##attr## _variant, inode->i_private); \
+}   \
+

[PATCH v3 3/5] soc: qcom: Add socinfo driver

2019-02-21 Thread Vaishali Thakkar
From: Imran Khan 

The Qualcomm socinfo driver exposes information about the SoC, its
version and its serial number to user space.

Signed-off-by: Imran Khan 
[Bjorn: Extract code to platform_driver, split patch in multiple]
Signed-off-by: Bjorn Andersson 
[Vaishali: Simplify declarations, introduce qcom_socinfo struct, Fix
   memory leak, Remove extra code and Misc code refactoring]
Signed-off-by: Vaishali Thakkar 
---
Changes since v2:
- Fix typo in the work log under signed off by s
Changes since v1:
- None
---
 drivers/soc/qcom/Kconfig   |   8 ++
 drivers/soc/qcom/Makefile  |   1 +
 drivers/soc/qcom/smem.c|   8 ++
 drivers/soc/qcom/socinfo.c | 197 +
 4 files changed, 214 insertions(+)
 create mode 100644 drivers/soc/qcom/socinfo.c

diff --git a/drivers/soc/qcom/Kconfig b/drivers/soc/qcom/Kconfig
index fcbf8a2e4080..1e31eda07934 100644
--- a/drivers/soc/qcom/Kconfig
+++ b/drivers/soc/qcom/Kconfig
@@ -144,6 +144,14 @@ config QCOM_SMSM
  Say yes here to support the Qualcomm Shared Memory State Machine.
  The state machine is represented by bits in shared memory.
 
+config QCOM_SOCINFO
+   tristate "Qualcomm socinfo driver"
+   depends on QCOM_SMEM
+   select SOC_BUS
+   help
+Say yes here to support the Qualcomm socinfo driver, providing
+information about the SoC to user space.
+
 config QCOM_WCNSS_CTRL
tristate "Qualcomm WCNSS control driver"
depends on ARCH_QCOM || COMPILE_TEST
diff --git a/drivers/soc/qcom/Makefile b/drivers/soc/qcom/Makefile
index f25b54cd6cf8..c817da4f4140 100644
--- a/drivers/soc/qcom/Makefile
+++ b/drivers/soc/qcom/Makefile
@@ -14,6 +14,7 @@ qcom_rpmh-y   += rpmh-rsc.o
 qcom_rpmh-y+= rpmh.o
 obj-$(CONFIG_QCOM_SMD_RPM) += smd-rpm.o
 obj-$(CONFIG_QCOM_SMEM) += smem.o
+obj-$(CONFIG_QCOM_SOCINFO) += socinfo.o
 obj-$(CONFIG_QCOM_SMEM_STATE) += smem_state.o
 obj-$(CONFIG_QCOM_SMP2P)   += smp2p.o
 obj-$(CONFIG_QCOM_SMSM)+= smsm.o
diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c
index f80d040601fd..efe0b053ef82 100644
--- a/drivers/soc/qcom/smem.c
+++ b/drivers/soc/qcom/smem.c
@@ -276,6 +276,7 @@ struct qcom_smem {
struct smem_partition_header *partitions[SMEM_HOST_COUNT];
size_t cacheline[SMEM_HOST_COUNT];
u32 item_count;
+   struct platform_device *socinfo;
 
unsigned num_regions;
struct smem_region regions[];
@@ -971,11 +972,18 @@ static int qcom_smem_probe(struct platform_device *pdev)
 
__smem = smem;
 
+   smem->socinfo = platform_device_register_data(>dev, 
"qcom-socinfo",
+ PLATFORM_DEVID_NONE, NULL,
+ 0);
+   if (IS_ERR(smem->socinfo))
+   dev_err(>dev, "failed to register socinfo device\n");
+
return 0;
 }
 
 static int qcom_smem_remove(struct platform_device *pdev)
 {
+
hwspin_lock_free(__smem->hwlock);
__smem = NULL;
 
diff --git a/drivers/soc/qcom/socinfo.c b/drivers/soc/qcom/socinfo.c
new file mode 100644
index ..02078049fac7
--- /dev/null
+++ b/drivers/soc/qcom/socinfo.c
@@ -0,0 +1,197 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2009-2017, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2017-2019, Linaro Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * SoC version type with major number in the upper 16 bits and minor
+ * number in the lower 16 bits.
+ */
+#define SOCINFO_MAJOR(ver) (((ver) >> 16) & 0x)
+#define SOCINFO_MINOR(ver) ((ver) & 0x)
+
+#define SMEM_SOCINFO_BUILD_ID_LENGTH   32
+
+/*
+ * SMEM item ids, used to acquire handles to respective
+ * SMEM region.
+ */
+#define SMEM_HW_SW_BUILD_ID137
+
+/* Socinfo SMEM item structure */
+struct socinfo {
+   __le32 fmt;
+   __le32 id;
+   __le32 ver;
+   char build_id[SMEM_SOCINFO_BUILD_ID_LENGTH];
+   /* Version 2 */
+   __le32 raw_id;
+   __le32 raw_ver;
+   /* Version 3 */
+   __le32 hw_plat;
+   /* Version 4 */
+   __le32 plat_ver;
+   /* Version 5 */
+   __le32 accessory_chip;
+   /* Version 6 */
+   __le32 hw_plat_subtype;
+   /* Version 7 */
+   __le32 pmic_model;
+   __le32 pmic_die_rev;
+   /* Version 8 */
+   __le32 pmic_model_1;
+   __le32 pmic_die_rev_1;
+   __le32 pmic_model_2;
+   __le32 pmic_die_rev_2;
+   /* Version 9 */
+   __le32 foundry_id;
+   /* Version 10 */
+   __le32 serial_num;
+   /* Version 11 */
+   __le32 num_pmics;
+   __le32 pmic_array_offset;
+   /* Version 12 */
+   __le32 chip_family;
+   __le32 raw_device_family;
+   __le32 raw_device_num;
+};
+
+str

[PATCH v3 2/5] base: soc: Export soc_device_register/unregister APIs

2019-02-21 Thread Vaishali Thakkar
From: Vinod Koul 

Qcom Socinfo driver can be built as a module, so
export these two APIs.

Signed-off-by: Vinod Koul 
Signed-off-by: Vaishali Thakkar 
---
Changes since v2:
- Reordered patches [patch 5->patch 2]
Changes since v1:
- None
---
 drivers/base/soc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/base/soc.c b/drivers/base/soc.c
index b0933b9fe67f..7c0c5ca5953d 100644
--- a/drivers/base/soc.c
+++ b/drivers/base/soc.c
@@ -164,6 +164,7 @@ struct soc_device *soc_device_register(struct 
soc_device_attribute *soc_dev_attr
 out1:
return ERR_PTR(ret);
 }
+EXPORT_SYMBOL_GPL(soc_device_register);
 
 /* Ensure soc_dev->attr is freed prior to calling soc_device_unregister. */
 void soc_device_unregister(struct soc_device *soc_dev)
@@ -173,6 +174,7 @@ void soc_device_unregister(struct soc_device *soc_dev)
device_unregister(_dev->dev);
early_soc_dev_attr = NULL;
 }
+EXPORT_SYMBOL_GPL(soc_device_unregister);
 
 static int __init soc_bus_register(void)
 {
-- 
2.17.1



[PATCH v3 4/5] soc: qcom: socinfo: Expose custom attributes

2019-02-21 Thread Vaishali Thakkar
The Qualcomm socinfo provides a number of additional attributes,
add these to the socinfo driver and expose them via debugfs
functionality.

Signed-off-by: Vaishali Thakkar 
---
Changes since v2:
- None
Changes since v1:
- Remove unnecessary debugfs dir creation check
- Align ifdefs to left
- Fix function signatures for debugfs init/exit
---
 drivers/soc/qcom/socinfo.c | 198 +
 1 file changed, 198 insertions(+)

diff --git a/drivers/soc/qcom/socinfo.c b/drivers/soc/qcom/socinfo.c
index 02078049fac7..5f4bef216ae1 100644
--- a/drivers/soc/qcom/socinfo.c
+++ b/drivers/soc/qcom/socinfo.c
@@ -4,6 +4,7 @@
  * Copyright (c) 2017-2019, Linaro Ltd.
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -29,6 +30,28 @@
  */
 #define SMEM_HW_SW_BUILD_ID137
 
+#ifdef CONFIG_DEBUG_FS
+/* pmic model info */
+static const char *const pmic_model[] = {
+   [0]  = "Unknown PMIC model",
+   [9]  = "PM8994",
+   [11] = "PM8916",
+   [13] = "PM8058",
+   [14] = "PM8028",
+   [15] = "PM8901",
+   [16] = "PM8027",
+   [17] = "ISL9519",
+   [18] = "PM8921",
+   [19] = "PM8018",
+   [20] = "PM8015",
+   [21] = "PM8014",
+   [22] = "PM8821",
+   [23] = "PM8038",
+   [24] = "PM8922",
+   [25] = "PM8917",
+};
+#endif /* CONFIG_DEBUG_FS */
+
 /* Socinfo SMEM item structure */
 struct socinfo {
__le32 fmt;
@@ -70,6 +93,10 @@ struct socinfo {
 struct qcom_socinfo {
struct soc_device *soc_dev;
struct soc_device_attribute attr;
+#ifdef CONFIG_DEBUG_FS
+   struct dentry *dbg_root;
+#endif /* CONFIG_DEBUG_FS */
+   struct socinfo *socinfo;
 };
 
 struct soc_of_id {
@@ -133,6 +160,171 @@ static const char *socinfo_machine(struct device *dev, 
unsigned int id)
return NULL;
 }
 
+#ifdef CONFIG_DEBUG_FS
+
+#define UINT_SHOW(name, attr)  \
+static int qcom_show_##name(struct seq_file *seq, void *p) \
+{  \
+   struct socinfo *socinfo = seq->private; \
+   seq_printf(seq, "%u\n", le32_to_cpu(socinfo->attr));\
+   return 0;   \
+}  \
+static int qcom_open_##name(struct inode *inode, struct file *file)\
+{  \
+   return single_open(file, qcom_show_##name, inode->i_private);   \
+}  \
+   \
+static const struct file_operations qcom_ ##name## _ops = {\
+   .open = qcom_open_##name,   \
+   .read = seq_read,   \
+   .llseek = seq_lseek,\
+   .release = single_release,  \
+}
+
+#define DEBUGFS_UINT_ADD(name) \
+   debugfs_create_file(__stringify(name), 0400,\
+   qcom_socinfo->dbg_root, \
+   qcom_socinfo->socinfo, _ ##name## _ops)
+
+#define HEX_SHOW(name, attr)   \
+static int qcom_show_##name(struct seq_file *seq, void *p) \
+{  \
+   struct socinfo *socinfo = seq->private; \
+   seq_printf(seq, "0x%x\n", le32_to_cpu(socinfo->attr));  \
+   return 0;   \
+}  \
+static int qcom_open_##name(struct inode *inode, struct file *file)\
+{  \
+   return single_open(file, qcom_show_##name, inode->i_private);   \
+}  \
+   \
+static const struct file_operations qcom_ ##name## _ops = {\
+   .open = qcom_open_##name,   \
+   .read = seq_read,   \
+   .llseek = seq_lseek,\
+   .release = single_release,  \
+}
+
+#define DEBUGFS_HEX_ADD(name)  \
+   de

[PATCH v3 1/5] base: soc: Add serial_number attribute to soc

2019-02-21 Thread Vaishali Thakkar
From: Bjorn Andersson 

Add new attribute named "serial_number" as a standard interface for
user space to acquire the serial number of the device.

For ST-Ericsson SoCs this is exposed by the cryptically named "soc_id"
attribute, but this provides a human readable standardized name for this
property.

Signed-off-by: Bjorn Andersson 
Signed-off-by: Vaishali Thakkar 
---
Changes since v2:
- None
Changes since v1:
- Make comment more clear for the case when serial
  number is not available
---
 Documentation/ABI/testing/sysfs-devices-soc | 7 +++
 drivers/base/soc.c  | 7 +++
 include/linux/sys_soc.h | 1 +
 3 files changed, 15 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-devices-soc 
b/Documentation/ABI/testing/sysfs-devices-soc
index 6d9cc253f2b2..ba3a3fac0ee1 100644
--- a/Documentation/ABI/testing/sysfs-devices-soc
+++ b/Documentation/ABI/testing/sysfs-devices-soc
@@ -26,6 +26,13 @@ Description:
Read-only attribute common to all SoCs. Contains SoC family name
(e.g. DB8500).
 
+What:  /sys/devices/socX/serial_number
+Date:  January 2019
+contact:   Bjorn Andersson 
+Description:
+   Read-only attribute supported by most SoCs. Contains the SoC's
+   serial number, if available.
+
 What:  /sys/devices/socX/soc_id
 Date:  January 2012
 contact:   Lee Jones 
diff --git a/drivers/base/soc.c b/drivers/base/soc.c
index 10b280f30217..b0933b9fe67f 100644
--- a/drivers/base/soc.c
+++ b/drivers/base/soc.c
@@ -33,6 +33,7 @@ static struct bus_type soc_bus_type = {
 
 static DEVICE_ATTR(machine,  S_IRUGO, soc_info_get,  NULL);
 static DEVICE_ATTR(family,   S_IRUGO, soc_info_get,  NULL);
+static DEVICE_ATTR(serial_number, S_IRUGO, soc_info_get,  NULL);
 static DEVICE_ATTR(soc_id,   S_IRUGO, soc_info_get,  NULL);
 static DEVICE_ATTR(revision, S_IRUGO, soc_info_get,  NULL);
 
@@ -57,6 +58,9 @@ static umode_t soc_attribute_mode(struct kobject *kobj,
if ((attr == _attr_revision.attr)
&& (soc_dev->attr->revision != NULL))
return attr->mode;
+   if ((attr == _attr_serial_number.attr)
+   && (soc_dev->attr->serial_number != NULL))
+   return attr->mode;
if ((attr == _attr_soc_id.attr)
&& (soc_dev->attr->soc_id != NULL))
return attr->mode;
@@ -77,6 +81,8 @@ static ssize_t soc_info_get(struct device *dev,
return sprintf(buf, "%s\n", soc_dev->attr->family);
if (attr == _attr_revision)
return sprintf(buf, "%s\n", soc_dev->attr->revision);
+   if (attr == _attr_serial_number)
+   return sprintf(buf, "%s\n", soc_dev->attr->serial_number);
if (attr == _attr_soc_id)
return sprintf(buf, "%s\n", soc_dev->attr->soc_id);
 
@@ -87,6 +93,7 @@ static ssize_t soc_info_get(struct device *dev,
 static struct attribute *soc_attr[] = {
_attr_machine.attr,
_attr_family.attr,
+   _attr_serial_number.attr,
_attr_soc_id.attr,
_attr_revision.attr,
NULL,
diff --git a/include/linux/sys_soc.h b/include/linux/sys_soc.h
index bed223b70217..2a13bc033bd6 100644
--- a/include/linux/sys_soc.h
+++ b/include/linux/sys_soc.h
@@ -12,6 +12,7 @@ struct soc_device_attribute {
const char *machine;
const char *family;
const char *revision;
+   const char *serial_number;
const char *soc_id;
const void *data;
 };
-- 
2.17.1



Re: [PATCH v2 5/5] base: soc: Export soc_device_register/unregister APIs

2019-02-20 Thread Vaishali Thakkar
On Wed, 20 Feb 2019 at 12:25, Greg KH  wrote:
>
> On Wed, Feb 20, 2019 at 10:29:46AM +0530, Vaishali Thakkar wrote:
> > From: Vinod Koul 
> >
> > Qcom Socinfo driver can be built as a module, so
> > export these two APIs.
> >
> > Signed-off-by: Vinod Koul 
> > Signed-off-by: Vaishali Thakkar 
> > ---
> > Changes since v1:
> >   - None
>
> This is fixing a build breakage introduced by an earlier patch.  Please
> rearange the patches so that breakage never happens.

Ok, yes. I'll put it as patch two [before adding socinfo driver].

> Also, any chance you can properly "thread" your patches so they all show
> up together?  git send-email does this automatically...

I'm using send-email only but I was sending it one by one. I believe
that's the reason why didn't come as a thread. I'll fix that in next version
too.

> thanks,
>
> greg k-h


[PATCH v2 5/5] base: soc: Export soc_device_register/unregister APIs

2019-02-19 Thread Vaishali Thakkar
From: Vinod Koul 

Qcom Socinfo driver can be built as a module, so
export these two APIs.

Signed-off-by: Vinod Koul 
Signed-off-by: Vaishali Thakkar 
---
Changes since v1:
- None
---
 drivers/base/soc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/base/soc.c b/drivers/base/soc.c
index b0933b9fe67f..7c0c5ca5953d 100644
--- a/drivers/base/soc.c
+++ b/drivers/base/soc.c
@@ -164,6 +164,7 @@ struct soc_device *soc_device_register(struct 
soc_device_attribute *soc_dev_attr
 out1:
return ERR_PTR(ret);
 }
+EXPORT_SYMBOL_GPL(soc_device_register);
 
 /* Ensure soc_dev->attr is freed prior to calling soc_device_unregister. */
 void soc_device_unregister(struct soc_device *soc_dev)
@@ -173,6 +174,7 @@ void soc_device_unregister(struct soc_device *soc_dev)
device_unregister(_dev->dev);
early_soc_dev_attr = NULL;
 }
+EXPORT_SYMBOL_GPL(soc_device_unregister);
 
 static int __init soc_bus_register(void)
 {
-- 
2.17.1



[PATCH v2 2/5] soc: qcom: Add socinfo driver

2019-02-19 Thread Vaishali Thakkar
From: Imran Khan 

The Qualcomm socinfo driver exposes information about the SoC, its
version and its serial number to user space.

Signed-off-by: Imran Khan 
[Bjorn: Extract code to platform_driver, split patch in multiple]
Signed-off-by: Bjorn Andersson 
[Vaishali: Simplify declarations, introduce qcom_socinfo struc, Fix
   memory leak, Remove extra code and Misc code refactoring]
Signed-off-by: Vaishali Thakkar 
---
Changes since v1:
- None
---
 drivers/soc/qcom/Kconfig   |   8 ++
 drivers/soc/qcom/Makefile  |   1 +
 drivers/soc/qcom/smem.c|   8 ++
 drivers/soc/qcom/socinfo.c | 197 +
 4 files changed, 214 insertions(+)
 create mode 100644 drivers/soc/qcom/socinfo.c

diff --git a/drivers/soc/qcom/Kconfig b/drivers/soc/qcom/Kconfig
index fcbf8a2e4080..1e31eda07934 100644
--- a/drivers/soc/qcom/Kconfig
+++ b/drivers/soc/qcom/Kconfig
@@ -144,6 +144,14 @@ config QCOM_SMSM
  Say yes here to support the Qualcomm Shared Memory State Machine.
  The state machine is represented by bits in shared memory.
 
+config QCOM_SOCINFO
+   tristate "Qualcomm socinfo driver"
+   depends on QCOM_SMEM
+   select SOC_BUS
+   help
+Say yes here to support the Qualcomm socinfo driver, providing
+information about the SoC to user space.
+
 config QCOM_WCNSS_CTRL
tristate "Qualcomm WCNSS control driver"
depends on ARCH_QCOM || COMPILE_TEST
diff --git a/drivers/soc/qcom/Makefile b/drivers/soc/qcom/Makefile
index f25b54cd6cf8..c817da4f4140 100644
--- a/drivers/soc/qcom/Makefile
+++ b/drivers/soc/qcom/Makefile
@@ -14,6 +14,7 @@ qcom_rpmh-y   += rpmh-rsc.o
 qcom_rpmh-y+= rpmh.o
 obj-$(CONFIG_QCOM_SMD_RPM) += smd-rpm.o
 obj-$(CONFIG_QCOM_SMEM) += smem.o
+obj-$(CONFIG_QCOM_SOCINFO) += socinfo.o
 obj-$(CONFIG_QCOM_SMEM_STATE) += smem_state.o
 obj-$(CONFIG_QCOM_SMP2P)   += smp2p.o
 obj-$(CONFIG_QCOM_SMSM)+= smsm.o
diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c
index f80d040601fd..efe0b053ef82 100644
--- a/drivers/soc/qcom/smem.c
+++ b/drivers/soc/qcom/smem.c
@@ -276,6 +276,7 @@ struct qcom_smem {
struct smem_partition_header *partitions[SMEM_HOST_COUNT];
size_t cacheline[SMEM_HOST_COUNT];
u32 item_count;
+   struct platform_device *socinfo;
 
unsigned num_regions;
struct smem_region regions[];
@@ -971,11 +972,18 @@ static int qcom_smem_probe(struct platform_device *pdev)
 
__smem = smem;
 
+   smem->socinfo = platform_device_register_data(>dev, 
"qcom-socinfo",
+ PLATFORM_DEVID_NONE, NULL,
+ 0);
+   if (IS_ERR(smem->socinfo))
+   dev_err(>dev, "failed to register socinfo device\n");
+
return 0;
 }
 
 static int qcom_smem_remove(struct platform_device *pdev)
 {
+
hwspin_lock_free(__smem->hwlock);
__smem = NULL;
 
diff --git a/drivers/soc/qcom/socinfo.c b/drivers/soc/qcom/socinfo.c
new file mode 100644
index ..02078049fac7
--- /dev/null
+++ b/drivers/soc/qcom/socinfo.c
@@ -0,0 +1,197 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2009-2017, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2017-2019, Linaro Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * SoC version type with major number in the upper 16 bits and minor
+ * number in the lower 16 bits.
+ */
+#define SOCINFO_MAJOR(ver) (((ver) >> 16) & 0x)
+#define SOCINFO_MINOR(ver) ((ver) & 0x)
+
+#define SMEM_SOCINFO_BUILD_ID_LENGTH   32
+
+/*
+ * SMEM item ids, used to acquire handles to respective
+ * SMEM region.
+ */
+#define SMEM_HW_SW_BUILD_ID137
+
+/* Socinfo SMEM item structure */
+struct socinfo {
+   __le32 fmt;
+   __le32 id;
+   __le32 ver;
+   char build_id[SMEM_SOCINFO_BUILD_ID_LENGTH];
+   /* Version 2 */
+   __le32 raw_id;
+   __le32 raw_ver;
+   /* Version 3 */
+   __le32 hw_plat;
+   /* Version 4 */
+   __le32 plat_ver;
+   /* Version 5 */
+   __le32 accessory_chip;
+   /* Version 6 */
+   __le32 hw_plat_subtype;
+   /* Version 7 */
+   __le32 pmic_model;
+   __le32 pmic_die_rev;
+   /* Version 8 */
+   __le32 pmic_model_1;
+   __le32 pmic_die_rev_1;
+   __le32 pmic_model_2;
+   __le32 pmic_die_rev_2;
+   /* Version 9 */
+   __le32 foundry_id;
+   /* Version 10 */
+   __le32 serial_num;
+   /* Version 11 */
+   __le32 num_pmics;
+   __le32 pmic_array_offset;
+   /* Version 12 */
+   __le32 chip_family;
+   __le32 raw_device_family;
+   __le32 raw_device_num;
+};
+
+struct qcom_socinfo {
+   struct soc_device *soc_dev;
+   struct soc_dev

[PATCH v2 3/5] soc: qcom: socinfo: Expose custom attributes

2019-02-19 Thread Vaishali Thakkar
The Qualcomm socinfo provides a number of additional attributes,
add these to the socinfo driver and expose them via debugfs
functionality.

Signed-off-by: Vaishali Thakkar 
---
Changes since v1:
- Remove unnecessary debugfs dir creation check
- Align ifdefs to left
- Fix function signatures for debugfs init/exit
---
 drivers/soc/qcom/socinfo.c | 198 +
 1 file changed, 198 insertions(+)

diff --git a/drivers/soc/qcom/socinfo.c b/drivers/soc/qcom/socinfo.c
index 02078049fac7..5f4bef216ae1 100644
--- a/drivers/soc/qcom/socinfo.c
+++ b/drivers/soc/qcom/socinfo.c
@@ -4,6 +4,7 @@
  * Copyright (c) 2017-2019, Linaro Ltd.
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -29,6 +30,28 @@
  */
 #define SMEM_HW_SW_BUILD_ID137
 
+#ifdef CONFIG_DEBUG_FS
+/* pmic model info */
+static const char *const pmic_model[] = {
+   [0]  = "Unknown PMIC model",
+   [9]  = "PM8994",
+   [11] = "PM8916",
+   [13] = "PM8058",
+   [14] = "PM8028",
+   [15] = "PM8901",
+   [16] = "PM8027",
+   [17] = "ISL9519",
+   [18] = "PM8921",
+   [19] = "PM8018",
+   [20] = "PM8015",
+   [21] = "PM8014",
+   [22] = "PM8821",
+   [23] = "PM8038",
+   [24] = "PM8922",
+   [25] = "PM8917",
+};
+#endif /* CONFIG_DEBUG_FS */
+
 /* Socinfo SMEM item structure */
 struct socinfo {
__le32 fmt;
@@ -70,6 +93,10 @@ struct socinfo {
 struct qcom_socinfo {
struct soc_device *soc_dev;
struct soc_device_attribute attr;
+#ifdef CONFIG_DEBUG_FS
+   struct dentry *dbg_root;
+#endif /* CONFIG_DEBUG_FS */
+   struct socinfo *socinfo;
 };
 
 struct soc_of_id {
@@ -133,6 +160,171 @@ static const char *socinfo_machine(struct device *dev, 
unsigned int id)
return NULL;
 }
 
+#ifdef CONFIG_DEBUG_FS
+
+#define UINT_SHOW(name, attr)  \
+static int qcom_show_##name(struct seq_file *seq, void *p) \
+{  \
+   struct socinfo *socinfo = seq->private; \
+   seq_printf(seq, "%u\n", le32_to_cpu(socinfo->attr));\
+   return 0;   \
+}  \
+static int qcom_open_##name(struct inode *inode, struct file *file)\
+{  \
+   return single_open(file, qcom_show_##name, inode->i_private);   \
+}  \
+   \
+static const struct file_operations qcom_ ##name## _ops = {\
+   .open = qcom_open_##name,   \
+   .read = seq_read,   \
+   .llseek = seq_lseek,\
+   .release = single_release,  \
+}
+
+#define DEBUGFS_UINT_ADD(name) \
+   debugfs_create_file(__stringify(name), 0400,\
+   qcom_socinfo->dbg_root, \
+   qcom_socinfo->socinfo, _ ##name## _ops)
+
+#define HEX_SHOW(name, attr)   \
+static int qcom_show_##name(struct seq_file *seq, void *p) \
+{  \
+   struct socinfo *socinfo = seq->private; \
+   seq_printf(seq, "0x%x\n", le32_to_cpu(socinfo->attr));  \
+   return 0;   \
+}  \
+static int qcom_open_##name(struct inode *inode, struct file *file)\
+{  \
+   return single_open(file, qcom_show_##name, inode->i_private);   \
+}  \
+   \
+static const struct file_operations qcom_ ##name## _ops = {\
+   .open = qcom_open_##name,   \
+   .read = seq_read,   \
+   .llseek = seq_lseek,\
+   .release = single_release,  \
+}
+
+#define DEBUGFS_HEX_ADD(name)  \
+   debugfs_create_file(__stringify(name),

[PATCH v2 4/5] soc: qcom: socinfo: Expose image information

2019-02-19 Thread Vaishali Thakkar
The socinfo driver provides information about version of the various
images loaded in the system. Expose this to user space for debugging
purpose.

Signed-off-by: Vaishali Thakkar 
---
Changes since v1:
- None
---
 drivers/soc/qcom/socinfo.c | 210 +
 1 file changed, 210 insertions(+)

diff --git a/drivers/soc/qcom/socinfo.c b/drivers/soc/qcom/socinfo.c
index 5f4bef216ae1..f6a931ca8953 100644
--- a/drivers/soc/qcom/socinfo.c
+++ b/drivers/soc/qcom/socinfo.c
@@ -31,6 +31,25 @@
 #define SMEM_HW_SW_BUILD_ID137
 
 #ifdef CONFIG_DEBUG_FS
+#define SMEM_IMAGE_VERSION_BLOCKS_COUNT32
+#define SMEM_IMAGE_VERSION_SIZE4096
+#define SMEM_IMAGE_VERSION_NAME_SIZE   75
+#define SMEM_IMAGE_VERSION_VARIANT_SIZE20
+#define SMEM_IMAGE_VERSION_OEM_SIZE32
+
+/*
+ * SMEM Image table indices
+ */
+#define SMEM_IMAGE_TABLE_BOOT_INDEX 0
+#define SMEM_IMAGE_TABLE_TZ_INDEX   1
+#define SMEM_IMAGE_TABLE_RPM_INDEX  3
+#define SMEM_IMAGE_TABLE_APPS_INDEX 10
+#define SMEM_IMAGE_TABLE_MPSS_INDEX 11
+#define SMEM_IMAGE_TABLE_ADSP_INDEX 12
+#define SMEM_IMAGE_TABLE_CNSS_INDEX 13
+#define SMEM_IMAGE_TABLE_VIDEO_INDEX14
+#define SMEM_IMAGE_VERSION_TABLE   469
+
 /* pmic model info */
 static const char *const pmic_model[] = {
[0]  = "Unknown PMIC model",
@@ -90,11 +109,21 @@ struct socinfo {
__le32 raw_device_num;
 };
 
+#ifdef CONFIG_DEBUG_FS
+struct smem_image_version {
+   char name[SMEM_IMAGE_VERSION_NAME_SIZE];
+   char variant[SMEM_IMAGE_VERSION_VARIANT_SIZE];
+   char pad;
+   char oem[SMEM_IMAGE_VERSION_OEM_SIZE];
+};
+#endif /* CONFIG_DEBUG_FS */
+
 struct qcom_socinfo {
struct soc_device *soc_dev;
struct soc_device_attribute attr;
 #ifdef CONFIG_DEBUG_FS
struct dentry *dbg_root;
+   struct dentry *boot, *tz, *rpm, *apps, *mpss, *adsp, *cnss, *video;
 #endif /* CONFIG_DEBUG_FS */
struct socinfo *socinfo;
 };
@@ -298,8 +327,97 @@ QCOM_OPEN(pmic_model, qcom_show_pmic_model);
 QCOM_OPEN(platform_subtype, qcom_show_platform_subtype);
 QCOM_OPEN(pmic_die_revision, qcom_show_pmic_die_revision);
 
+#define IMAGE_SHOW_NAME(attr)\
+static int show_ ##attr## _name(struct seq_file *seq, void *p)   \
+{\
+   struct smem_image_version *image_version = seq->private;  \
+   seq_puts(seq, image_version->name);   \
+   seq_puts(seq, "\n");  \
+   return 0; \
+}\
+static int open_ ##attr## _name(struct inode *inode, struct file *file)
  \
+{\
+   return single_open(file, show_ ##attr## _name, inode->i_private); \
+}\
+ \
+static const struct file_operations qcom_ ##attr## _name_ops = { \
+   .open = open_ ##attr## _name, \
+   .read = seq_read, \
+   .llseek = seq_lseek,  \
+   .release = single_release,\
+}\
+
+#define DEBUGFS_IMAGE_NAME(fname, attr, index)   \
+debugfs_create_file(__stringify(fname), 0400, qcom_socinfo->attr,\
+   _image_version[index], _ ##attr## _name_ops)
+
+#define IMAGE_SHOW_VARIANT(attr)\
+static int show_ ##attr## _variant(struct seq_file *seq, void *p)   \
+{   \
+   struct smem_image_version *image_version = seq->private; \
+   seq_puts(seq, image_version->variant);   \
+   seq_puts(seq, "\n"); \
+   return 0;\
+}   \
+static int open_ ##attr## _variant(struct inode *inode, struct file *file)   \
+{\
+   return single_open(file, show_ ##attr## _variant, inode->i_private); \
+}   \
+\
+static const

[PATCH v2 0/5] soc: qcom: Add SoC info driver

2019-02-19 Thread Vaishali Thakkar
This patchset adds SoC info driver which can provide information
such as Chip ID, Chip family and serial number about Qualcomm SoCs
to user space via sysfs. Furthermore, it allows userspace to get
information about custom attributes and various image version
information via debugfs.

The patchset cleanly applies on top of v5.0-rc6.

Changes since v1:
- Align ifdefs to left, remove unnecessary debugfs dir
  creation check and fix function signatures in patch 3
- Fix comment for teh case when serial number is not
  available in patch 1

Vaishali Thakkar (5):
  base: soc: Add serial_number attribute to soc
  soc: qcom: Add socinfo driver
  soc: qcom: socinfo: Expose custom attributes
  soc: qcom: socinfo: Expose image information
  base: soc: Export soc_device_register/unregister APIs

 Documentation/ABI/testing/sysfs-devices-soc |   7 +
 drivers/base/soc.c  |   9 +
 drivers/soc/qcom/Kconfig|   8 +
 drivers/soc/qcom/Makefile   |   1 +
 drivers/soc/qcom/smem.c |   8 +
 drivers/soc/qcom/socinfo.c  | 605 
 include/linux/sys_soc.h |   1 +
 7 files changed, 639 insertions(+)
 create mode 100644 drivers/soc/qcom/socinfo.c

-- 
2.17.1



[PATCH v2 1/5] base: soc: Add serial_number attribute to soc

2019-02-19 Thread Vaishali Thakkar
From: Bjorn Andersson 

Add new attribute named "serial_number" as a standard interface for
user space to acquire the serial number of the device.

For ST-Ericsson SoCs this is exposed by the cryptically named "soc_id"
attribute, but this provides a human readable standardized name for this
property.

Signed-off-by: Bjorn Andersson 
Signed-off-by: Vaishali Thakkar 
---
Changes since v1:
- Make comment more clear for the case when serial
  number is not available
---
 Documentation/ABI/testing/sysfs-devices-soc | 7 +++
 drivers/base/soc.c  | 7 +++
 include/linux/sys_soc.h | 1 +
 3 files changed, 15 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-devices-soc 
b/Documentation/ABI/testing/sysfs-devices-soc
index 6d9cc253f2b2..ba3a3fac0ee1 100644
--- a/Documentation/ABI/testing/sysfs-devices-soc
+++ b/Documentation/ABI/testing/sysfs-devices-soc
@@ -26,6 +26,13 @@ Description:
Read-only attribute common to all SoCs. Contains SoC family name
(e.g. DB8500).
 
+What:  /sys/devices/socX/serial_number
+Date:  January 2019
+contact:   Bjorn Andersson 
+Description:
+   Read-only attribute supported by most SoCs. Contains the SoC's
+   serial number, if available.
+
 What:  /sys/devices/socX/soc_id
 Date:  January 2012
 contact:   Lee Jones 
diff --git a/drivers/base/soc.c b/drivers/base/soc.c
index 10b280f30217..b0933b9fe67f 100644
--- a/drivers/base/soc.c
+++ b/drivers/base/soc.c
@@ -33,6 +33,7 @@ static struct bus_type soc_bus_type = {
 
 static DEVICE_ATTR(machine,  S_IRUGO, soc_info_get,  NULL);
 static DEVICE_ATTR(family,   S_IRUGO, soc_info_get,  NULL);
+static DEVICE_ATTR(serial_number, S_IRUGO, soc_info_get,  NULL);
 static DEVICE_ATTR(soc_id,   S_IRUGO, soc_info_get,  NULL);
 static DEVICE_ATTR(revision, S_IRUGO, soc_info_get,  NULL);
 
@@ -57,6 +58,9 @@ static umode_t soc_attribute_mode(struct kobject *kobj,
if ((attr == _attr_revision.attr)
&& (soc_dev->attr->revision != NULL))
return attr->mode;
+   if ((attr == _attr_serial_number.attr)
+   && (soc_dev->attr->serial_number != NULL))
+   return attr->mode;
if ((attr == _attr_soc_id.attr)
&& (soc_dev->attr->soc_id != NULL))
return attr->mode;
@@ -77,6 +81,8 @@ static ssize_t soc_info_get(struct device *dev,
return sprintf(buf, "%s\n", soc_dev->attr->family);
if (attr == _attr_revision)
return sprintf(buf, "%s\n", soc_dev->attr->revision);
+   if (attr == _attr_serial_number)
+   return sprintf(buf, "%s\n", soc_dev->attr->serial_number);
if (attr == _attr_soc_id)
return sprintf(buf, "%s\n", soc_dev->attr->soc_id);
 
@@ -87,6 +93,7 @@ static ssize_t soc_info_get(struct device *dev,
 static struct attribute *soc_attr[] = {
_attr_machine.attr,
_attr_family.attr,
+   _attr_serial_number.attr,
_attr_soc_id.attr,
_attr_revision.attr,
NULL,
diff --git a/include/linux/sys_soc.h b/include/linux/sys_soc.h
index bed223b70217..2a13bc033bd6 100644
--- a/include/linux/sys_soc.h
+++ b/include/linux/sys_soc.h
@@ -12,6 +12,7 @@ struct soc_device_attribute {
const char *machine;
const char *family;
const char *revision;
+   const char *serial_number;
const char *soc_id;
const void *data;
 };
-- 
2.17.1



Re: [Outreachy kernel] [PATCH] net: dsa: add missing of_node_put

2019-02-19 Thread Vaishali Thakkar
On Wed, Feb 20, 2019 at 8:54 AM Himadri Pandya  wrote:
>

Hi Himadri,

Thanks for the patch!

For the scope of Outreachy, we prefer that you send patches in staging
directory as Greg makes sure to pick them during the application
period. Of course, you're very much encouraged to contribute to other
subsystems as well but there patches are mainly picked up based on
maintainer's cycle which may or may not be picked up for linux-next when
selection of interns happens.

I hope that makes sense.

> Decrement the reference count on port while returning out of the loop.

How did you find out about this issue? I think it would be good to
give credit to tool in commit log if the issue is identified or produced
by tool. [In this case, I assume it's Coccinelle]

> Signed-off-by: Himadri Pandya 
> ---
>  net/dsa/dsa2.c | 14 ++
>  1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
> index a1917025e155..396e7433dd8f 100644
> --- a/net/dsa/dsa2.c
> +++ b/net/dsa/dsa2.c
> @@ -624,19 +624,25 @@ static int dsa_switch_parse_ports_of(struct dsa_switch 
> *ds,
> for_each_available_child_of_node(ports, port) {
> err = of_property_read_u32(port, "reg", );
> if (err)
> -   return err;
> +   goto put_port;
>
> -   if (reg >= ds->num_ports)
> -   return -EINVAL;
> +   if (reg >= ds->num_ports) {
> +   err = -EINVAL;
> +   goto put_port;
> +   }
>
> dp = >ports[reg];
>
> err = dsa_port_parse_of(dp, port);
> if (err)
> -   return err;
> +   goto put_port;
> }
>
> return 0;
> +
> +put_port:
> +   of_node_put(port);
> +   return err;
>  }
>
>  static int dsa_switch_parse_member_of(struct dsa_switch *ds,
> --
> 2.17.1
>
> --
> You received this message because you are subscribed to the Google Groups 
> "outreachy-kernel" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to outreachy-kernel+unsubscr...@googlegroups.com.
> To post to this group, send email to outreachy-ker...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/outreachy-kernel/20190220032432.2878-1-himadri18.07%40gmail.com.
> For more options, visit https://groups.google.com/d/optout.


[PATCH 5/5] base: soc: Export soc_device_register/unregister APIs

2019-02-13 Thread Vaishali Thakkar
From: Vinod Koul 

Qcom Socinfo driver can be built as a module, so
export these two APIs.

Signed-off-by: Vinod Koul 
Signed-off-by: Vaishali Thakkar 
---
 drivers/base/soc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/base/soc.c b/drivers/base/soc.c
index b0933b9fe67f..7c0c5ca5953d 100644
--- a/drivers/base/soc.c
+++ b/drivers/base/soc.c
@@ -164,6 +164,7 @@ struct soc_device *soc_device_register(struct 
soc_device_attribute *soc_dev_attr
 out1:
return ERR_PTR(ret);
 }
+EXPORT_SYMBOL_GPL(soc_device_register);
 
 /* Ensure soc_dev->attr is freed prior to calling soc_device_unregister. */
 void soc_device_unregister(struct soc_device *soc_dev)
@@ -173,6 +174,7 @@ void soc_device_unregister(struct soc_device *soc_dev)
device_unregister(_dev->dev);
early_soc_dev_attr = NULL;
 }
+EXPORT_SYMBOL_GPL(soc_device_unregister);
 
 static int __init soc_bus_register(void)
 {
-- 
2.17.1



[PATCH 1/5] base: soc: Add serial_number attribute to soc

2019-02-13 Thread Vaishali Thakkar
From: Bjorn Andersson 

Add new attribute named "serial_number" as a standard interface for
user space to acquire the serial number of the device.

For ST-Ericsson SoCs this is exposed by the cryptically named "soc_id"
attribute, but this provides a human readable standardized name for this
property.

Signed-off-by: Bjorn Andersson 
Signed-off-by: Vaishali Thakkar 
---
 Documentation/ABI/testing/sysfs-devices-soc | 7 +++
 drivers/base/soc.c  | 7 +++
 include/linux/sys_soc.h | 1 +
 3 files changed, 15 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-devices-soc 
b/Documentation/ABI/testing/sysfs-devices-soc
index 6d9cc253f2b2..919109697bf0 100644
--- a/Documentation/ABI/testing/sysfs-devices-soc
+++ b/Documentation/ABI/testing/sysfs-devices-soc
@@ -26,6 +26,13 @@ Description:
Read-only attribute common to all SoCs. Contains SoC family name
(e.g. DB8500).
 
+What:  /sys/devices/socX/serial_number
+Date:  January 2019
+contact:   Bjorn Andersson 
+Description:
+   Read-only attribute supported by most SoCs. Contains the SoC's
+   serial number.
+
 What:  /sys/devices/socX/soc_id
 Date:  January 2012
 contact:   Lee Jones 
diff --git a/drivers/base/soc.c b/drivers/base/soc.c
index 10b280f30217..b0933b9fe67f 100644
--- a/drivers/base/soc.c
+++ b/drivers/base/soc.c
@@ -33,6 +33,7 @@ static struct bus_type soc_bus_type = {
 
 static DEVICE_ATTR(machine,  S_IRUGO, soc_info_get,  NULL);
 static DEVICE_ATTR(family,   S_IRUGO, soc_info_get,  NULL);
+static DEVICE_ATTR(serial_number, S_IRUGO, soc_info_get,  NULL);
 static DEVICE_ATTR(soc_id,   S_IRUGO, soc_info_get,  NULL);
 static DEVICE_ATTR(revision, S_IRUGO, soc_info_get,  NULL);
 
@@ -57,6 +58,9 @@ static umode_t soc_attribute_mode(struct kobject *kobj,
if ((attr == _attr_revision.attr)
&& (soc_dev->attr->revision != NULL))
return attr->mode;
+   if ((attr == _attr_serial_number.attr)
+   && (soc_dev->attr->serial_number != NULL))
+   return attr->mode;
if ((attr == _attr_soc_id.attr)
&& (soc_dev->attr->soc_id != NULL))
return attr->mode;
@@ -77,6 +81,8 @@ static ssize_t soc_info_get(struct device *dev,
return sprintf(buf, "%s\n", soc_dev->attr->family);
if (attr == _attr_revision)
return sprintf(buf, "%s\n", soc_dev->attr->revision);
+   if (attr == _attr_serial_number)
+   return sprintf(buf, "%s\n", soc_dev->attr->serial_number);
if (attr == _attr_soc_id)
return sprintf(buf, "%s\n", soc_dev->attr->soc_id);
 
@@ -87,6 +93,7 @@ static ssize_t soc_info_get(struct device *dev,
 static struct attribute *soc_attr[] = {
_attr_machine.attr,
_attr_family.attr,
+   _attr_serial_number.attr,
_attr_soc_id.attr,
_attr_revision.attr,
NULL,
diff --git a/include/linux/sys_soc.h b/include/linux/sys_soc.h
index bed223b70217..2a13bc033bd6 100644
--- a/include/linux/sys_soc.h
+++ b/include/linux/sys_soc.h
@@ -12,6 +12,7 @@ struct soc_device_attribute {
const char *machine;
const char *family;
const char *revision;
+   const char *serial_number;
const char *soc_id;
const void *data;
 };
-- 
2.17.1



[PATCH 4/5] soc: qcom: socinfo: Expose image information

2019-02-13 Thread Vaishali Thakkar
The socinfo driver provides information about version of the various
images loaded in the system. Expose this to user space for debugging
purpose.

Signed-off-by: Vaishali Thakkar 
---
 drivers/soc/qcom/socinfo.c | 210 +
 1 file changed, 210 insertions(+)

diff --git a/drivers/soc/qcom/socinfo.c b/drivers/soc/qcom/socinfo.c
index 58665067beb8..fb5a3cabe42a 100644
--- a/drivers/soc/qcom/socinfo.c
+++ b/drivers/soc/qcom/socinfo.c
@@ -31,6 +31,25 @@
 #define SMEM_HW_SW_BUILD_ID137
 
 #ifdef CONFIG_DEBUG_FS
+#define SMEM_IMAGE_VERSION_BLOCKS_COUNT32
+#define SMEM_IMAGE_VERSION_SIZE4096
+#define SMEM_IMAGE_VERSION_NAME_SIZE   75
+#define SMEM_IMAGE_VERSION_VARIANT_SIZE20
+#define SMEM_IMAGE_VERSION_OEM_SIZE32
+
+/*
+ * SMEM Image table indices
+ */
+#define SMEM_IMAGE_TABLE_BOOT_INDEX 0
+#define SMEM_IMAGE_TABLE_TZ_INDEX   1
+#define SMEM_IMAGE_TABLE_RPM_INDEX  3
+#define SMEM_IMAGE_TABLE_APPS_INDEX 10
+#define SMEM_IMAGE_TABLE_MPSS_INDEX 11
+#define SMEM_IMAGE_TABLE_ADSP_INDEX 12
+#define SMEM_IMAGE_TABLE_CNSS_INDEX 13
+#define SMEM_IMAGE_TABLE_VIDEO_INDEX14
+#define SMEM_IMAGE_VERSION_TABLE   469
+
 /* pmic model info */
 static const char *const pmic_model[] = {
[0]  = "Unknown PMIC model",
@@ -90,11 +109,21 @@ struct socinfo {
__le32 raw_device_num;
 };
 
+#ifdef CONFIG_DEBUG_FS
+struct smem_image_version {
+   char name[SMEM_IMAGE_VERSION_NAME_SIZE];
+   char variant[SMEM_IMAGE_VERSION_VARIANT_SIZE];
+   char pad;
+   char oem[SMEM_IMAGE_VERSION_OEM_SIZE];
+};
+#endif /* CONFIG_DEBUG_FS */
+
 struct qcom_socinfo {
struct soc_device *soc_dev;
struct soc_device_attribute attr;
#ifdef CONFIG_DEBUG_FS
struct dentry *dbg_root;
+   struct dentry *boot, *tz, *rpm, *apps, *mpss, *adsp, *cnss, *video;
#endif /* CONFIG_DEBUG_FS */
struct socinfo *socinfo;
 };
@@ -298,8 +327,97 @@ QCOM_OPEN(pmic_model, qcom_show_pmic_model);
 QCOM_OPEN(platform_subtype, qcom_show_platform_subtype);
 QCOM_OPEN(pmic_die_revision, qcom_show_pmic_die_revision);
 
+#define IMAGE_SHOW_NAME(attr)\
+static int show_ ##attr## _name(struct seq_file *seq, void *p)   \
+{\
+   struct smem_image_version *image_version = seq->private;  \
+   seq_puts(seq, image_version->name);   \
+   seq_puts(seq, "\n");  \
+   return 0; \
+}\
+static int open_ ##attr## _name(struct inode *inode, struct file *file)
  \
+{\
+   return single_open(file, show_ ##attr## _name, inode->i_private); \
+}\
+ \
+static const struct file_operations qcom_ ##attr## _name_ops = { \
+   .open = open_ ##attr## _name, \
+   .read = seq_read, \
+   .llseek = seq_lseek,  \
+   .release = single_release,\
+}\
+
+#define DEBUGFS_IMAGE_NAME(fname, attr, index)   \
+debugfs_create_file(__stringify(fname), 0400, qcom_socinfo->attr,\
+   _image_version[index], _ ##attr## _name_ops)
+
+#define IMAGE_SHOW_VARIANT(attr)\
+static int show_ ##attr## _variant(struct seq_file *seq, void *p)   \
+{   \
+   struct smem_image_version *image_version = seq->private; \
+   seq_puts(seq, image_version->variant);   \
+   seq_puts(seq, "\n"); \
+   return 0;\
+}   \
+static int open_ ##attr## _variant(struct inode *inode, struct file *file)   \
+{\
+   return single_open(file, show_ ##attr## _variant, inode->i_private); \
+}   \
+\
+static const struct file_operations qcom_ ##attr## _var

[PATCH 3/5] soc: qcom: socinfo: Expose custom attributes

2019-02-13 Thread Vaishali Thakkar
The Qualcomm socinfo provides a number of additional attributes,
add these to the socinfo driver and expose them via debugfs
functionality.

Signed-off-by: Vaishali Thakkar 
---
Note that this may have some 80 char checkpatch warnings as
fixing them makes code less readable.
---
 drivers/soc/qcom/socinfo.c | 203 +
 1 file changed, 203 insertions(+)

diff --git a/drivers/soc/qcom/socinfo.c b/drivers/soc/qcom/socinfo.c
index 02078049fac7..58665067beb8 100644
--- a/drivers/soc/qcom/socinfo.c
+++ b/drivers/soc/qcom/socinfo.c
@@ -4,6 +4,7 @@
  * Copyright (c) 2017-2019, Linaro Ltd.
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -29,6 +30,28 @@
  */
 #define SMEM_HW_SW_BUILD_ID137
 
+#ifdef CONFIG_DEBUG_FS
+/* pmic model info */
+static const char *const pmic_model[] = {
+   [0]  = "Unknown PMIC model",
+   [9]  = "PM8994",
+   [11] = "PM8916",
+   [13] = "PM8058",
+   [14] = "PM8028",
+   [15] = "PM8901",
+   [16] = "PM8027",
+   [17] = "ISL9519",
+   [18] = "PM8921",
+   [19] = "PM8018",
+   [20] = "PM8015",
+   [21] = "PM8014",
+   [22] = "PM8821",
+   [23] = "PM8038",
+   [24] = "PM8922",
+   [25] = "PM8917",
+};
+#endif /* CONFIG_DEBUG_FS */
+
 /* Socinfo SMEM item structure */
 struct socinfo {
__le32 fmt;
@@ -70,6 +93,10 @@ struct socinfo {
 struct qcom_socinfo {
struct soc_device *soc_dev;
struct soc_device_attribute attr;
+   #ifdef CONFIG_DEBUG_FS
+   struct dentry *dbg_root;
+   #endif /* CONFIG_DEBUG_FS */
+   struct socinfo *socinfo;
 };
 
 struct soc_of_id {
@@ -133,6 +160,176 @@ static const char *socinfo_machine(struct device *dev, 
unsigned int id)
return NULL;
 }
 
+#ifdef CONFIG_DEBUG_FS
+
+#define UINT_SHOW(name, attr)  \
+static int qcom_show_##name(struct seq_file *seq, void *p) \
+{  \
+   struct socinfo *socinfo = seq->private; \
+   seq_printf(seq, "%u\n", le32_to_cpu(socinfo->attr));\
+   return 0;   \
+}  \
+static int qcom_open_##name(struct inode *inode, struct file *file)\
+{  \
+   return single_open(file, qcom_show_##name, inode->i_private);   \
+}  \
+   \
+static const struct file_operations qcom_ ##name## _ops = {\
+   .open = qcom_open_##name,   \
+   .read = seq_read,   \
+   .llseek = seq_lseek,\
+   .release = single_release,  \
+}
+
+#define DEBUGFS_UINT_ADD(name) \
+   debugfs_create_file(__stringify(name), 0400,\
+   qcom_socinfo->dbg_root, \
+   qcom_socinfo->socinfo, _ ##name## _ops)
+
+#define HEX_SHOW(name, attr)   \
+static int qcom_show_##name(struct seq_file *seq, void *p) \
+{  \
+   struct socinfo *socinfo = seq->private; \
+   seq_printf(seq, "0x%x\n", le32_to_cpu(socinfo->attr));  \
+   return 0;   \
+}  \
+static int qcom_open_##name(struct inode *inode, struct file *file)\
+{  \
+   return single_open(file, qcom_show_##name, inode->i_private);   \
+}  \
+   \
+static const struct file_operations qcom_ ##name## _ops = {\
+   .open = qcom_open_##name,   \
+   .read = seq_read,   \
+   .llseek = seq_lseek,\
+   .release = single_release,  \
+}
+
+#define DEBUGFS_HEX_ADD(name)  \
+   debugfs_create_file(__stringify(name), 0400,\
+  

[PATCH 2/5] soc: qcom: Add socinfo driver

2019-02-13 Thread Vaishali Thakkar
From: Imran Khan 

The Qualcomm socinfo driver exposes information about the SoC, its
version and its serial number to user space.

Signed-off-by: Imran Khan 
[Bjorn: Extract code to platform_driver, split patch in multiple]
Signed-off-by: Bjorn Andersson 
[Vaishali: Simplify declarations, introduce qcom_socinfo struc, Fix
   memory leak, Remove extra code and Misc code refactoring]
Signed-off-by: Vaishali Thakkar 
---
 drivers/soc/qcom/Kconfig   |   8 ++
 drivers/soc/qcom/Makefile  |   1 +
 drivers/soc/qcom/smem.c|   8 ++
 drivers/soc/qcom/socinfo.c | 197 +
 4 files changed, 214 insertions(+)
 create mode 100644 drivers/soc/qcom/socinfo.c

diff --git a/drivers/soc/qcom/Kconfig b/drivers/soc/qcom/Kconfig
index fcbf8a2e4080..1e31eda07934 100644
--- a/drivers/soc/qcom/Kconfig
+++ b/drivers/soc/qcom/Kconfig
@@ -144,6 +144,14 @@ config QCOM_SMSM
  Say yes here to support the Qualcomm Shared Memory State Machine.
  The state machine is represented by bits in shared memory.
 
+config QCOM_SOCINFO
+   tristate "Qualcomm socinfo driver"
+   depends on QCOM_SMEM
+   select SOC_BUS
+   help
+Say yes here to support the Qualcomm socinfo driver, providing
+information about the SoC to user space.
+
 config QCOM_WCNSS_CTRL
tristate "Qualcomm WCNSS control driver"
depends on ARCH_QCOM || COMPILE_TEST
diff --git a/drivers/soc/qcom/Makefile b/drivers/soc/qcom/Makefile
index f25b54cd6cf8..c817da4f4140 100644
--- a/drivers/soc/qcom/Makefile
+++ b/drivers/soc/qcom/Makefile
@@ -14,6 +14,7 @@ qcom_rpmh-y   += rpmh-rsc.o
 qcom_rpmh-y+= rpmh.o
 obj-$(CONFIG_QCOM_SMD_RPM) += smd-rpm.o
 obj-$(CONFIG_QCOM_SMEM) += smem.o
+obj-$(CONFIG_QCOM_SOCINFO) += socinfo.o
 obj-$(CONFIG_QCOM_SMEM_STATE) += smem_state.o
 obj-$(CONFIG_QCOM_SMP2P)   += smp2p.o
 obj-$(CONFIG_QCOM_SMSM)+= smsm.o
diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c
index f80d040601fd..efe0b053ef82 100644
--- a/drivers/soc/qcom/smem.c
+++ b/drivers/soc/qcom/smem.c
@@ -276,6 +276,7 @@ struct qcom_smem {
struct smem_partition_header *partitions[SMEM_HOST_COUNT];
size_t cacheline[SMEM_HOST_COUNT];
u32 item_count;
+   struct platform_device *socinfo;
 
unsigned num_regions;
struct smem_region regions[];
@@ -971,11 +972,18 @@ static int qcom_smem_probe(struct platform_device *pdev)
 
__smem = smem;
 
+   smem->socinfo = platform_device_register_data(>dev, 
"qcom-socinfo",
+ PLATFORM_DEVID_NONE, NULL,
+ 0);
+   if (IS_ERR(smem->socinfo))
+   dev_err(>dev, "failed to register socinfo device\n");
+
return 0;
 }
 
 static int qcom_smem_remove(struct platform_device *pdev)
 {
+
hwspin_lock_free(__smem->hwlock);
__smem = NULL;
 
diff --git a/drivers/soc/qcom/socinfo.c b/drivers/soc/qcom/socinfo.c
new file mode 100644
index ..02078049fac7
--- /dev/null
+++ b/drivers/soc/qcom/socinfo.c
@@ -0,0 +1,197 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2009-2017, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2017-2019, Linaro Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * SoC version type with major number in the upper 16 bits and minor
+ * number in the lower 16 bits.
+ */
+#define SOCINFO_MAJOR(ver) (((ver) >> 16) & 0x)
+#define SOCINFO_MINOR(ver) ((ver) & 0x)
+
+#define SMEM_SOCINFO_BUILD_ID_LENGTH   32
+
+/*
+ * SMEM item ids, used to acquire handles to respective
+ * SMEM region.
+ */
+#define SMEM_HW_SW_BUILD_ID137
+
+/* Socinfo SMEM item structure */
+struct socinfo {
+   __le32 fmt;
+   __le32 id;
+   __le32 ver;
+   char build_id[SMEM_SOCINFO_BUILD_ID_LENGTH];
+   /* Version 2 */
+   __le32 raw_id;
+   __le32 raw_ver;
+   /* Version 3 */
+   __le32 hw_plat;
+   /* Version 4 */
+   __le32 plat_ver;
+   /* Version 5 */
+   __le32 accessory_chip;
+   /* Version 6 */
+   __le32 hw_plat_subtype;
+   /* Version 7 */
+   __le32 pmic_model;
+   __le32 pmic_die_rev;
+   /* Version 8 */
+   __le32 pmic_model_1;
+   __le32 pmic_die_rev_1;
+   __le32 pmic_model_2;
+   __le32 pmic_die_rev_2;
+   /* Version 9 */
+   __le32 foundry_id;
+   /* Version 10 */
+   __le32 serial_num;
+   /* Version 11 */
+   __le32 num_pmics;
+   __le32 pmic_array_offset;
+   /* Version 12 */
+   __le32 chip_family;
+   __le32 raw_device_family;
+   __le32 raw_device_num;
+};
+
+struct qcom_socinfo {
+   struct soc_device *soc_dev;
+   struct soc_device_attribute attr;
+};
+

[PATCH 0/5] soc: qcom: Add SoC info driver

2019-02-13 Thread Vaishali Thakkar
This patchset adds SoC info driver which can provide information
such as Chip ID, Chip family and serial number about Qualcomm SoCs
to user space via sysfs. Furthermore, it allows userspace to get
information about custom attributes and various image version
information via debugfs.

The patchset cleanly applies on top of v5.0-rc6.

Vaishali Thakkar (5):
  base: soc: Add serial_number attribute to soc
  soc: qcom: Add socinfo driver
  soc: qcom: socinfo: Expose custom attributes
  soc: qcom: socinfo: Expose image information
  base: soc: Export soc_device_register/unregister APIs

 Documentation/ABI/testing/sysfs-devices-soc |   7 +
 drivers/base/soc.c  |   9 +
 drivers/soc/qcom/Kconfig|   8 +
 drivers/soc/qcom/Makefile   |   1 +
 drivers/soc/qcom/smem.c |   8 +
 drivers/soc/qcom/socinfo.c  | 610 
 include/linux/sys_soc.h |   1 +
 7 files changed, 644 insertions(+)
 create mode 100644 drivers/soc/qcom/socinfo.c

-- 
2.17.1



Re: [Intel-gfx] [PATCH] drm/core: Remove drm_dev_unref() and it's uses

2018-04-26 Thread Vaishali Thakkar
On Thu, Apr 26, 2018 at 6:15 PM, Laurent Pinchart
<laurent.pinch...@ideasonboard.com> wrote:
> Hi Daniel,
>
> On Thursday, 26 April 2018 15:36:15 EEST Daniel Vetter wrote:
>> On Thu, Apr 26, 2018 at 03:58:19PM +0530, Vaishali Thakkar wrote:
>> > It's been a while since we introduced drm_dev{get/put} functions
>> > to replace reference/unreference in drm subsystem for the
>> > consistency purpose. So, with this patch, let's just replace
>> > all current use cases of drm_dev_unref() with drm_dev_put and remove
>> > the function itself.
>> >
>> > Coccinelle was used for mass-patching.
>> >
>> > Signed-off-by: Vaishali Thakkar <vthakkar1...@gmail.com>
>>
>> Thanks for doing this. Unfortunately drm moves pretty fast, so already a
>> conflict when I tried to apply this. Some drivers are also in their own
>> trees, so this might lead to more fun :-/
>>
>> Can you pls split it up per-driver (just the directories under
>> drivers/gpu/drm/ is enough)? Final patch to remove the function might then
>> get stalled a bit ofc.
>
> I requested a single patch instead of splitting it per driver, you might want
> to blame me for that.
>
>> Also can you pls update ./scripts/coccinelle/api/drm-get-put.cocci and
>> remove that spatch hunk in the final patch, since we no longer need it?
>
> How about just rerunning the coccinelle patch when it's time to apply this ?
> There's precedent for performing such automated changes, and it would ensure
> that no driver is left out.

I was planning to send patches to remove all remaining reference/unreference
functions by the weekend [as there aren't much remaining now and I see that
new drivers keeps adding them instead of new API]. So, wanted to delete whole
cocci file after that. I thought of dividing a patch per function because
Laurent requested to send a single patch for all files.

But if we are going to split it per driver under gpu/drm, would it work if per
driver patch contains all function cases? Also, would you be fine with taking a
patch for removal of coccinelle file via your tree? Then I can include that in
the same patchset as well.

Thanks!

>> > ---
>> >
>> >  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c|  4 ++--
>> >  drivers/gpu/drm/arc/arcpgu_drv.c   |  4 ++--
>> >  drivers/gpu/drm/armada/armada_drv.c|  6 +++---
>> >  drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_dc.c   |  4 ++--
>> >  drivers/gpu/drm/drm_drv.c  | 13 -
>> >  drivers/gpu/drm/etnaviv/etnaviv_drv.c  |  4 ++--
>> >  drivers/gpu/drm/exynos/exynos_drm_drv.c|  4 ++--
>> >  drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c  |  4 ++--
>> >  drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c|  4 ++--
>> >  drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c|  8 
>> >  drivers/gpu/drm/i915/selftests/huge_pages.c|  2 +-
>> >  drivers/gpu/drm/i915/selftests/i915_gem_dmabuf.c   |  2 +-
>> >  drivers/gpu/drm/i915/selftests/i915_gem_evict.c|  2 +-
>> >  drivers/gpu/drm/i915/selftests/i915_gem_gtt.c  |  2 +-
>> >  drivers/gpu/drm/i915/selftests/i915_gem_object.c   |  2 +-
>> >  drivers/gpu/drm/i915/selftests/i915_request.c  |  2 +-
>> >  drivers/gpu/drm/i915/selftests/i915_vma.c  |  2 +-
>> >  drivers/gpu/drm/i915/selftests/intel_breadcrumbs.c |  2 +-
>> >  drivers/gpu/drm/imx/imx-drm-core.c |  4 ++--
>> >  drivers/gpu/drm/mediatek/mtk_drm_drv.c |  6 +++---
>> >  drivers/gpu/drm/msm/msm_drv.c  |  8 
>> >  drivers/gpu/drm/mxsfb/mxsfb_drv.c  |  4 ++--
>> >  drivers/gpu/drm/nouveau/nouveau_platform.c |  2 +-
>> >  drivers/gpu/drm/omapdrm/omap_drv.c |  4 ++--
>> >  drivers/gpu/drm/pl111/pl111_drv.c  |  4 ++--
>> >  drivers/gpu/drm/qxl/qxl_drv.c  |  2 +-
>> >  drivers/gpu/drm/rcar-du/rcar_du_drv.c  |  2 +-
>> >  drivers/gpu/drm/rockchip/rockchip_drm_drv.c|  4 ++--
>> >  drivers/gpu/drm/shmobile/shmob_drm_drv.c   |  4 ++--
>> >  drivers/gpu/drm/sti/sti_drv.c  |  8 
>> >  drivers/gpu/drm/stm/drv.c  |  4 ++--
>> >  drivers/gpu/drm/sun4i/sun4i_drv.c  |  4 ++--
>> >  drivers/gpu/drm/tegra/drm.c|  4 ++--
>> >  drivers/gpu/drm/tinydrm/core/tinydrm-core.c|  6 +++---
>> >  drivers/gpu/drm/tve200/tve200_drv.c|

Re: [Intel-gfx] [PATCH] drm/core: Remove drm_dev_unref() and it's uses

2018-04-26 Thread Vaishali Thakkar
On Thu, Apr 26, 2018 at 6:15 PM, Laurent Pinchart
 wrote:
> Hi Daniel,
>
> On Thursday, 26 April 2018 15:36:15 EEST Daniel Vetter wrote:
>> On Thu, Apr 26, 2018 at 03:58:19PM +0530, Vaishali Thakkar wrote:
>> > It's been a while since we introduced drm_dev{get/put} functions
>> > to replace reference/unreference in drm subsystem for the
>> > consistency purpose. So, with this patch, let's just replace
>> > all current use cases of drm_dev_unref() with drm_dev_put and remove
>> > the function itself.
>> >
>> > Coccinelle was used for mass-patching.
>> >
>> > Signed-off-by: Vaishali Thakkar 
>>
>> Thanks for doing this. Unfortunately drm moves pretty fast, so already a
>> conflict when I tried to apply this. Some drivers are also in their own
>> trees, so this might lead to more fun :-/
>>
>> Can you pls split it up per-driver (just the directories under
>> drivers/gpu/drm/ is enough)? Final patch to remove the function might then
>> get stalled a bit ofc.
>
> I requested a single patch instead of splitting it per driver, you might want
> to blame me for that.
>
>> Also can you pls update ./scripts/coccinelle/api/drm-get-put.cocci and
>> remove that spatch hunk in the final patch, since we no longer need it?
>
> How about just rerunning the coccinelle patch when it's time to apply this ?
> There's precedent for performing such automated changes, and it would ensure
> that no driver is left out.

I was planning to send patches to remove all remaining reference/unreference
functions by the weekend [as there aren't much remaining now and I see that
new drivers keeps adding them instead of new API]. So, wanted to delete whole
cocci file after that. I thought of dividing a patch per function because
Laurent requested to send a single patch for all files.

But if we are going to split it per driver under gpu/drm, would it work if per
driver patch contains all function cases? Also, would you be fine with taking a
patch for removal of coccinelle file via your tree? Then I can include that in
the same patchset as well.

Thanks!

>> > ---
>> >
>> >  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c|  4 ++--
>> >  drivers/gpu/drm/arc/arcpgu_drv.c   |  4 ++--
>> >  drivers/gpu/drm/armada/armada_drv.c|  6 +++---
>> >  drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_dc.c   |  4 ++--
>> >  drivers/gpu/drm/drm_drv.c  | 13 -
>> >  drivers/gpu/drm/etnaviv/etnaviv_drv.c  |  4 ++--
>> >  drivers/gpu/drm/exynos/exynos_drm_drv.c|  4 ++--
>> >  drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c  |  4 ++--
>> >  drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c|  4 ++--
>> >  drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c|  8 
>> >  drivers/gpu/drm/i915/selftests/huge_pages.c|  2 +-
>> >  drivers/gpu/drm/i915/selftests/i915_gem_dmabuf.c   |  2 +-
>> >  drivers/gpu/drm/i915/selftests/i915_gem_evict.c|  2 +-
>> >  drivers/gpu/drm/i915/selftests/i915_gem_gtt.c  |  2 +-
>> >  drivers/gpu/drm/i915/selftests/i915_gem_object.c   |  2 +-
>> >  drivers/gpu/drm/i915/selftests/i915_request.c  |  2 +-
>> >  drivers/gpu/drm/i915/selftests/i915_vma.c  |  2 +-
>> >  drivers/gpu/drm/i915/selftests/intel_breadcrumbs.c |  2 +-
>> >  drivers/gpu/drm/imx/imx-drm-core.c |  4 ++--
>> >  drivers/gpu/drm/mediatek/mtk_drm_drv.c |  6 +++---
>> >  drivers/gpu/drm/msm/msm_drv.c  |  8 
>> >  drivers/gpu/drm/mxsfb/mxsfb_drv.c  |  4 ++--
>> >  drivers/gpu/drm/nouveau/nouveau_platform.c |  2 +-
>> >  drivers/gpu/drm/omapdrm/omap_drv.c |  4 ++--
>> >  drivers/gpu/drm/pl111/pl111_drv.c  |  4 ++--
>> >  drivers/gpu/drm/qxl/qxl_drv.c  |  2 +-
>> >  drivers/gpu/drm/rcar-du/rcar_du_drv.c  |  2 +-
>> >  drivers/gpu/drm/rockchip/rockchip_drm_drv.c|  4 ++--
>> >  drivers/gpu/drm/shmobile/shmob_drm_drv.c   |  4 ++--
>> >  drivers/gpu/drm/sti/sti_drv.c  |  8 
>> >  drivers/gpu/drm/stm/drv.c  |  4 ++--
>> >  drivers/gpu/drm/sun4i/sun4i_drv.c  |  4 ++--
>> >  drivers/gpu/drm/tegra/drm.c|  4 ++--
>> >  drivers/gpu/drm/tinydrm/core/tinydrm-core.c|  6 +++---
>> >  drivers/gpu/drm/tve200/tve200_drv.c|  4 ++--
>> >  drivers/gpu/drm/udl/udl_drv.c  |  2 +-
>> >  drivers/gpu/drm/vc4/vc4_drv.c  |  4 ++--
>> >  drivers/gpu/drm/vgem/vgem_drv.c|  2 +-
>> >  drivers/gpu/drm/virtio/virtgpu_drm_bus.c   |  2 +-
>> >  drivers/gpu/drm/zte/zx_drm_drv.c   |  4 ++--
>> >  include/drm/drm_drv.h  |  1 -
>> >  41 files changed, 73 insertions(+), 87 deletions(-)
>
> --
> Regards,
>
> Laurent Pinchart
>
>
>



-- 
Vaishali
http://vaishalithakkar.in/


[PATCH] drm/core: Remove drm_dev_unref() and it's uses

2018-04-26 Thread Vaishali Thakkar
It's been a while since we introduced drm_dev{get/put} functions
to replace reference/unreference in drm subsystem for the
consistency purpose. So, with this patch, let's just replace
all current use cases of drm_dev_unref() with drm_dev_put and remove
the function itself.

Coccinelle was used for mass-patching.

Signed-off-by: Vaishali Thakkar <vthakkar1...@gmail.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c|  4 ++--
 drivers/gpu/drm/arc/arcpgu_drv.c   |  4 ++--
 drivers/gpu/drm/armada/armada_drv.c|  6 +++---
 drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_dc.c   |  4 ++--
 drivers/gpu/drm/drm_drv.c  | 13 -
 drivers/gpu/drm/etnaviv/etnaviv_drv.c  |  4 ++--
 drivers/gpu/drm/exynos/exynos_drm_drv.c|  4 ++--
 drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c  |  4 ++--
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c|  4 ++--
 drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c|  8 
 drivers/gpu/drm/i915/selftests/huge_pages.c|  2 +-
 drivers/gpu/drm/i915/selftests/i915_gem_dmabuf.c   |  2 +-
 drivers/gpu/drm/i915/selftests/i915_gem_evict.c|  2 +-
 drivers/gpu/drm/i915/selftests/i915_gem_gtt.c  |  2 +-
 drivers/gpu/drm/i915/selftests/i915_gem_object.c   |  2 +-
 drivers/gpu/drm/i915/selftests/i915_request.c  |  2 +-
 drivers/gpu/drm/i915/selftests/i915_vma.c  |  2 +-
 drivers/gpu/drm/i915/selftests/intel_breadcrumbs.c |  2 +-
 drivers/gpu/drm/imx/imx-drm-core.c |  4 ++--
 drivers/gpu/drm/mediatek/mtk_drm_drv.c |  6 +++---
 drivers/gpu/drm/msm/msm_drv.c  |  8 
 drivers/gpu/drm/mxsfb/mxsfb_drv.c  |  4 ++--
 drivers/gpu/drm/nouveau/nouveau_platform.c |  2 +-
 drivers/gpu/drm/omapdrm/omap_drv.c |  4 ++--
 drivers/gpu/drm/pl111/pl111_drv.c  |  4 ++--
 drivers/gpu/drm/qxl/qxl_drv.c  |  2 +-
 drivers/gpu/drm/rcar-du/rcar_du_drv.c  |  2 +-
 drivers/gpu/drm/rockchip/rockchip_drm_drv.c|  4 ++--
 drivers/gpu/drm/shmobile/shmob_drm_drv.c   |  4 ++--
 drivers/gpu/drm/sti/sti_drv.c  |  8 
 drivers/gpu/drm/stm/drv.c  |  4 ++--
 drivers/gpu/drm/sun4i/sun4i_drv.c  |  4 ++--
 drivers/gpu/drm/tegra/drm.c|  4 ++--
 drivers/gpu/drm/tinydrm/core/tinydrm-core.c|  6 +++---
 drivers/gpu/drm/tve200/tve200_drv.c|  4 ++--
 drivers/gpu/drm/udl/udl_drv.c  |  2 +-
 drivers/gpu/drm/vc4/vc4_drv.c  |  4 ++--
 drivers/gpu/drm/vgem/vgem_drv.c|  2 +-
 drivers/gpu/drm/virtio/virtgpu_drm_bus.c   |  2 +-
 drivers/gpu/drm/zte/zx_drm_drv.c   |  4 ++--
 include/drm/drm_drv.h  |  1 -
 41 files changed, 73 insertions(+), 87 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 0b19482b36b8..5fb455febeba 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -647,7 +647,7 @@ static int amdgpu_pci_probe(struct pci_dev *pdev,
 err_pci:
pci_disable_device(pdev);
 err_free:
-   drm_dev_unref(dev);
+   drm_dev_put(dev);
return ret;
 }
 
@@ -657,7 +657,7 @@ amdgpu_pci_remove(struct pci_dev *pdev)
struct drm_device *dev = pci_get_drvdata(pdev);
 
drm_dev_unregister(dev);
-   drm_dev_unref(dev);
+   drm_dev_put(dev);
pci_disable_device(pdev);
pci_set_drvdata(pdev, NULL);
 }
diff --git a/drivers/gpu/drm/arc/arcpgu_drv.c b/drivers/gpu/drm/arc/arcpgu_drv.c
index f067de4e1e82..dcb06d4e9135 100644
--- a/drivers/gpu/drm/arc/arcpgu_drv.c
+++ b/drivers/gpu/drm/arc/arcpgu_drv.c
@@ -216,7 +216,7 @@ static int arcpgu_probe(struct platform_device *pdev)
arcpgu_unload(drm);
 
 err_unref:
-   drm_dev_unref(drm);
+   drm_dev_put(drm);
 
return ret;
 }
@@ -227,7 +227,7 @@ static int arcpgu_remove(struct platform_device *pdev)
 
drm_dev_unregister(drm);
arcpgu_unload(drm);
-   drm_dev_unref(drm);
+   drm_dev_put(drm);
 
return 0;
 }
diff --git a/drivers/gpu/drm/armada/armada_drv.c 
b/drivers/gpu/drm/armada/armada_drv.c
index 4b11b6b52f1d..d1705d298a39 100644
--- a/drivers/gpu/drm/armada/armada_drv.c
+++ b/drivers/gpu/drm/armada/armada_drv.c
@@ -109,7 +109,7 @@ static int armada_drm_bind(struct device *dev)
 
/*
 * The drm_device structure must be at the start of
-* armada_private for drm_dev_unref() to work correctly.
+* armada_private for drm_dev_put() to work correctly.
 */
BUILD_BUG_ON(offsetof(struct armada_private, drm) != 0);
 
@@ -180,7 +180,7 @@ static int armada_drm_bind(struct device *dev)
drm_mode_config_cleanup(>drm);
drm_mm_takedow

[PATCH] drm/core: Remove drm_dev_unref() and it's uses

2018-04-26 Thread Vaishali Thakkar
It's been a while since we introduced drm_dev{get/put} functions
to replace reference/unreference in drm subsystem for the
consistency purpose. So, with this patch, let's just replace
all current use cases of drm_dev_unref() with drm_dev_put and remove
the function itself.

Coccinelle was used for mass-patching.

Signed-off-by: Vaishali Thakkar 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c|  4 ++--
 drivers/gpu/drm/arc/arcpgu_drv.c   |  4 ++--
 drivers/gpu/drm/armada/armada_drv.c|  6 +++---
 drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_dc.c   |  4 ++--
 drivers/gpu/drm/drm_drv.c  | 13 -
 drivers/gpu/drm/etnaviv/etnaviv_drv.c  |  4 ++--
 drivers/gpu/drm/exynos/exynos_drm_drv.c|  4 ++--
 drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c  |  4 ++--
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c|  4 ++--
 drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c|  8 
 drivers/gpu/drm/i915/selftests/huge_pages.c|  2 +-
 drivers/gpu/drm/i915/selftests/i915_gem_dmabuf.c   |  2 +-
 drivers/gpu/drm/i915/selftests/i915_gem_evict.c|  2 +-
 drivers/gpu/drm/i915/selftests/i915_gem_gtt.c  |  2 +-
 drivers/gpu/drm/i915/selftests/i915_gem_object.c   |  2 +-
 drivers/gpu/drm/i915/selftests/i915_request.c  |  2 +-
 drivers/gpu/drm/i915/selftests/i915_vma.c  |  2 +-
 drivers/gpu/drm/i915/selftests/intel_breadcrumbs.c |  2 +-
 drivers/gpu/drm/imx/imx-drm-core.c |  4 ++--
 drivers/gpu/drm/mediatek/mtk_drm_drv.c |  6 +++---
 drivers/gpu/drm/msm/msm_drv.c  |  8 
 drivers/gpu/drm/mxsfb/mxsfb_drv.c  |  4 ++--
 drivers/gpu/drm/nouveau/nouveau_platform.c |  2 +-
 drivers/gpu/drm/omapdrm/omap_drv.c |  4 ++--
 drivers/gpu/drm/pl111/pl111_drv.c  |  4 ++--
 drivers/gpu/drm/qxl/qxl_drv.c  |  2 +-
 drivers/gpu/drm/rcar-du/rcar_du_drv.c  |  2 +-
 drivers/gpu/drm/rockchip/rockchip_drm_drv.c|  4 ++--
 drivers/gpu/drm/shmobile/shmob_drm_drv.c   |  4 ++--
 drivers/gpu/drm/sti/sti_drv.c  |  8 
 drivers/gpu/drm/stm/drv.c  |  4 ++--
 drivers/gpu/drm/sun4i/sun4i_drv.c  |  4 ++--
 drivers/gpu/drm/tegra/drm.c|  4 ++--
 drivers/gpu/drm/tinydrm/core/tinydrm-core.c|  6 +++---
 drivers/gpu/drm/tve200/tve200_drv.c|  4 ++--
 drivers/gpu/drm/udl/udl_drv.c  |  2 +-
 drivers/gpu/drm/vc4/vc4_drv.c  |  4 ++--
 drivers/gpu/drm/vgem/vgem_drv.c|  2 +-
 drivers/gpu/drm/virtio/virtgpu_drm_bus.c   |  2 +-
 drivers/gpu/drm/zte/zx_drm_drv.c   |  4 ++--
 include/drm/drm_drv.h  |  1 -
 41 files changed, 73 insertions(+), 87 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 0b19482b36b8..5fb455febeba 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -647,7 +647,7 @@ static int amdgpu_pci_probe(struct pci_dev *pdev,
 err_pci:
pci_disable_device(pdev);
 err_free:
-   drm_dev_unref(dev);
+   drm_dev_put(dev);
return ret;
 }
 
@@ -657,7 +657,7 @@ amdgpu_pci_remove(struct pci_dev *pdev)
struct drm_device *dev = pci_get_drvdata(pdev);
 
drm_dev_unregister(dev);
-   drm_dev_unref(dev);
+   drm_dev_put(dev);
pci_disable_device(pdev);
pci_set_drvdata(pdev, NULL);
 }
diff --git a/drivers/gpu/drm/arc/arcpgu_drv.c b/drivers/gpu/drm/arc/arcpgu_drv.c
index f067de4e1e82..dcb06d4e9135 100644
--- a/drivers/gpu/drm/arc/arcpgu_drv.c
+++ b/drivers/gpu/drm/arc/arcpgu_drv.c
@@ -216,7 +216,7 @@ static int arcpgu_probe(struct platform_device *pdev)
arcpgu_unload(drm);
 
 err_unref:
-   drm_dev_unref(drm);
+   drm_dev_put(drm);
 
return ret;
 }
@@ -227,7 +227,7 @@ static int arcpgu_remove(struct platform_device *pdev)
 
drm_dev_unregister(drm);
arcpgu_unload(drm);
-   drm_dev_unref(drm);
+   drm_dev_put(drm);
 
return 0;
 }
diff --git a/drivers/gpu/drm/armada/armada_drv.c 
b/drivers/gpu/drm/armada/armada_drv.c
index 4b11b6b52f1d..d1705d298a39 100644
--- a/drivers/gpu/drm/armada/armada_drv.c
+++ b/drivers/gpu/drm/armada/armada_drv.c
@@ -109,7 +109,7 @@ static int armada_drm_bind(struct device *dev)
 
/*
 * The drm_device structure must be at the start of
-* armada_private for drm_dev_unref() to work correctly.
+* armada_private for drm_dev_put() to work correctly.
 */
BUILD_BUG_ON(offsetof(struct armada_private, drm) != 0);
 
@@ -180,7 +180,7 @@ static int armada_drm_bind(struct device *dev)
drm_mode_config_cleanup(>drm);
drm_mm_takedown(>linear);
flush_work(>fb_u

Re: [PATCH] drm: rcar-du: Use drm_dev_put

2018-04-25 Thread Vaishali Thakkar
On Wed, Apr 25, 2018 at 7:02 PM, Laurent Pinchart
<laurent.pinch...@ideasonboard.com> wrote:
> Hi Vaishali,
>
> Thank you for the patch.
>
> On Wednesday, 25 April 2018 15:10:36 EEST Vaishali Thakkar wrote:
>> As specified in drm_drv.c, drm_dev_unref is a compatibility alias
>> for drm_dev_put and shouldn't be used in new code. So, use
>> drm_dev_put instead.
>
> This looks good to me. However, how about taking it one step further and mass-
> patching all drivers to use drm_dev_put() ? We could then remove
> drm_dev_unref() completely.

Sure thing! Do you want me to fold this patch in that patchset or will you be
fine with applying this separately?

>> Signed-off-by: Vaishali Thakkar <vthakkar1...@gmail.com>
>> ---
>>  drivers/gpu/drm/rcar-du/rcar_du_drv.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/rcar-du/rcar_du_drv.c
>> b/drivers/gpu/drm/rcar-du/rcar_du_drv.c index 05745e86d73e..418a80e6b2f4
>> 100644
>> --- a/drivers/gpu/drm/rcar-du/rcar_du_drv.c
>> +++ b/drivers/gpu/drm/rcar-du/rcar_du_drv.c
>> @@ -378,7 +378,7 @@ static int rcar_du_remove(struct platform_device *pdev)
>>   drm_kms_helper_poll_fini(ddev);
>>   drm_mode_config_cleanup(ddev);
>>
>> - drm_dev_unref(ddev);
>> + drm_dev_put(ddev);
>>
>>   return 0;
>>  }
>
> --
> Regards,
>
> Laurent Pinchart
>
>
>



-- 
Vaishali
http://vaishalithakkar.in/


Re: [PATCH] drm: rcar-du: Use drm_dev_put

2018-04-25 Thread Vaishali Thakkar
On Wed, Apr 25, 2018 at 7:02 PM, Laurent Pinchart
 wrote:
> Hi Vaishali,
>
> Thank you for the patch.
>
> On Wednesday, 25 April 2018 15:10:36 EEST Vaishali Thakkar wrote:
>> As specified in drm_drv.c, drm_dev_unref is a compatibility alias
>> for drm_dev_put and shouldn't be used in new code. So, use
>> drm_dev_put instead.
>
> This looks good to me. However, how about taking it one step further and mass-
> patching all drivers to use drm_dev_put() ? We could then remove
> drm_dev_unref() completely.

Sure thing! Do you want me to fold this patch in that patchset or will you be
fine with applying this separately?

>> Signed-off-by: Vaishali Thakkar 
>> ---
>>  drivers/gpu/drm/rcar-du/rcar_du_drv.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/rcar-du/rcar_du_drv.c
>> b/drivers/gpu/drm/rcar-du/rcar_du_drv.c index 05745e86d73e..418a80e6b2f4
>> 100644
>> --- a/drivers/gpu/drm/rcar-du/rcar_du_drv.c
>> +++ b/drivers/gpu/drm/rcar-du/rcar_du_drv.c
>> @@ -378,7 +378,7 @@ static int rcar_du_remove(struct platform_device *pdev)
>>   drm_kms_helper_poll_fini(ddev);
>>   drm_mode_config_cleanup(ddev);
>>
>> - drm_dev_unref(ddev);
>> + drm_dev_put(ddev);
>>
>>   return 0;
>>  }
>
> --
> Regards,
>
> Laurent Pinchart
>
>
>



-- 
Vaishali
http://vaishalithakkar.in/


[PATCH] drm: rcar-du: Use drm_dev_put

2018-04-25 Thread Vaishali Thakkar
As specified in drm_drv.c, drm_dev_unref is a compatibility alias
for drm_dev_put and shouldn't be used in new code. So, use
drm_dev_put instead.

Signed-off-by: Vaishali Thakkar <vthakkar1...@gmail.com>
---
 drivers/gpu/drm/rcar-du/rcar_du_drv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/rcar-du/rcar_du_drv.c 
b/drivers/gpu/drm/rcar-du/rcar_du_drv.c
index 05745e86d73e..418a80e6b2f4 100644
--- a/drivers/gpu/drm/rcar-du/rcar_du_drv.c
+++ b/drivers/gpu/drm/rcar-du/rcar_du_drv.c
@@ -378,7 +378,7 @@ static int rcar_du_remove(struct platform_device *pdev)
drm_kms_helper_poll_fini(ddev);
drm_mode_config_cleanup(ddev);
 
-   drm_dev_unref(ddev);
+   drm_dev_put(ddev);
 
return 0;
 }
-- 
2.14.1



[PATCH] drm: rcar-du: Use drm_dev_put

2018-04-25 Thread Vaishali Thakkar
As specified in drm_drv.c, drm_dev_unref is a compatibility alias
for drm_dev_put and shouldn't be used in new code. So, use
drm_dev_put instead.

Signed-off-by: Vaishali Thakkar 
---
 drivers/gpu/drm/rcar-du/rcar_du_drv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/rcar-du/rcar_du_drv.c 
b/drivers/gpu/drm/rcar-du/rcar_du_drv.c
index 05745e86d73e..418a80e6b2f4 100644
--- a/drivers/gpu/drm/rcar-du/rcar_du_drv.c
+++ b/drivers/gpu/drm/rcar-du/rcar_du_drv.c
@@ -378,7 +378,7 @@ static int rcar_du_remove(struct platform_device *pdev)
drm_kms_helper_poll_fini(ddev);
drm_mode_config_cleanup(ddev);
 
-   drm_dev_unref(ddev);
+   drm_dev_put(ddev);
 
return 0;
 }
-- 
2.14.1



[PATCH] drm/vc4: make function vc4_allocate_bin_bo static

2018-04-25 Thread Vaishali Thakkar
Sparse complains with following warning:
drivers/gpu/drm/vc4/vc4_v3d.c:222:1: warning: symbol
'vc4_allocate_bin_bo' was not declared. Should it be static?

Make vc4_allocate_bin static as it is not used outside of
vc4_v3d.c.

Signed-off-by: Vaishali Thakkar <vthakkar1...@gmail.com>
---
 drivers/gpu/drm/vc4/vc4_v3d.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/vc4/vc4_v3d.c b/drivers/gpu/drm/vc4/vc4_v3d.c
index bfc2fa73d2ae..e47e29426078 100644
--- a/drivers/gpu/drm/vc4/vc4_v3d.c
+++ b/drivers/gpu/drm/vc4/vc4_v3d.c
@@ -218,8 +218,7 @@ int vc4_v3d_get_bin_slot(struct vc4_dev *vc4)
  * overall CMA pool before they make scenes complicated enough to run
  * out of bin space.
  */
-int
-vc4_allocate_bin_bo(struct drm_device *drm)
+static int vc4_allocate_bin_bo(struct drm_device *drm)
 {
struct vc4_dev *vc4 = to_vc4_dev(drm);
struct vc4_v3d *v3d = vc4->v3d;
-- 
2.14.1



[PATCH] drm/vc4: make function vc4_allocate_bin_bo static

2018-04-25 Thread Vaishali Thakkar
Sparse complains with following warning:
drivers/gpu/drm/vc4/vc4_v3d.c:222:1: warning: symbol
'vc4_allocate_bin_bo' was not declared. Should it be static?

Make vc4_allocate_bin static as it is not used outside of
vc4_v3d.c.

Signed-off-by: Vaishali Thakkar 
---
 drivers/gpu/drm/vc4/vc4_v3d.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/vc4/vc4_v3d.c b/drivers/gpu/drm/vc4/vc4_v3d.c
index bfc2fa73d2ae..e47e29426078 100644
--- a/drivers/gpu/drm/vc4/vc4_v3d.c
+++ b/drivers/gpu/drm/vc4/vc4_v3d.c
@@ -218,8 +218,7 @@ int vc4_v3d_get_bin_slot(struct vc4_dev *vc4)
  * overall CMA pool before they make scenes complicated enough to run
  * out of bin space.
  */
-int
-vc4_allocate_bin_bo(struct drm_device *drm)
+static int vc4_allocate_bin_bo(struct drm_device *drm)
 {
struct vc4_dev *vc4 = to_vc4_dev(drm);
struct vc4_v3d *v3d = vc4->v3d;
-- 
2.14.1



[PATCH v2] Coccinelle: api: Add offset_in_page.cocci

2017-05-05 Thread Vaishali Thakkar
Use of offset_in_page is preferable instead of open coding.
This patch adds coccinelle script for suggesting the use of
macro offset_in_page.

Signed-off-by: Vaishali Thakkar <vaishali.thak...@oracle.com>
---
Changes since v1:
- Add parenthesis around rule for patch mode to avoid
  extra parenthesis in end result
---
 scripts/coccinelle/api/offset_in_page.cocci | 77 +
 1 file changed, 77 insertions(+)
 create mode 100644 scripts/coccinelle/api/offset_in_page.cocci

diff --git a/scripts/coccinelle/api/offset_in_page.cocci 
b/scripts/coccinelle/api/offset_in_page.cocci
new file mode 100644
index 000..4034864
--- /dev/null
+++ b/scripts/coccinelle/api/offset_in_page.cocci
@@ -0,0 +1,77 @@
+/// Use offset_in_page instead of duplicating its implementation
+///
+// Confidence: High
+// Copyright: (C) 2017 Vaishali Thakkar, Oracle. GPLv2.
+// Options: --no-includes --include-headers
+// Keywords: offset_in_page
+
+virtual patch
+virtual context
+virtual org
+virtual report
+
+@r_patch depends on patch@
+expression e;
+identifier i;
+@@
+- unsigned long i = (unsigned long)e & ~PAGE_MASK;
+...
+- i
++ offset_in_page(e)
+
+@r1_patch depends on patch@
+expression e1;
+@@
+
+(
+- ((unsigned long)e1 & ~PAGE_MASK)
++ offset_in_page(e1)
+|
+- ((unsigned long)e1 % PAGE_SIZE)
++ offset_in_page(e1)
+)
+
+@r_context depends on !patch@
+expression e;
+identifier i;
+position p;
+@@
+
+* unsigned long i = (unsigned long)e@p & ~PAGE_MASK;
+...
+* i
+
+@r1_context depends on !patch@
+expression e1;
+position p1;
+@@
+
+(
+* (unsigned long)e1@p1 & ~PAGE_MASK
+|
+* (unsigned long)e1@p1 % PAGE_SIZE
+)
+
+@script:python depends on org@
+p << r_context.p;
+@@
+
+coccilib.org.print_todo(p[0], "WARNING opportunity for offset_in_page")
+
+@script:python depends on org@
+p << r1_context.p1;
+@@
+
+coccilib.org.print_todo(p[0], "WARNING opportunity for offset_in_page")
+
+@script:python depends on report@
+p << r_context.p;
+@@
+
+coccilib.report.print_report(p[0], "WARNING opportunity for offset_in_page")
+
+@script:python depends on report@
+p << r1_context.p1;
+@@
+
+coccilib.report.print_report(p[0], "WARNING opportunity for offset_in_page")
-- 
2.7.4



[PATCH v2] Coccinelle: api: Add offset_in_page.cocci

2017-05-05 Thread Vaishali Thakkar
Use of offset_in_page is preferable instead of open coding.
This patch adds coccinelle script for suggesting the use of
macro offset_in_page.

Signed-off-by: Vaishali Thakkar 
---
Changes since v1:
- Add parenthesis around rule for patch mode to avoid
  extra parenthesis in end result
---
 scripts/coccinelle/api/offset_in_page.cocci | 77 +
 1 file changed, 77 insertions(+)
 create mode 100644 scripts/coccinelle/api/offset_in_page.cocci

diff --git a/scripts/coccinelle/api/offset_in_page.cocci 
b/scripts/coccinelle/api/offset_in_page.cocci
new file mode 100644
index 000..4034864
--- /dev/null
+++ b/scripts/coccinelle/api/offset_in_page.cocci
@@ -0,0 +1,77 @@
+/// Use offset_in_page instead of duplicating its implementation
+///
+// Confidence: High
+// Copyright: (C) 2017 Vaishali Thakkar, Oracle. GPLv2.
+// Options: --no-includes --include-headers
+// Keywords: offset_in_page
+
+virtual patch
+virtual context
+virtual org
+virtual report
+
+@r_patch depends on patch@
+expression e;
+identifier i;
+@@
+- unsigned long i = (unsigned long)e & ~PAGE_MASK;
+...
+- i
++ offset_in_page(e)
+
+@r1_patch depends on patch@
+expression e1;
+@@
+
+(
+- ((unsigned long)e1 & ~PAGE_MASK)
++ offset_in_page(e1)
+|
+- ((unsigned long)e1 % PAGE_SIZE)
++ offset_in_page(e1)
+)
+
+@r_context depends on !patch@
+expression e;
+identifier i;
+position p;
+@@
+
+* unsigned long i = (unsigned long)e@p & ~PAGE_MASK;
+...
+* i
+
+@r1_context depends on !patch@
+expression e1;
+position p1;
+@@
+
+(
+* (unsigned long)e1@p1 & ~PAGE_MASK
+|
+* (unsigned long)e1@p1 % PAGE_SIZE
+)
+
+@script:python depends on org@
+p << r_context.p;
+@@
+
+coccilib.org.print_todo(p[0], "WARNING opportunity for offset_in_page")
+
+@script:python depends on org@
+p << r1_context.p1;
+@@
+
+coccilib.org.print_todo(p[0], "WARNING opportunity for offset_in_page")
+
+@script:python depends on report@
+p << r_context.p;
+@@
+
+coccilib.report.print_report(p[0], "WARNING opportunity for offset_in_page")
+
+@script:python depends on report@
+p << r1_context.p1;
+@@
+
+coccilib.report.print_report(p[0], "WARNING opportunity for offset_in_page")
-- 
2.7.4



[PATCH] Coccinelle: api: Add offset_in_page.cocci

2017-04-25 Thread Vaishali Thakkar
Use of offset_in_page is preferable instead of open coding.
This patch adds coccinelle script for suggesting the use of
macro offset_in_page.

Signed-off-by: Vaishali Thakkar <vaishali.thak...@oracle.com>
---
 scripts/coccinelle/api/offset_in_page.cocci | 77 +
 1 file changed, 77 insertions(+)
 create mode 100644 scripts/coccinelle/api/offset_in_page.cocci

diff --git a/scripts/coccinelle/api/offset_in_page.cocci 
b/scripts/coccinelle/api/offset_in_page.cocci
new file mode 100644
index 000..d083109
--- /dev/null
+++ b/scripts/coccinelle/api/offset_in_page.cocci
@@ -0,0 +1,77 @@
+/// Use offset_in_page instead of duplicating its implementation
+///
+// Confidence: High
+// Copyright: (C) 2017 Vaishali Thakkar, Oracle. GPLv2.
+// Options: --no-includes --include-headers
+// Keywords: offset_in_page
+
+virtual patch
+virtual context
+virtual org
+virtual report
+
+@r_patch depends on patch@
+expression e;
+identifier i;
+@@
+- unsigned long i = (unsigned long)e & ~PAGE_MASK;
+...
+- i
++ offset_in_page(e)
+
+@r1_patch depends on patch@
+expression e1;
+@@
+
+(
+- (unsigned long)e1 & ~PAGE_MASK
++ offset_in_page(e1)
+|
+- (unsigned long)e1 % PAGE_SIZE
++ offset_in_page(e1)
+)
+
+@r_context depends on !patch@
+expression e;
+identifier i;
+position p;
+@@
+
+* unsigned long i = (unsigned long)e@p & ~PAGE_MASK;
+...
+* i
+
+@r1_context depends on !patch@
+expression e1;
+position p1;
+@@
+
+(
+* (unsigned long)e1@p1 & ~PAGE_MASK
+|
+* (unsigned long)e1@p1 % PAGE_SIZE
+)
+
+@script:python depends on org@
+p << r_context.p;
+@@
+
+coccilib.org.print_todo(p[0], "WARNING opportunity for offset_in_page")
+
+@script:python depends on org@
+p << r1_context.p1;
+@@
+
+coccilib.org.print_todo(p[0], "WARNING opportunity for offset_in_page")
+
+@script:python depends on report@
+p << r_context.p;
+@@
+
+coccilib.report.print_report(p[0], "WARNING opportunity for offset_in_page")
+
+@script:python depends on report@
+p << r1_context.p1;
+@@
+
+coccilib.report.print_report(p[0], "WARNING opportunity for offset_in_page")
-- 
2.7.4



[PATCH] Coccinelle: api: Add offset_in_page.cocci

2017-04-25 Thread Vaishali Thakkar
Use of offset_in_page is preferable instead of open coding.
This patch adds coccinelle script for suggesting the use of
macro offset_in_page.

Signed-off-by: Vaishali Thakkar 
---
 scripts/coccinelle/api/offset_in_page.cocci | 77 +
 1 file changed, 77 insertions(+)
 create mode 100644 scripts/coccinelle/api/offset_in_page.cocci

diff --git a/scripts/coccinelle/api/offset_in_page.cocci 
b/scripts/coccinelle/api/offset_in_page.cocci
new file mode 100644
index 000..d083109
--- /dev/null
+++ b/scripts/coccinelle/api/offset_in_page.cocci
@@ -0,0 +1,77 @@
+/// Use offset_in_page instead of duplicating its implementation
+///
+// Confidence: High
+// Copyright: (C) 2017 Vaishali Thakkar, Oracle. GPLv2.
+// Options: --no-includes --include-headers
+// Keywords: offset_in_page
+
+virtual patch
+virtual context
+virtual org
+virtual report
+
+@r_patch depends on patch@
+expression e;
+identifier i;
+@@
+- unsigned long i = (unsigned long)e & ~PAGE_MASK;
+...
+- i
++ offset_in_page(e)
+
+@r1_patch depends on patch@
+expression e1;
+@@
+
+(
+- (unsigned long)e1 & ~PAGE_MASK
++ offset_in_page(e1)
+|
+- (unsigned long)e1 % PAGE_SIZE
++ offset_in_page(e1)
+)
+
+@r_context depends on !patch@
+expression e;
+identifier i;
+position p;
+@@
+
+* unsigned long i = (unsigned long)e@p & ~PAGE_MASK;
+...
+* i
+
+@r1_context depends on !patch@
+expression e1;
+position p1;
+@@
+
+(
+* (unsigned long)e1@p1 & ~PAGE_MASK
+|
+* (unsigned long)e1@p1 % PAGE_SIZE
+)
+
+@script:python depends on org@
+p << r_context.p;
+@@
+
+coccilib.org.print_todo(p[0], "WARNING opportunity for offset_in_page")
+
+@script:python depends on org@
+p << r1_context.p1;
+@@
+
+coccilib.org.print_todo(p[0], "WARNING opportunity for offset_in_page")
+
+@script:python depends on report@
+p << r_context.p;
+@@
+
+coccilib.report.print_report(p[0], "WARNING opportunity for offset_in_page")
+
+@script:python depends on report@
+p << r1_context.p1;
+@@
+
+coccilib.report.print_report(p[0], "WARNING opportunity for offset_in_page")
-- 
2.7.4



Re: [Outreachy kernel] Re: [PATCH v2 4/6] staging: fbtft: Fix sparse warnings of incorrect type in assignment

2017-03-04 Thread Vaishali Thakkar
On Sun, Mar 5, 2017 at 10:10 AM, SIMRAN SINGHAL
 wrote:
> On Sun, Mar 5, 2017 at 5:36 AM, Alison Schofield  wrote:
>> On Thu, Mar 02, 2017 at 02:26:37PM +0100, Noralf Trønnes wrote:
>>>
>>> Den 02.03.2017 14.04, skrev simran singhal:
>>> >This patch fixes the following sparse warnings:
>>> >
>>> >drivers/staging/fbtft/fbtft-bus.c:166:36: warning: incorrect type in 
>>> >assignment (different base types)
>>> >drivers/staging/fbtft/fbtft-bus.c:166:36:expected unsigned short 
>>> >[unsigned] [short] [usertype] 
>>> >drivers/staging/fbtft/fbtft-bus.c:166:36:got restricted __be16 
>>> >[usertype] 
>>> >
>>> >drivers/staging/fbtft/fbtft-io.c:74:29: warning: incorrect type in 
>>> >assignment (different base types)
>>> >drivers/staging/fbtft/fbtft-io.c:74:29:expected unsigned long long 
>>> >[unsigned] [long] [long long] [usertype] 
>>> >drivers/staging/fbtft/fbtft-io.c:74:29:got restricted __be64 
>>> >[usertype] 
>>> >
>>> >Signed-off-by: simran singhal 
>>> >---
>>> >  v2:
>>> >-changed commit message
>>> >
>>> >  drivers/staging/fbtft/fbtft-bus.c | 2 +-
>>> >  drivers/staging/fbtft/fbtft-io.c  | 2 +-
>>> >  2 files changed, 2 insertions(+), 2 deletions(-)
>>> >
>>> >diff --git a/drivers/staging/fbtft/fbtft-bus.c 
>>> >b/drivers/staging/fbtft/fbtft-bus.c
>>> >index ec45043..df2223e 100644
>>> >--- a/drivers/staging/fbtft/fbtft-bus.c
>>> >+++ b/drivers/staging/fbtft/fbtft-bus.c
>>> >@@ -163,7 +163,7 @@ int fbtft_write_vmem16_bus8(struct fbtft_par *par, 
>>> >size_t offset, size_t len)
>>> > to_copy, remain - to_copy);
>>> > for (i = 0; i < to_copy; i++)
>>> >-txbuf16[i] = cpu_to_be16(vmem16[i]);
>>> >+txbuf16[i] = vmem16[i];
>>>
>>> This change breaks functionality on little endian machines like
>>> the Raspberry Pi.
>>>
>>>
>>> Noralf.
>>>
>>
>> Hi Simran,
>>
>> It's probably good to get back to this one while we have Noralf's
>> attention.
>>
>> While the change above - in fbtft-bus.c is a problem, the change
>> below in fbtft-io.c looks ok.  So, compare what you did.  You can't
>> *not* do the endian conversion.
>>
>> This is a cleanup change, a cosmetic change.  There is no underlying
>> bug, so you just need to get the typing correct w/out affecting
>> behavior.
>> anyway.
>>
>> BTW: I think it's OK to pull this one out and send a v3 of this alone.
>> That would mean abandoning the patchset and doing them one at a time.
>> They are all in different drivers
>
> Hi alison,
>
> Thanks for the explaination.
>
> I will drop the changes I did in fbtft-bus.c and send a v3 of this alone.
>
> Can you please suggest me any source through which I can understand the
> concept of endianess. As right know I didn't understand it, I just
> tried to fix the
> warnings which I got through sparse and as you can see most of the fixes are
> wrong.
>
> Thanks!
> Simran
>

Hi Simran,

I would suggest to have a look at thie LWN article[1]. It is pretty old
article but explains very well on the concept of why these annotations
[__le16, __le32 etc] were introduced at first place and how Sparse
gives warnings based on these annotations.

In addition, you should look at the definitions of byte ordering macros.
For example, in this example we have 'cpu_to_be64' then you can go
and look at the definition of that macro see where they are used and
why they are used in the first place.

Thanks.

[1] https://lwn.net/Articles/205624/

>
>> alisons
>
>>
>>
>>
>>> > vmem16 = vmem16 + to_copy;
>>> > ret = par->fbtftops.write(par, par->txbuf.buf,
>>> >diff --git a/drivers/staging/fbtft/fbtft-io.c 
>>> >b/drivers/staging/fbtft/fbtft-io.c
>>> >index d868405..ffb9a3b 100644
>>> >--- a/drivers/staging/fbtft/fbtft-io.c
>>> >+++ b/drivers/staging/fbtft/fbtft-io.c
>>> >@@ -71,7 +71,7 @@ int fbtft_write_spi_emulate_9(struct fbtft_par *par, 
>>> >void *buf, size_t len)
>>> > src++;
>>> > }
>>> > tmp |= ((*src & 0x0100) ? 1 : 0);
>>> >-*(u64 *)dst = cpu_to_be64(tmp);
>>> >+*(__be64 *)dst = cpu_to_be64(tmp);
>>> > dst += 8;
>>> > *dst++ = (u8)(*src++ & 0x00FF);
>>> > added++;
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups 
>>> "outreachy-kernel" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an 
>>> email to outreachy-kernel+unsubscr...@googlegroups.com.
>>> To post to this group, send email to outreachy-ker...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/outreachy-kernel/fe8d6a85-3d4e-8019-937b-22389b942da3%40tronnes.org.
>>> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "outreachy-kernel" group.
> To 

Re: [Outreachy kernel] Re: [PATCH v2 4/6] staging: fbtft: Fix sparse warnings of incorrect type in assignment

2017-03-04 Thread Vaishali Thakkar
On Sun, Mar 5, 2017 at 10:10 AM, SIMRAN SINGHAL
 wrote:
> On Sun, Mar 5, 2017 at 5:36 AM, Alison Schofield  wrote:
>> On Thu, Mar 02, 2017 at 02:26:37PM +0100, Noralf Trønnes wrote:
>>>
>>> Den 02.03.2017 14.04, skrev simran singhal:
>>> >This patch fixes the following sparse warnings:
>>> >
>>> >drivers/staging/fbtft/fbtft-bus.c:166:36: warning: incorrect type in 
>>> >assignment (different base types)
>>> >drivers/staging/fbtft/fbtft-bus.c:166:36:expected unsigned short 
>>> >[unsigned] [short] [usertype] 
>>> >drivers/staging/fbtft/fbtft-bus.c:166:36:got restricted __be16 
>>> >[usertype] 
>>> >
>>> >drivers/staging/fbtft/fbtft-io.c:74:29: warning: incorrect type in 
>>> >assignment (different base types)
>>> >drivers/staging/fbtft/fbtft-io.c:74:29:expected unsigned long long 
>>> >[unsigned] [long] [long long] [usertype] 
>>> >drivers/staging/fbtft/fbtft-io.c:74:29:got restricted __be64 
>>> >[usertype] 
>>> >
>>> >Signed-off-by: simran singhal 
>>> >---
>>> >  v2:
>>> >-changed commit message
>>> >
>>> >  drivers/staging/fbtft/fbtft-bus.c | 2 +-
>>> >  drivers/staging/fbtft/fbtft-io.c  | 2 +-
>>> >  2 files changed, 2 insertions(+), 2 deletions(-)
>>> >
>>> >diff --git a/drivers/staging/fbtft/fbtft-bus.c 
>>> >b/drivers/staging/fbtft/fbtft-bus.c
>>> >index ec45043..df2223e 100644
>>> >--- a/drivers/staging/fbtft/fbtft-bus.c
>>> >+++ b/drivers/staging/fbtft/fbtft-bus.c
>>> >@@ -163,7 +163,7 @@ int fbtft_write_vmem16_bus8(struct fbtft_par *par, 
>>> >size_t offset, size_t len)
>>> > to_copy, remain - to_copy);
>>> > for (i = 0; i < to_copy; i++)
>>> >-txbuf16[i] = cpu_to_be16(vmem16[i]);
>>> >+txbuf16[i] = vmem16[i];
>>>
>>> This change breaks functionality on little endian machines like
>>> the Raspberry Pi.
>>>
>>>
>>> Noralf.
>>>
>>
>> Hi Simran,
>>
>> It's probably good to get back to this one while we have Noralf's
>> attention.
>>
>> While the change above - in fbtft-bus.c is a problem, the change
>> below in fbtft-io.c looks ok.  So, compare what you did.  You can't
>> *not* do the endian conversion.
>>
>> This is a cleanup change, a cosmetic change.  There is no underlying
>> bug, so you just need to get the typing correct w/out affecting
>> behavior.
>> anyway.
>>
>> BTW: I think it's OK to pull this one out and send a v3 of this alone.
>> That would mean abandoning the patchset and doing them one at a time.
>> They are all in different drivers
>
> Hi alison,
>
> Thanks for the explaination.
>
> I will drop the changes I did in fbtft-bus.c and send a v3 of this alone.
>
> Can you please suggest me any source through which I can understand the
> concept of endianess. As right know I didn't understand it, I just
> tried to fix the
> warnings which I got through sparse and as you can see most of the fixes are
> wrong.
>
> Thanks!
> Simran
>

Hi Simran,

I would suggest to have a look at thie LWN article[1]. It is pretty old
article but explains very well on the concept of why these annotations
[__le16, __le32 etc] were introduced at first place and how Sparse
gives warnings based on these annotations.

In addition, you should look at the definitions of byte ordering macros.
For example, in this example we have 'cpu_to_be64' then you can go
and look at the definition of that macro see where they are used and
why they are used in the first place.

Thanks.

[1] https://lwn.net/Articles/205624/

>
>> alisons
>
>>
>>
>>
>>> > vmem16 = vmem16 + to_copy;
>>> > ret = par->fbtftops.write(par, par->txbuf.buf,
>>> >diff --git a/drivers/staging/fbtft/fbtft-io.c 
>>> >b/drivers/staging/fbtft/fbtft-io.c
>>> >index d868405..ffb9a3b 100644
>>> >--- a/drivers/staging/fbtft/fbtft-io.c
>>> >+++ b/drivers/staging/fbtft/fbtft-io.c
>>> >@@ -71,7 +71,7 @@ int fbtft_write_spi_emulate_9(struct fbtft_par *par, 
>>> >void *buf, size_t len)
>>> > src++;
>>> > }
>>> > tmp |= ((*src & 0x0100) ? 1 : 0);
>>> >-*(u64 *)dst = cpu_to_be64(tmp);
>>> >+*(__be64 *)dst = cpu_to_be64(tmp);
>>> > dst += 8;
>>> > *dst++ = (u8)(*src++ & 0x00FF);
>>> > added++;
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups 
>>> "outreachy-kernel" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an 
>>> email to outreachy-kernel+unsubscr...@googlegroups.com.
>>> To post to this group, send email to outreachy-ker...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/outreachy-kernel/fe8d6a85-3d4e-8019-937b-22389b942da3%40tronnes.org.
>>> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "outreachy-kernel" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to 

Re: [Cocci] [RFC] coccicheck: add a test for repeat memory fetches

2017-01-10 Thread Vaishali Thakkar

On Wednesday 11 January 2017 05:34 AM, Kees Cook wrote:

On Tue, Jan 10, 2017 at 1:14 PM, Julia Lawall  wrote:

OK, I have the impression that what you are looking for is the following,
that currently does not seem to work well. Still maybe it gives an idea.

The basic pattern is the following sequence:

1. copy_from_user
2. test on a field of the copied value
3. another copy_from_user
4. a use of the same field as tested in step 2 from the structure obtained
by the second copy_from_user or a function call with the structure as an
argument


This looks pretty good!


In the case where the second copy_from_user stores the result in a
pointer, then a return with no reference of the tested field is also a
concern, unless, the pointer was already kfreed.


I think sequence "2" above missing just looking at a direct value,
like if instead of a field it was a u32. Also, should binop include
"=="?

And we need to add back in get_user() too... hmmm


May be having a separate script for get_user would be a good idea. 
get_user needs few more tests than copy_from_user. Also, for the both 
cases we can later add multi-function handling rules. And for the 
get_user, may be combinational usage rule as well.



-Kees





Re: [Cocci] [RFC] coccicheck: add a test for repeat memory fetches

2017-01-10 Thread Vaishali Thakkar

On Wednesday 11 January 2017 05:34 AM, Kees Cook wrote:

On Tue, Jan 10, 2017 at 1:14 PM, Julia Lawall  wrote:

OK, I have the impression that what you are looking for is the following,
that currently does not seem to work well. Still maybe it gives an idea.

The basic pattern is the following sequence:

1. copy_from_user
2. test on a field of the copied value
3. another copy_from_user
4. a use of the same field as tested in step 2 from the structure obtained
by the second copy_from_user or a function call with the structure as an
argument


This looks pretty good!


In the case where the second copy_from_user stores the result in a
pointer, then a return with no reference of the tested field is also a
concern, unless, the pointer was already kfreed.


I think sequence "2" above missing just looking at a direct value,
like if instead of a field it was a u32. Also, should binop include
"=="?

And we need to add back in get_user() too... hmmm


May be having a separate script for get_user would be a good idea. 
get_user needs few more tests than copy_from_user. Also, for the both 
cases we can later add multi-function handling rules. And for the 
get_user, may be combinational usage rule as well.



-Kees





Re: [Cocci] [PATCH] coccicheck: add a test for repeat copy_from_user

2017-01-10 Thread Vaishali Thakkar

On Tuesday 10 January 2017 02:32 PM, Pengfei Wang wrote:



在 2017年1月10日,下午4:40,Vaishali Thakkar <vaishali.thak...@oracle.com> 写道:

On Tuesday 10 January 2017 01:51 PM, Pengfei Wang wrote:



在 2017年1月10日,上午1:05,Vaishali Thakkar <vaishali.thak...@oracle.com> 写道:

On Tuesday 27 December 2016 11:51 PM, Julia Lawall wrote:

I totally dropped the ball on this.  Many thanks to Vaishali for
resurrecting it.

Some changes are suggested below.

On Tue, 26 Apr 2016, Kees Cook wrote:


This is usually a sign of a resized request. This adds a check for
potential races or confusions. The check isn't 100% accurate, so it
needs some manual review.

Signed-off-by: Kees Cook <keesc...@chromium.org>
---
scripts/coccinelle/tests/reusercopy.cocci | 36 +++
1 file changed, 36 insertions(+)
create mode 100644 scripts/coccinelle/tests/reusercopy.cocci

diff --git a/scripts/coccinelle/tests/reusercopy.cocci 
b/scripts/coccinelle/tests/reusercopy.cocci
new file mode 100644
index ..53645de8ae95
--- /dev/null
+++ b/scripts/coccinelle/tests/reusercopy.cocci
@@ -0,0 +1,36 @@
+/// Recopying from the same user buffer frequently indicates a pattern of
+/// Reading a size header, allocating, and then re-reading an entire
+/// structure. If the structure's size is not re-validated, this can lead
+/// to structure or data size confusions.
+///
+// Confidence: Moderate
+// Copyright: (C) 2016 Kees Cook, Google. License: GPLv2.
+// URL: http://coccinelle.lip6.fr/
+// Comments:
+// Options: -no_includes -include_headers


The options could be: --no-include --include-headers

Actually, Coccinelle supports both, but it only officially supports the
-- versions.


+
+virtual report
+virtual org


Add, the following for the *s:

virtual context

Then add the following rule:

@ok@
position p;
expression src,dest;
@@

copy_from_user@p(, src, sizeof(dest))


+
+@cfu_twice@
+position p;


Change this to:

position p != ok.p;


+identifier src;
+expression dest1, dest2, size1, size2, offset;
+@@
+
+*copy_from_user(dest1, src, size1)
+ ... when != src = offset
+ when != src += offset


Here, may be we should add few more lines from Pengfei's
script to avoid th potential FPs.


Add the following lines:

   when != if (size2 > e1 || ...) { ... return ...; }
   when != if (size2 > e1 || ...) { ... size2 = e2 ... }

These changes drop cases where the last argument to copy_from_usr is the
size of the first argument, which seems safe enough, and where there is a
test on the size value that can either update it or abort the function.
These changes only eliminate false positives, as far as I could tell.

If it would be more convenient, I could just send the complete revised
patch, or whatever seems convenient.


I was also thinking that probably we should also add other user space memory 
API functions. May be get_user and strncpy_from_user. Although I'm not sure how 
common it is to find such patterns for both of these functions.


I strongly recommend you adding get_user() API , which is used pervasively
within the kernel just like copy_from user().


Sure. I have changed regetuser-wang.cocci from Kees's RFC patches to
include everything in the pattern matching rule. I'll send that as well.


In many situations, there is a combination use, get_user() copies first then
followed by a copy_from_user() copy. According to our investigation, this 
typical
situation works by get_user() firstly copying a field of a specific struct to 
check,
then copy_from_user() copies in the whole struct to use. Of course, the struct
field is fetch twice.


Do you mean that there is a problem when we have get_user() followed by 
copy_from_user()? Basically something like
this:

get_user(..., src.arg) //where src.arg = field of a structure
...
copy_from_user(..., src, ...) //where src is a whole structure

If that is the case then we would need to have one more new script
or rule for such kind of combinational patterns. Disjunction can
probably give FPs.


Yes, I’ve seen these cases when examining the source code. Actually, copying a 
field
first and then copying the whole struct is very common in the kernel especially 
the driver.
For example, when a struct (or a message as we call it) is variable length, the 
first copy is
used to check its size field, and allocate a kernel buffer based on it, then 
the second copy is
to copy the whole message also based on the size. There are also situations of 
the
variable type messages.

The reason that they use get_user() instead of copy_from_user() for the first 
copy is because
get_user() is defined as a macro, which works faster than a function call that 
copy_from_user() does
when copy simple data type such as char and int.


I see. If possible, can you point me to a code or actual bug
[reported by you or others] which has this kind of pattern
particularly?

I wrote a separate rule for the kind of pattern you have
described but I am not sure if this kind of code is s

Re: [Cocci] [PATCH] coccicheck: add a test for repeat copy_from_user

2017-01-10 Thread Vaishali Thakkar

On Tuesday 10 January 2017 02:32 PM, Pengfei Wang wrote:



在 2017年1月10日,下午4:40,Vaishali Thakkar  写道:

On Tuesday 10 January 2017 01:51 PM, Pengfei Wang wrote:



在 2017年1月10日,上午1:05,Vaishali Thakkar  写道:

On Tuesday 27 December 2016 11:51 PM, Julia Lawall wrote:

I totally dropped the ball on this.  Many thanks to Vaishali for
resurrecting it.

Some changes are suggested below.

On Tue, 26 Apr 2016, Kees Cook wrote:


This is usually a sign of a resized request. This adds a check for
potential races or confusions. The check isn't 100% accurate, so it
needs some manual review.

Signed-off-by: Kees Cook 
---
scripts/coccinelle/tests/reusercopy.cocci | 36 +++
1 file changed, 36 insertions(+)
create mode 100644 scripts/coccinelle/tests/reusercopy.cocci

diff --git a/scripts/coccinelle/tests/reusercopy.cocci 
b/scripts/coccinelle/tests/reusercopy.cocci
new file mode 100644
index ..53645de8ae95
--- /dev/null
+++ b/scripts/coccinelle/tests/reusercopy.cocci
@@ -0,0 +1,36 @@
+/// Recopying from the same user buffer frequently indicates a pattern of
+/// Reading a size header, allocating, and then re-reading an entire
+/// structure. If the structure's size is not re-validated, this can lead
+/// to structure or data size confusions.
+///
+// Confidence: Moderate
+// Copyright: (C) 2016 Kees Cook, Google. License: GPLv2.
+// URL: http://coccinelle.lip6.fr/
+// Comments:
+// Options: -no_includes -include_headers


The options could be: --no-include --include-headers

Actually, Coccinelle supports both, but it only officially supports the
-- versions.


+
+virtual report
+virtual org


Add, the following for the *s:

virtual context

Then add the following rule:

@ok@
position p;
expression src,dest;
@@

copy_from_user@p(, src, sizeof(dest))


+
+@cfu_twice@
+position p;


Change this to:

position p != ok.p;


+identifier src;
+expression dest1, dest2, size1, size2, offset;
+@@
+
+*copy_from_user(dest1, src, size1)
+ ... when != src = offset
+ when != src += offset


Here, may be we should add few more lines from Pengfei's
script to avoid th potential FPs.


Add the following lines:

   when != if (size2 > e1 || ...) { ... return ...; }
   when != if (size2 > e1 || ...) { ... size2 = e2 ... }

These changes drop cases where the last argument to copy_from_usr is the
size of the first argument, which seems safe enough, and where there is a
test on the size value that can either update it or abort the function.
These changes only eliminate false positives, as far as I could tell.

If it would be more convenient, I could just send the complete revised
patch, or whatever seems convenient.


I was also thinking that probably we should also add other user space memory 
API functions. May be get_user and strncpy_from_user. Although I'm not sure how 
common it is to find such patterns for both of these functions.


I strongly recommend you adding get_user() API , which is used pervasively
within the kernel just like copy_from user().


Sure. I have changed regetuser-wang.cocci from Kees's RFC patches to
include everything in the pattern matching rule. I'll send that as well.


In many situations, there is a combination use, get_user() copies first then
followed by a copy_from_user() copy. According to our investigation, this 
typical
situation works by get_user() firstly copying a field of a specific struct to 
check,
then copy_from_user() copies in the whole struct to use. Of course, the struct
field is fetch twice.


Do you mean that there is a problem when we have get_user() followed by 
copy_from_user()? Basically something like
this:

get_user(..., src.arg) //where src.arg = field of a structure
...
copy_from_user(..., src, ...) //where src is a whole structure

If that is the case then we would need to have one more new script
or rule for such kind of combinational patterns. Disjunction can
probably give FPs.


Yes, I’ve seen these cases when examining the source code. Actually, copying a 
field
first and then copying the whole struct is very common in the kernel especially 
the driver.
For example, when a struct (or a message as we call it) is variable length, the 
first copy is
used to check its size field, and allocate a kernel buffer based on it, then 
the second copy is
to copy the whole message also based on the size. There are also situations of 
the
variable type messages.

The reason that they use get_user() instead of copy_from_user() for the first 
copy is because
get_user() is defined as a macro, which works faster than a function call that 
copy_from_user() does
when copy simple data type such as char and int.


I see. If possible, can you point me to a code or actual bug
[reported by you or others] which has this kind of pattern
particularly?

I wrote a separate rule for the kind of pattern you have
described but I am not sure if this kind of code is suspicious.
Like you said, it is very common to use this pattern in drivers.
So may be suspicious one ca

Re: [Cocci] [PATCH] coccicheck: add a test for repeat copy_from_user

2017-01-10 Thread Vaishali Thakkar

On Tuesday 10 January 2017 01:51 PM, Pengfei Wang wrote:



在 2017年1月10日,上午1:05,Vaishali Thakkar <vaishali.thak...@oracle.com> 写道:

On Tuesday 27 December 2016 11:51 PM, Julia Lawall wrote:

I totally dropped the ball on this.  Many thanks to Vaishali for
resurrecting it.

Some changes are suggested below.

On Tue, 26 Apr 2016, Kees Cook wrote:


This is usually a sign of a resized request. This adds a check for
potential races or confusions. The check isn't 100% accurate, so it
needs some manual review.

Signed-off-by: Kees Cook <keesc...@chromium.org>
---
scripts/coccinelle/tests/reusercopy.cocci | 36 +++
1 file changed, 36 insertions(+)
create mode 100644 scripts/coccinelle/tests/reusercopy.cocci

diff --git a/scripts/coccinelle/tests/reusercopy.cocci 
b/scripts/coccinelle/tests/reusercopy.cocci
new file mode 100644
index ..53645de8ae95
--- /dev/null
+++ b/scripts/coccinelle/tests/reusercopy.cocci
@@ -0,0 +1,36 @@
+/// Recopying from the same user buffer frequently indicates a pattern of
+/// Reading a size header, allocating, and then re-reading an entire
+/// structure. If the structure's size is not re-validated, this can lead
+/// to structure or data size confusions.
+///
+// Confidence: Moderate
+// Copyright: (C) 2016 Kees Cook, Google. License: GPLv2.
+// URL: http://coccinelle.lip6.fr/
+// Comments:
+// Options: -no_includes -include_headers


The options could be: --no-include --include-headers

Actually, Coccinelle supports both, but it only officially supports the
-- versions.


+
+virtual report
+virtual org


Add, the following for the *s:

virtual context

Then add the following rule:

@ok@
position p;
expression src,dest;
@@

copy_from_user@p(, src, sizeof(dest))


+
+@cfu_twice@
+position p;


Change this to:

position p != ok.p;


+identifier src;
+expression dest1, dest2, size1, size2, offset;
+@@
+
+*copy_from_user(dest1, src, size1)
+ ... when != src = offset
+ when != src += offset


Here, may be we should add few more lines from Pengfei's
script to avoid th potential FPs.


Add the following lines:

when != if (size2 > e1 || ...) { ... return ...; }
when != if (size2 > e1 || ...) { ... size2 = e2 ... }

These changes drop cases where the last argument to copy_from_usr is the
size of the first argument, which seems safe enough, and where there is a
test on the size value that can either update it or abort the function.
These changes only eliminate false positives, as far as I could tell.

If it would be more convenient, I could just send the complete revised
patch, or whatever seems convenient.


I was also thinking that probably we should also add other user space memory 
API functions. May be get_user and strncpy_from_user. Although I'm not sure how 
common it is to find such patterns for both of these functions.


I strongly recommend you adding get_user() API , which is used pervasively
within the kernel just like copy_from user().


Sure. I have changed regetuser-wang.cocci from Kees's RFC patches to
include everything in the pattern matching rule. I'll send that as well.


In many situations, there is a combination use, get_user() copies first then
followed by a copy_from_user() copy. According to our investigation, this 
typical
situation works by get_user() firstly copying a field of a specific struct to 
check,
then copy_from_user() copies in the whole struct to use. Of course, the struct
field is fetch twice.


Do you mean that there is a problem when we have get_user() followed by 
copy_from_user()? Basically something like

this:

get_user(..., src.arg) //where src.arg = field of a structure
...
copy_from_user(..., src, ...) //where src is a whole structure

If that is the case then we would need to have one more new script
or rule for such kind of combinational patterns. Disjunction can
probably give FPs.

Thanks!


Regards
Pengfei



thanks,
julia


+*copy_from_user@p(dest2, src, size2)
+
+@script:python depends on org@
+p << cfu_twice.p;
+@@
+
+cocci.print_main("potentially dangerous second copy_from_user()",p)
+
+@script:python depends on report@
+p << cfu_twice.p;
+@@
+
+coccilib.report.print_report(p[0],"potentially dangerous second 
copy_from_user()")
--
2.6.3


--
Kees Cook
Chrome OS & Brillo Security


___
Cocci mailing list
co...@systeme.lip6.fr <mailto:co...@systeme.lip6.fr>
https://systeme.lip6.fr/mailman/listinfo/cocci 
<https://systeme.lip6.fr/mailman/listinfo/cocci>






Re: [Cocci] [PATCH] coccicheck: add a test for repeat copy_from_user

2017-01-10 Thread Vaishali Thakkar

On Tuesday 10 January 2017 01:51 PM, Pengfei Wang wrote:



在 2017年1月10日,上午1:05,Vaishali Thakkar  写道:

On Tuesday 27 December 2016 11:51 PM, Julia Lawall wrote:

I totally dropped the ball on this.  Many thanks to Vaishali for
resurrecting it.

Some changes are suggested below.

On Tue, 26 Apr 2016, Kees Cook wrote:


This is usually a sign of a resized request. This adds a check for
potential races or confusions. The check isn't 100% accurate, so it
needs some manual review.

Signed-off-by: Kees Cook 
---
scripts/coccinelle/tests/reusercopy.cocci | 36 +++
1 file changed, 36 insertions(+)
create mode 100644 scripts/coccinelle/tests/reusercopy.cocci

diff --git a/scripts/coccinelle/tests/reusercopy.cocci 
b/scripts/coccinelle/tests/reusercopy.cocci
new file mode 100644
index ..53645de8ae95
--- /dev/null
+++ b/scripts/coccinelle/tests/reusercopy.cocci
@@ -0,0 +1,36 @@
+/// Recopying from the same user buffer frequently indicates a pattern of
+/// Reading a size header, allocating, and then re-reading an entire
+/// structure. If the structure's size is not re-validated, this can lead
+/// to structure or data size confusions.
+///
+// Confidence: Moderate
+// Copyright: (C) 2016 Kees Cook, Google. License: GPLv2.
+// URL: http://coccinelle.lip6.fr/
+// Comments:
+// Options: -no_includes -include_headers


The options could be: --no-include --include-headers

Actually, Coccinelle supports both, but it only officially supports the
-- versions.


+
+virtual report
+virtual org


Add, the following for the *s:

virtual context

Then add the following rule:

@ok@
position p;
expression src,dest;
@@

copy_from_user@p(, src, sizeof(dest))


+
+@cfu_twice@
+position p;


Change this to:

position p != ok.p;


+identifier src;
+expression dest1, dest2, size1, size2, offset;
+@@
+
+*copy_from_user(dest1, src, size1)
+ ... when != src = offset
+ when != src += offset


Here, may be we should add few more lines from Pengfei's
script to avoid th potential FPs.


Add the following lines:

when != if (size2 > e1 || ...) { ... return ...; }
when != if (size2 > e1 || ...) { ... size2 = e2 ... }

These changes drop cases where the last argument to copy_from_usr is the
size of the first argument, which seems safe enough, and where there is a
test on the size value that can either update it or abort the function.
These changes only eliminate false positives, as far as I could tell.

If it would be more convenient, I could just send the complete revised
patch, or whatever seems convenient.


I was also thinking that probably we should also add other user space memory 
API functions. May be get_user and strncpy_from_user. Although I'm not sure how 
common it is to find such patterns for both of these functions.


I strongly recommend you adding get_user() API , which is used pervasively
within the kernel just like copy_from user().


Sure. I have changed regetuser-wang.cocci from Kees's RFC patches to
include everything in the pattern matching rule. I'll send that as well.


In many situations, there is a combination use, get_user() copies first then
followed by a copy_from_user() copy. According to our investigation, this 
typical
situation works by get_user() firstly copying a field of a specific struct to 
check,
then copy_from_user() copies in the whole struct to use. Of course, the struct
field is fetch twice.


Do you mean that there is a problem when we have get_user() followed by 
copy_from_user()? Basically something like

this:

get_user(..., src.arg) //where src.arg = field of a structure
...
copy_from_user(..., src, ...) //where src is a whole structure

If that is the case then we would need to have one more new script
or rule for such kind of combinational patterns. Disjunction can
probably give FPs.

Thanks!


Regards
Pengfei



thanks,
julia


+*copy_from_user@p(dest2, src, size2)
+
+@script:python depends on org@
+p << cfu_twice.p;
+@@
+
+cocci.print_main("potentially dangerous second copy_from_user()",p)
+
+@script:python depends on report@
+p << cfu_twice.p;
+@@
+
+coccilib.report.print_report(p[0],"potentially dangerous second 
copy_from_user()")
--
2.6.3


--
Kees Cook
Chrome OS & Brillo Security


___
Cocci mailing list
co...@systeme.lip6.fr <mailto:co...@systeme.lip6.fr>
https://systeme.lip6.fr/mailman/listinfo/cocci 
<https://systeme.lip6.fr/mailman/listinfo/cocci>






Re: [RFC] coccicheck: add a test for repeat memory fetches

2017-01-10 Thread Vaishali Thakkar
On Tue, Jan 10, 2017 at 1:31 PM, Julia Lawall  wrote:
>
>
> On Tue, 10 Jan 2017, Pengfei Wang wrote:
>
>>
>> > 在 2017年1月10日,下午2:06,Julia Lawall  写道:
>> >
>> >
>> >
>> > On Mon, 9 Jan 2017, Kees Cook wrote:
>> >
>> >> Okay, this adds a few tests, for people to examine.
>> >>
>> >> reusercopy-cook.cocci:
>> >> My original test, with recent updates from Julia.
>> >>
>> >> reusercopy-wang.cocci:
>> >> This is Pengfei's test, but with heavily modified reporting to fit in the
>> >> kernel coccicheck target, and with all the getuser checks removed so that
>> >> Julia's size test could be added (this lets us compare the results between
>> >> this and my original test).
>> >
>> > Thanks for the update.
>> >
>> > I'm not enthusiastic about all the python filtering.  It would be better
>> > to try to put it into the pattern matching rules.
>>
>> I agree with that. I used the python filtering because I could not filter 
>> out the false
>> positives with the rules since I was a beginner to Coccinelle. I encourage 
>> you to use
>> the pattern matching rules if possible.
>> >
>> > I'm not sure what is the point of func in the various rules.  Is there a
>> > need to ensure that the pattern appears only once in a function definition?
>>
>> It is unnecessary to use the “func” as long as it won’t cause an error when 
>> running the script.
>> I used it because we found that this pattern usually takes place within a 
>> function. The pattern
>> is not necessarily to appear only once, and our approach should be able to 
>> match multiple
>> occurrences of this pattern within one function.
>>
>> However, our approach currently cannot match an inter-function pattern, 
>> within which the two
>> copy operations reside in two functions respectively. The first function 
>> copies the user data first,
>> and it calls the second function, then within the second function, the user 
>> data is copied again
>> and used. This situation actually exists(CVE-2016-6516), and could cause bad 
>> consequences.

Thanks for the inputs on this issue. Indeed finding things under one
function are
obvious cases. /kernel/kexec_core.c was removed from the output because of
that approach. This can be easily done in the reusercopy-cook.cocci as well.

Also, reusercopy-wang.cocci  finds few more cases. I have done few changes in
reusercopy-cook.cocci to cover them in pattern matching rule only so
that we don't
need the whole python rule from reusercopy-wang.cocci. Was supposed to send it
but now that you have mentioned the issue with the inter function
pattern, let me try
to see if we can do that with Coccinelle. As far as it is within a
single file, I think
coccinelle would be able to do that. I'll send my proposed changes
after testing the
inter function pattern.

>> I also suggest adding more copy function APIs, such as strncpy_from_user(). 
>> I didn’t do so for
>> two reasons.
>> 1. My script already looks redundant and I’m trying to use a better 
>> structure.
>> 2. The other copy functions are not so prevalent as the four I used.
>> But adding more copy functions could make it more accurate.

I'll check about strncpy_from_user once we will have a coccinelle
script in a good shape
for both of these cases.

Thanks!

>> Please feel free to contact me if you have any questions about my script.
>
> Thanks for the feedback!  Indeed Coccinelle is not well adapted to
> interprocedural analysis, but it could be added to a limited extent, eg
> one level of function call if it seems useful, once the rest is in good
> shape.
>
> julia
>
>
>>
>> Regards
>> Pengfei
>>
>> >
>> > I'll look at this in more detail this evening, and try to remove more false
>> > positives.  If you know of some specifically, please let me know what they 
>> > are.
>> >
>> > thanks,
>> > julia
>> >
>> >
>> >>
>> >> regetuser-wang.cocci:
>> >> This is Pengfei's get_user() tests only (to compare against hits from just
>> >> the copy_from_user() tests).
>> >>
>> >> Comparing reusercopy-cook.cocci with reusercopy-wang.cocci:
>> >> -./arch/ia64/kernel/perfmon.c:4833
>> >> +./arch/powerpc/kernel/signal_32.c:742
>> >> +./arch/powerpc/kernel/signal_32.c:850
>> >> ./arch/powerpc/platforms/powernv/opal-prd.c:248
>> >> ./drivers/acpi/custom_method.c:54
>> >> -./drivers/firmware/efi/test/efi_test.c:617
>> >> -./drivers/hid/hid-picolcd_debugfs.c:283
>> >> +./drivers/gpu/drm/radeon/radeon_cs.c:635
>> >> ./drivers/hwtracing/stm/core.c:580
>> >> ./drivers/isdn/i4l/isdn_ppp.c:875
>> >> ./drivers/md/dm-ioctl.c:1741
>> >> -./drivers/misc/mic/vop/vop_vringh.c:775
>> >> +./drivers/md/md.c:7030
>> >> +./drivers/misc/lkdtm_usercopy.c:106
>> >> +./drivers/misc/lkdtm_usercopy.c:160
>> >> +./drivers/misc/lkdtm_usercopy.c:232
>> >> ./drivers/misc/mic/vop/vop_vringh.c:944
>> >> +./drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c:2159
>> >> +./drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c:2257
>> >> +./drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c:2302
>> >> 

Re: [RFC] coccicheck: add a test for repeat memory fetches

2017-01-10 Thread Vaishali Thakkar
On Tue, Jan 10, 2017 at 1:31 PM, Julia Lawall  wrote:
>
>
> On Tue, 10 Jan 2017, Pengfei Wang wrote:
>
>>
>> > 在 2017年1月10日,下午2:06,Julia Lawall  写道:
>> >
>> >
>> >
>> > On Mon, 9 Jan 2017, Kees Cook wrote:
>> >
>> >> Okay, this adds a few tests, for people to examine.
>> >>
>> >> reusercopy-cook.cocci:
>> >> My original test, with recent updates from Julia.
>> >>
>> >> reusercopy-wang.cocci:
>> >> This is Pengfei's test, but with heavily modified reporting to fit in the
>> >> kernel coccicheck target, and with all the getuser checks removed so that
>> >> Julia's size test could be added (this lets us compare the results between
>> >> this and my original test).
>> >
>> > Thanks for the update.
>> >
>> > I'm not enthusiastic about all the python filtering.  It would be better
>> > to try to put it into the pattern matching rules.
>>
>> I agree with that. I used the python filtering because I could not filter 
>> out the false
>> positives with the rules since I was a beginner to Coccinelle. I encourage 
>> you to use
>> the pattern matching rules if possible.
>> >
>> > I'm not sure what is the point of func in the various rules.  Is there a
>> > need to ensure that the pattern appears only once in a function definition?
>>
>> It is unnecessary to use the “func” as long as it won’t cause an error when 
>> running the script.
>> I used it because we found that this pattern usually takes place within a 
>> function. The pattern
>> is not necessarily to appear only once, and our approach should be able to 
>> match multiple
>> occurrences of this pattern within one function.
>>
>> However, our approach currently cannot match an inter-function pattern, 
>> within which the two
>> copy operations reside in two functions respectively. The first function 
>> copies the user data first,
>> and it calls the second function, then within the second function, the user 
>> data is copied again
>> and used. This situation actually exists(CVE-2016-6516), and could cause bad 
>> consequences.

Thanks for the inputs on this issue. Indeed finding things under one
function are
obvious cases. /kernel/kexec_core.c was removed from the output because of
that approach. This can be easily done in the reusercopy-cook.cocci as well.

Also, reusercopy-wang.cocci  finds few more cases. I have done few changes in
reusercopy-cook.cocci to cover them in pattern matching rule only so
that we don't
need the whole python rule from reusercopy-wang.cocci. Was supposed to send it
but now that you have mentioned the issue with the inter function
pattern, let me try
to see if we can do that with Coccinelle. As far as it is within a
single file, I think
coccinelle would be able to do that. I'll send my proposed changes
after testing the
inter function pattern.

>> I also suggest adding more copy function APIs, such as strncpy_from_user(). 
>> I didn’t do so for
>> two reasons.
>> 1. My script already looks redundant and I’m trying to use a better 
>> structure.
>> 2. The other copy functions are not so prevalent as the four I used.
>> But adding more copy functions could make it more accurate.

I'll check about strncpy_from_user once we will have a coccinelle
script in a good shape
for both of these cases.

Thanks!

>> Please feel free to contact me if you have any questions about my script.
>
> Thanks for the feedback!  Indeed Coccinelle is not well adapted to
> interprocedural analysis, but it could be added to a limited extent, eg
> one level of function call if it seems useful, once the rest is in good
> shape.
>
> julia
>
>
>>
>> Regards
>> Pengfei
>>
>> >
>> > I'll look at this in more detail this evening, and try to remove more false
>> > positives.  If you know of some specifically, please let me know what they 
>> > are.
>> >
>> > thanks,
>> > julia
>> >
>> >
>> >>
>> >> regetuser-wang.cocci:
>> >> This is Pengfei's get_user() tests only (to compare against hits from just
>> >> the copy_from_user() tests).
>> >>
>> >> Comparing reusercopy-cook.cocci with reusercopy-wang.cocci:
>> >> -./arch/ia64/kernel/perfmon.c:4833
>> >> +./arch/powerpc/kernel/signal_32.c:742
>> >> +./arch/powerpc/kernel/signal_32.c:850
>> >> ./arch/powerpc/platforms/powernv/opal-prd.c:248
>> >> ./drivers/acpi/custom_method.c:54
>> >> -./drivers/firmware/efi/test/efi_test.c:617
>> >> -./drivers/hid/hid-picolcd_debugfs.c:283
>> >> +./drivers/gpu/drm/radeon/radeon_cs.c:635
>> >> ./drivers/hwtracing/stm/core.c:580
>> >> ./drivers/isdn/i4l/isdn_ppp.c:875
>> >> ./drivers/md/dm-ioctl.c:1741
>> >> -./drivers/misc/mic/vop/vop_vringh.c:775
>> >> +./drivers/md/md.c:7030
>> >> +./drivers/misc/lkdtm_usercopy.c:106
>> >> +./drivers/misc/lkdtm_usercopy.c:160
>> >> +./drivers/misc/lkdtm_usercopy.c:232
>> >> ./drivers/misc/mic/vop/vop_vringh.c:944
>> >> +./drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c:2159
>> >> +./drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c:2257
>> >> +./drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c:2302
>> >> 

Re: [Cocci] [PATCH] coccicheck: add a test for repeat copy_from_user

2017-01-09 Thread Vaishali Thakkar

On Tuesday 27 December 2016 11:51 PM, Julia Lawall wrote:

I totally dropped the ball on this.  Many thanks to Vaishali for
resurrecting it.

Some changes are suggested below.

On Tue, 26 Apr 2016, Kees Cook wrote:


This is usually a sign of a resized request. This adds a check for
potential races or confusions. The check isn't 100% accurate, so it
needs some manual review.

Signed-off-by: Kees Cook 
---
 scripts/coccinelle/tests/reusercopy.cocci | 36 +++
 1 file changed, 36 insertions(+)
 create mode 100644 scripts/coccinelle/tests/reusercopy.cocci

diff --git a/scripts/coccinelle/tests/reusercopy.cocci 
b/scripts/coccinelle/tests/reusercopy.cocci
new file mode 100644
index ..53645de8ae95
--- /dev/null
+++ b/scripts/coccinelle/tests/reusercopy.cocci
@@ -0,0 +1,36 @@
+/// Recopying from the same user buffer frequently indicates a pattern of
+/// Reading a size header, allocating, and then re-reading an entire
+/// structure. If the structure's size is not re-validated, this can lead
+/// to structure or data size confusions.
+///
+// Confidence: Moderate
+// Copyright: (C) 2016 Kees Cook, Google. License: GPLv2.
+// URL: http://coccinelle.lip6.fr/
+// Comments:
+// Options: -no_includes -include_headers


The options could be: --no-include --include-headers

Actually, Coccinelle supports both, but it only officially supports the
-- versions.


+
+virtual report
+virtual org


Add, the following for the *s:

virtual context

Then add the following rule:

@ok@
position p;
expression src,dest;
@@

copy_from_user@p(, src, sizeof(dest))


+
+@cfu_twice@
+position p;


Change this to:

position p != ok.p;


+identifier src;
+expression dest1, dest2, size1, size2, offset;
+@@
+
+*copy_from_user(dest1, src, size1)
+ ... when != src = offset
+ when != src += offset


Here, may be we should add few more lines from Pengfei's
script to avoid th potential FPs.


Add the following lines:

 when != if (size2 > e1 || ...) { ... return ...; }
 when != if (size2 > e1 || ...) { ... size2 = e2 ... }

These changes drop cases where the last argument to copy_from_usr is the
size of the first argument, which seems safe enough, and where there is a
test on the size value that can either update it or abort the function.
These changes only eliminate false positives, as far as I could tell.

If it would be more convenient, I could just send the complete revised
patch, or whatever seems convenient.


I was also thinking that probably we should also add other user space 
memory API functions. May be get_user and strncpy_from_user. Although 
I'm not sure how common it is to find such patterns for both of these 
functions.



thanks,
julia


+*copy_from_user@p(dest2, src, size2)
+
+@script:python depends on org@
+p << cfu_twice.p;
+@@
+
+cocci.print_main("potentially dangerous second copy_from_user()",p)
+
+@script:python depends on report@
+p << cfu_twice.p;
+@@
+
+coccilib.report.print_report(p[0],"potentially dangerous second 
copy_from_user()")
--
2.6.3


--
Kees Cook
Chrome OS & Brillo Security


___
Cocci mailing list
co...@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci





Re: [Cocci] [PATCH] coccicheck: add a test for repeat copy_from_user

2017-01-09 Thread Vaishali Thakkar

On Tuesday 27 December 2016 11:51 PM, Julia Lawall wrote:

I totally dropped the ball on this.  Many thanks to Vaishali for
resurrecting it.

Some changes are suggested below.

On Tue, 26 Apr 2016, Kees Cook wrote:


This is usually a sign of a resized request. This adds a check for
potential races or confusions. The check isn't 100% accurate, so it
needs some manual review.

Signed-off-by: Kees Cook 
---
 scripts/coccinelle/tests/reusercopy.cocci | 36 +++
 1 file changed, 36 insertions(+)
 create mode 100644 scripts/coccinelle/tests/reusercopy.cocci

diff --git a/scripts/coccinelle/tests/reusercopy.cocci 
b/scripts/coccinelle/tests/reusercopy.cocci
new file mode 100644
index ..53645de8ae95
--- /dev/null
+++ b/scripts/coccinelle/tests/reusercopy.cocci
@@ -0,0 +1,36 @@
+/// Recopying from the same user buffer frequently indicates a pattern of
+/// Reading a size header, allocating, and then re-reading an entire
+/// structure. If the structure's size is not re-validated, this can lead
+/// to structure or data size confusions.
+///
+// Confidence: Moderate
+// Copyright: (C) 2016 Kees Cook, Google. License: GPLv2.
+// URL: http://coccinelle.lip6.fr/
+// Comments:
+// Options: -no_includes -include_headers


The options could be: --no-include --include-headers

Actually, Coccinelle supports both, but it only officially supports the
-- versions.


+
+virtual report
+virtual org


Add, the following for the *s:

virtual context

Then add the following rule:

@ok@
position p;
expression src,dest;
@@

copy_from_user@p(, src, sizeof(dest))


+
+@cfu_twice@
+position p;


Change this to:

position p != ok.p;


+identifier src;
+expression dest1, dest2, size1, size2, offset;
+@@
+
+*copy_from_user(dest1, src, size1)
+ ... when != src = offset
+ when != src += offset


Here, may be we should add few more lines from Pengfei's
script to avoid th potential FPs.


Add the following lines:

 when != if (size2 > e1 || ...) { ... return ...; }
 when != if (size2 > e1 || ...) { ... size2 = e2 ... }

These changes drop cases where the last argument to copy_from_usr is the
size of the first argument, which seems safe enough, and where there is a
test on the size value that can either update it or abort the function.
These changes only eliminate false positives, as far as I could tell.

If it would be more convenient, I could just send the complete revised
patch, or whatever seems convenient.


I was also thinking that probably we should also add other user space 
memory API functions. May be get_user and strncpy_from_user. Although 
I'm not sure how common it is to find such patterns for both of these 
functions.



thanks,
julia


+*copy_from_user@p(dest2, src, size2)
+
+@script:python depends on org@
+p << cfu_twice.p;
+@@
+
+cocci.print_main("potentially dangerous second copy_from_user()",p)
+
+@script:python depends on report@
+p << cfu_twice.p;
+@@
+
+coccilib.report.print_report(p[0],"potentially dangerous second 
copy_from_user()")
--
2.6.3


--
Kees Cook
Chrome OS & Brillo Security


___
Cocci mailing list
co...@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci





[PATCH v4 1/3] Coccinelle: misc: Improve the matching of rules

2016-11-23 Thread Vaishali Thakkar
Currently because of the left associativity of the operators, pattern
IRQF_ONESHOT | flags does not match with the pattern when we have more
than one flag after the disjunction. This eventually results in giving
false positives by the script. This patch eliminates these FPs by
improving the rule.

Signed-off-by: Vaishali Thakkar <vaishali.thak...@oracle.com>
---
Changes since v3:
- Few more changes in the script to avoid some
  possible false positives
- Moved initialization of all expressions in a single line
Changes since v2:
- No change in this patch
Changes since v1:
- Splitted patch in the patchset
---
 scripts/coccinelle/misc/irqf_oneshot.cocci | 36 +++---
 1 file changed, 23 insertions(+), 13 deletions(-)

diff --git a/scripts/coccinelle/misc/irqf_oneshot.cocci 
b/scripts/coccinelle/misc/irqf_oneshot.cocci
index b421150..bd3e140 100644
--- a/scripts/coccinelle/misc/irqf_oneshot.cocci
+++ b/scripts/coccinelle/misc/irqf_oneshot.cocci
@@ -15,16 +15,13 @@ virtual org
 virtual report
 
 @r1@
-expression dev;
-expression irq;
-expression thread_fn;
-expression flags;
+expression dev, irq, thread_fn;
 position p;
 @@
 (
 request_threaded_irq@p(irq, NULL, thread_fn,
 (
-flags | IRQF_ONESHOT
+IRQF_ONESHOT | ...
 |
 IRQF_ONESHOT
 )
@@ -32,21 +29,34 @@ IRQF_ONESHOT
 |
 devm_request_threaded_irq@p(dev, irq, NULL, thread_fn,
 (
-flags | IRQF_ONESHOT
+IRQF_ONESHOT | ...
 |
 IRQF_ONESHOT
 )
 , ...)
 )
 
-@depends on patch@
-expression dev;
-expression irq;
-expression thread_fn;
-expression flags;
+@r2@
+expression dev, irq, thread_fn, flags, e;
 position p != r1.p;
 @@
 (
+flags = IRQF_ONESHOT | ...
+|
+flags |= IRQF_ONESHOT | ...
+)
+... when != flags = e
+(
+request_threaded_irq@p(irq, NULL, thread_fn, flags, ...);
+|
+devm_request_threaded_irq@p(dev, irq, NULL, thread_fn, flags, ...);
+)
+
+@depends on patch@
+expression dev, irq, thread_fn, flags;
+position p != {r1.p,r2.p};
+@@
+(
 request_threaded_irq@p(irq, NULL, thread_fn,
 (
 -0
@@ -69,13 +79,13 @@ devm_request_threaded_irq@p(dev, irq, NULL, thread_fn,
 )
 
 @depends on context@
-position p != r1.p;
+position p != {r1.p,r2.p};
 @@
 *request_threaded_irq@p(...)
 
 @match depends on report || org@
 expression irq;
-position p != r1.p;
+position p != {r1.p,r2.p};
 @@
 request_threaded_irq@p(irq, NULL, ...)
 
-- 
2.1.4



[PATCH v4 1/3] Coccinelle: misc: Improve the matching of rules

2016-11-23 Thread Vaishali Thakkar
Currently because of the left associativity of the operators, pattern
IRQF_ONESHOT | flags does not match with the pattern when we have more
than one flag after the disjunction. This eventually results in giving
false positives by the script. This patch eliminates these FPs by
improving the rule.

Signed-off-by: Vaishali Thakkar 
---
Changes since v3:
- Few more changes in the script to avoid some
  possible false positives
- Moved initialization of all expressions in a single line
Changes since v2:
- No change in this patch
Changes since v1:
- Splitted patch in the patchset
---
 scripts/coccinelle/misc/irqf_oneshot.cocci | 36 +++---
 1 file changed, 23 insertions(+), 13 deletions(-)

diff --git a/scripts/coccinelle/misc/irqf_oneshot.cocci 
b/scripts/coccinelle/misc/irqf_oneshot.cocci
index b421150..bd3e140 100644
--- a/scripts/coccinelle/misc/irqf_oneshot.cocci
+++ b/scripts/coccinelle/misc/irqf_oneshot.cocci
@@ -15,16 +15,13 @@ virtual org
 virtual report
 
 @r1@
-expression dev;
-expression irq;
-expression thread_fn;
-expression flags;
+expression dev, irq, thread_fn;
 position p;
 @@
 (
 request_threaded_irq@p(irq, NULL, thread_fn,
 (
-flags | IRQF_ONESHOT
+IRQF_ONESHOT | ...
 |
 IRQF_ONESHOT
 )
@@ -32,21 +29,34 @@ IRQF_ONESHOT
 |
 devm_request_threaded_irq@p(dev, irq, NULL, thread_fn,
 (
-flags | IRQF_ONESHOT
+IRQF_ONESHOT | ...
 |
 IRQF_ONESHOT
 )
 , ...)
 )
 
-@depends on patch@
-expression dev;
-expression irq;
-expression thread_fn;
-expression flags;
+@r2@
+expression dev, irq, thread_fn, flags, e;
 position p != r1.p;
 @@
 (
+flags = IRQF_ONESHOT | ...
+|
+flags |= IRQF_ONESHOT | ...
+)
+... when != flags = e
+(
+request_threaded_irq@p(irq, NULL, thread_fn, flags, ...);
+|
+devm_request_threaded_irq@p(dev, irq, NULL, thread_fn, flags, ...);
+)
+
+@depends on patch@
+expression dev, irq, thread_fn, flags;
+position p != {r1.p,r2.p};
+@@
+(
 request_threaded_irq@p(irq, NULL, thread_fn,
 (
 -0
@@ -69,13 +79,13 @@ devm_request_threaded_irq@p(dev, irq, NULL, thread_fn,
 )
 
 @depends on context@
-position p != r1.p;
+position p != {r1.p,r2.p};
 @@
 *request_threaded_irq@p(...)
 
 @match depends on report || org@
 expression irq;
-position p != r1.p;
+position p != {r1.p,r2.p};
 @@
 request_threaded_irq@p(irq, NULL, ...)
 
-- 
2.1.4



[PATCH v4 0/3] Coccinelle: misc: Improve the script for more accurate results

2016-11-23 Thread Vaishali Thakkar
Few changes to improve the results given by the irqf_oneshot.cocci:

- Change in the matching rules to eliminate false postives in the
  patch mode
- Change in the context mode to eliminate false postives in the
  context mode
- Support for the missing devm_request_threaded_irq in context, report
  and org mode

Changes since v3:
- Few more changes in the script to avoid some
  possible false positives
- Moved initialization of all expressions in a single line 
Changes since v2:
- Add missing initialization of metavariables
Changes since v1:
- Split patch in to the patchset

Vaishali Thakkar (3):
  Coccinelle: misc: Improve the matching of rules
  Coccinelle: misc: Improve the result given by context mode
  Coccinelle: misc: Add support for devm variant in all modes

 scripts/coccinelle/misc/irqf_oneshot.cocci | 52 +-
 1 file changed, 36 insertions(+), 16 deletions(-)

-- 
2.1.4



[PATCH v4 0/3] Coccinelle: misc: Improve the script for more accurate results

2016-11-23 Thread Vaishali Thakkar
Few changes to improve the results given by the irqf_oneshot.cocci:

- Change in the matching rules to eliminate false postives in the
  patch mode
- Change in the context mode to eliminate false postives in the
  context mode
- Support for the missing devm_request_threaded_irq in context, report
  and org mode

Changes since v3:
- Few more changes in the script to avoid some
  possible false positives
- Moved initialization of all expressions in a single line 
Changes since v2:
- Add missing initialization of metavariables
Changes since v1:
- Split patch in to the patchset

Vaishali Thakkar (3):
  Coccinelle: misc: Improve the matching of rules
  Coccinelle: misc: Improve the result given by context mode
  Coccinelle: misc: Add support for devm variant in all modes

 scripts/coccinelle/misc/irqf_oneshot.cocci | 52 +-
 1 file changed, 36 insertions(+), 16 deletions(-)

-- 
2.1.4



[PATCH v4 2/3] Coccinelle: misc: Improve the result given by context mode

2016-11-23 Thread Vaishali Thakkar
To eliminate false positives given by the context mode, add
necessary arguments for the function request_threaded_irq.

Signed-off-by: Vaishali Thakkar <vaishali.thak...@oracle.com>
Acked-by: Julia Lawall <julia.law...@lip6.fr>
---
Changes since v3:
- No changes in this patch
Changes since v2:
- Add missing declaration of metavariable irq
Changes since v1:
- Split patch in to the patch set
---
 scripts/coccinelle/misc/irqf_oneshot.cocci | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/scripts/coccinelle/misc/irqf_oneshot.cocci 
b/scripts/coccinelle/misc/irqf_oneshot.cocci
index bd3e140..cec3672 100644
--- a/scripts/coccinelle/misc/irqf_oneshot.cocci
+++ b/scripts/coccinelle/misc/irqf_oneshot.cocci
@@ -79,9 +79,10 @@ devm_request_threaded_irq@p(dev, irq, NULL, thread_fn,
 )
 
 @depends on context@
+expression irq;
 position p != {r1.p,r2.p};
 @@
-*request_threaded_irq@p(...)
+*request_threaded_irq@p(irq, NULL, ...)
 
 @match depends on report || org@
 expression irq;
-- 
2.1.4



[PATCH v4 2/3] Coccinelle: misc: Improve the result given by context mode

2016-11-23 Thread Vaishali Thakkar
To eliminate false positives given by the context mode, add
necessary arguments for the function request_threaded_irq.

Signed-off-by: Vaishali Thakkar 
Acked-by: Julia Lawall 
---
Changes since v3:
- No changes in this patch
Changes since v2:
- Add missing declaration of metavariable irq
Changes since v1:
- Split patch in to the patch set
---
 scripts/coccinelle/misc/irqf_oneshot.cocci | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/scripts/coccinelle/misc/irqf_oneshot.cocci 
b/scripts/coccinelle/misc/irqf_oneshot.cocci
index bd3e140..cec3672 100644
--- a/scripts/coccinelle/misc/irqf_oneshot.cocci
+++ b/scripts/coccinelle/misc/irqf_oneshot.cocci
@@ -79,9 +79,10 @@ devm_request_threaded_irq@p(dev, irq, NULL, thread_fn,
 )
 
 @depends on context@
+expression irq;
 position p != {r1.p,r2.p};
 @@
-*request_threaded_irq@p(...)
+*request_threaded_irq@p(irq, NULL, ...)
 
 @match depends on report || org@
 expression irq;
-- 
2.1.4



[PATCH v4 3/3] Coccinelle: misc: Add support for devm variant in all modes

2016-11-23 Thread Vaishali Thakkar
Add missing support for the devm_request_threaded_irq in
the rules of context, report and org modes.

Misc:

To be consistent with other scripts, change confidence level
of the script to 'Moderate'.

Signed-off-by: Vaishali Thakkar <vaishali.thak...@oracle.com>
Acked-by: Julia Lawall <julia.law...@lip6.fr>
---
Changes since v3:
- No changes in this patch
Changes since v2:
- Add missing initialization of metavariables
Changes since v1:
- Split patch in to the patchset
---
 scripts/coccinelle/misc/irqf_oneshot.cocci | 15 ---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/scripts/coccinelle/misc/irqf_oneshot.cocci 
b/scripts/coccinelle/misc/irqf_oneshot.cocci
index cec3672..58c2578 100644
--- a/scripts/coccinelle/misc/irqf_oneshot.cocci
+++ b/scripts/coccinelle/misc/irqf_oneshot.cocci
@@ -5,7 +5,7 @@
 /// So pass the IRQF_ONESHOT flag in this case.
 ///
 //
-// Confidence: Good
+// Confidence: Moderate
 // Comments:
 // Options: --no-includes
 
@@ -79,16 +79,25 @@ devm_request_threaded_irq@p(dev, irq, NULL, thread_fn,
 )
 
 @depends on context@
-expression irq;
+expression dev, irq;
 position p != {r1.p,r2.p};
 @@
+(
 *request_threaded_irq@p(irq, NULL, ...)
+|
+*devm_request_threaded_irq@p(dev, irq, NULL, ...)
+)
+
 
 @match depends on report || org@
-expression irq;
+expression dev, irq;
 position p != {r1.p,r2.p};
 @@
+(
 request_threaded_irq@p(irq, NULL, ...)
+|
+devm_request_threaded_irq@p(dev, irq, NULL, ...)
+)
 
 @script:python depends on org@
 p << match.p;
-- 
2.1.4



[PATCH v4 3/3] Coccinelle: misc: Add support for devm variant in all modes

2016-11-23 Thread Vaishali Thakkar
Add missing support for the devm_request_threaded_irq in
the rules of context, report and org modes.

Misc:

To be consistent with other scripts, change confidence level
of the script to 'Moderate'.

Signed-off-by: Vaishali Thakkar 
Acked-by: Julia Lawall 
---
Changes since v3:
- No changes in this patch
Changes since v2:
- Add missing initialization of metavariables
Changes since v1:
- Split patch in to the patchset
---
 scripts/coccinelle/misc/irqf_oneshot.cocci | 15 ---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/scripts/coccinelle/misc/irqf_oneshot.cocci 
b/scripts/coccinelle/misc/irqf_oneshot.cocci
index cec3672..58c2578 100644
--- a/scripts/coccinelle/misc/irqf_oneshot.cocci
+++ b/scripts/coccinelle/misc/irqf_oneshot.cocci
@@ -5,7 +5,7 @@
 /// So pass the IRQF_ONESHOT flag in this case.
 ///
 //
-// Confidence: Good
+// Confidence: Moderate
 // Comments:
 // Options: --no-includes
 
@@ -79,16 +79,25 @@ devm_request_threaded_irq@p(dev, irq, NULL, thread_fn,
 )
 
 @depends on context@
-expression irq;
+expression dev, irq;
 position p != {r1.p,r2.p};
 @@
+(
 *request_threaded_irq@p(irq, NULL, ...)
+|
+*devm_request_threaded_irq@p(dev, irq, NULL, ...)
+)
+
 
 @match depends on report || org@
-expression irq;
+expression dev, irq;
 position p != {r1.p,r2.p};
 @@
+(
 request_threaded_irq@p(irq, NULL, ...)
+|
+devm_request_threaded_irq@p(dev, irq, NULL, ...)
+)
 
 @script:python depends on org@
 p << match.p;
-- 
2.1.4



Re: [PATCH v3 1/3] Coccinelle: misc: Improve the matching of rules

2016-11-18 Thread Vaishali Thakkar


On Saturday 12 November 2016 11:36 PM, Julia Lawall wrote:
> 
> 
> On Mon, 24 Oct 2016, Vaishali Thakkar wrote:
> 
>> Currently because of the left associativity of the operators, pattern
>> IRQF_ONESHOT | flags does not match with the pattern when we have more
>> than one flag after the disjunction. This eventually results in giving
>> false positives by the script. This patch eliminates these FPs by
>> improving the rule.
>>
>> Signed-off-by: Vaishali Thakkar <vaishali.thak...@oracle.com>
>> ---
>> Changes since v2:
>>  - No change in this patch
>> Changes since v1:
>>  - Splitted patch in the patchset
>> ---
>>  scripts/coccinelle/misc/irqf_oneshot.cocci | 30 
>> --
>>  1 file changed, 24 insertions(+), 6 deletions(-)
>>
>> diff --git a/scripts/coccinelle/misc/irqf_oneshot.cocci 
>> b/scripts/coccinelle/misc/irqf_oneshot.cocci
>> index b421150..a8537fb 100644
>> --- a/scripts/coccinelle/misc/irqf_oneshot.cocci
>> +++ b/scripts/coccinelle/misc/irqf_oneshot.cocci
>> @@ -18,13 +18,12 @@ virtual report
>>  expression dev;
>>  expression irq;
>>  expression thread_fn;
>> -expression flags;
>>  position p;
>>  @@
>>  (
>>  request_threaded_irq@p(irq, NULL, thread_fn,
>>  (
>> -flags | IRQF_ONESHOT
>> +IRQF_ONESHOT | ...
>>  |
>>  IRQF_ONESHOT
>>  )
>> @@ -32,20 +31,39 @@ IRQF_ONESHOT
>>  |
>>  devm_request_threaded_irq@p(dev, irq, NULL, thread_fn,
>>  (
>> -flags | IRQF_ONESHOT
>> +IRQF_ONESHOT | ...
>>  |
>>  IRQF_ONESHOT
>>  )
>>  , ...)
>>  )
>>
>> -@depends on patch@
>> +@r2@
>>  expression dev;
>>  expression irq;
>>  expression thread_fn;
>>  expression flags;
>> +expression ret;
>>  position p != r1.p;
>>  @@
>> +flags = IRQF_ONESHOT | ...;
>> +(
>> +ret = request_threaded_irq@p(irq, NULL, thread_fn, flags, ...);
>> +|
>> +ret = devm_request_threaded_irq@p(dev, irq, NULL, thread_fn, flags, ...);
>> +|
>> +return request_threaded_irq@p(irq, NULL, thread_fn, flags, ...);
>> +|
>> +return devm_request_threaded_irq@p(dev, irq, NULL, thread_fn, flags, ...);
>> +)
> 
> This rule needs some improvement.
> 
> flags = IRQF_ONESHOT | ...;
> 
> should be replaced by:
> 
> (
> flags = IRQF_ONESHOT | ...
> |
> flags |= IRQF_ONESHOT | ...
> )
> ... when != flags = e
> 
> where e should be a new expression metavariable.  This effects a number of
> changes.  1) Dropping the ; after the assignment allows an isomorphism to
> trigger that allows it to match a variable declaration as well, 2)
> IRQF_ONESHOT can be added after the original initialization by a |=, 3)
> there can be some instructions between the initialization of flags and the
> use.

Ok, this makes sense.

> Afterwards, the big disjunction with the irq calls is too specific.
> In particular, these calls can also occur in an if test.  The disjunction
> should be replaced by the following:
> 
> (
> request_threaded_irq@p(irq, NULL, thread_fn, flags, ...)
> |
> devm_request_threaded_irq@p(dev, irq, NULL, thread_fn, flags, ...)
> )

Ok, primary motivation with having specified pattern was to have less
running time. But as discussed, it doesn't make much difference. So,
going with the more general way sounds good. 

Thanks for the suggestions. I'll send the the revised version with these
changes.

> julia
> 
> 
>> +
>> +@depends on patch@
>> +expression dev;
>> +expression irq;
>> +expression thread_fn;
>> +expression flags;
>> +position p != {r1.p,r2.p};
>> +@@
>>  (
>>  request_threaded_irq@p(irq, NULL, thread_fn,
>>  (
>> @@ -69,13 +87,13 @@ devm_request_threaded_irq@p(dev, irq, NULL, thread_fn,
>>  )
>>
>>  @depends on context@
>> -position p != r1.p;
>> +position p != {r1.p,r2.p};
>>  @@
>>  *request_threaded_irq@p(...)
>>
>>  @match depends on report || org@
>>  expression irq;
>> -position p != r1.p;
>> +position p != {r1.p,r2.p};
>>  @@
>>  request_threaded_irq@p(irq, NULL, ...)
>>
>> --
>> 2.1.4
>>
>>

-- 
Vaishali


Re: [PATCH v3 1/3] Coccinelle: misc: Improve the matching of rules

2016-11-18 Thread Vaishali Thakkar


On Saturday 12 November 2016 11:36 PM, Julia Lawall wrote:
> 
> 
> On Mon, 24 Oct 2016, Vaishali Thakkar wrote:
> 
>> Currently because of the left associativity of the operators, pattern
>> IRQF_ONESHOT | flags does not match with the pattern when we have more
>> than one flag after the disjunction. This eventually results in giving
>> false positives by the script. This patch eliminates these FPs by
>> improving the rule.
>>
>> Signed-off-by: Vaishali Thakkar 
>> ---
>> Changes since v2:
>>  - No change in this patch
>> Changes since v1:
>>  - Splitted patch in the patchset
>> ---
>>  scripts/coccinelle/misc/irqf_oneshot.cocci | 30 
>> --
>>  1 file changed, 24 insertions(+), 6 deletions(-)
>>
>> diff --git a/scripts/coccinelle/misc/irqf_oneshot.cocci 
>> b/scripts/coccinelle/misc/irqf_oneshot.cocci
>> index b421150..a8537fb 100644
>> --- a/scripts/coccinelle/misc/irqf_oneshot.cocci
>> +++ b/scripts/coccinelle/misc/irqf_oneshot.cocci
>> @@ -18,13 +18,12 @@ virtual report
>>  expression dev;
>>  expression irq;
>>  expression thread_fn;
>> -expression flags;
>>  position p;
>>  @@
>>  (
>>  request_threaded_irq@p(irq, NULL, thread_fn,
>>  (
>> -flags | IRQF_ONESHOT
>> +IRQF_ONESHOT | ...
>>  |
>>  IRQF_ONESHOT
>>  )
>> @@ -32,20 +31,39 @@ IRQF_ONESHOT
>>  |
>>  devm_request_threaded_irq@p(dev, irq, NULL, thread_fn,
>>  (
>> -flags | IRQF_ONESHOT
>> +IRQF_ONESHOT | ...
>>  |
>>  IRQF_ONESHOT
>>  )
>>  , ...)
>>  )
>>
>> -@depends on patch@
>> +@r2@
>>  expression dev;
>>  expression irq;
>>  expression thread_fn;
>>  expression flags;
>> +expression ret;
>>  position p != r1.p;
>>  @@
>> +flags = IRQF_ONESHOT | ...;
>> +(
>> +ret = request_threaded_irq@p(irq, NULL, thread_fn, flags, ...);
>> +|
>> +ret = devm_request_threaded_irq@p(dev, irq, NULL, thread_fn, flags, ...);
>> +|
>> +return request_threaded_irq@p(irq, NULL, thread_fn, flags, ...);
>> +|
>> +return devm_request_threaded_irq@p(dev, irq, NULL, thread_fn, flags, ...);
>> +)
> 
> This rule needs some improvement.
> 
> flags = IRQF_ONESHOT | ...;
> 
> should be replaced by:
> 
> (
> flags = IRQF_ONESHOT | ...
> |
> flags |= IRQF_ONESHOT | ...
> )
> ... when != flags = e
> 
> where e should be a new expression metavariable.  This effects a number of
> changes.  1) Dropping the ; after the assignment allows an isomorphism to
> trigger that allows it to match a variable declaration as well, 2)
> IRQF_ONESHOT can be added after the original initialization by a |=, 3)
> there can be some instructions between the initialization of flags and the
> use.

Ok, this makes sense.

> Afterwards, the big disjunction with the irq calls is too specific.
> In particular, these calls can also occur in an if test.  The disjunction
> should be replaced by the following:
> 
> (
> request_threaded_irq@p(irq, NULL, thread_fn, flags, ...)
> |
> devm_request_threaded_irq@p(dev, irq, NULL, thread_fn, flags, ...)
> )

Ok, primary motivation with having specified pattern was to have less
running time. But as discussed, it doesn't make much difference. So,
going with the more general way sounds good. 

Thanks for the suggestions. I'll send the the revised version with these
changes.

> julia
> 
> 
>> +
>> +@depends on patch@
>> +expression dev;
>> +expression irq;
>> +expression thread_fn;
>> +expression flags;
>> +position p != {r1.p,r2.p};
>> +@@
>>  (
>>  request_threaded_irq@p(irq, NULL, thread_fn,
>>  (
>> @@ -69,13 +87,13 @@ devm_request_threaded_irq@p(dev, irq, NULL, thread_fn,
>>  )
>>
>>  @depends on context@
>> -position p != r1.p;
>> +position p != {r1.p,r2.p};
>>  @@
>>  *request_threaded_irq@p(...)
>>
>>  @match depends on report || org@
>>  expression irq;
>> -position p != r1.p;
>> +position p != {r1.p,r2.p};
>>  @@
>>  request_threaded_irq@p(irq, NULL, ...)
>>
>> --
>> 2.1.4
>>
>>

-- 
Vaishali


Re: Failing of the script get_maintainer.pl

2016-11-02 Thread Vaishali Thakkar


On Wednesday 02 November 2016 10:28 PM, Joe Perches wrote:
> On Wed, 2016-11-02 at 22:07 +0530, Vaishali Thakkar wrote:
>> Hi,
>>
>> The script get_maintainer.pl fails with the following message/warning:
>>
>> Unrecognized character \xA0; marked by <-- HERE after <-- HERE near column 1 
>> at scripts/get_maintainer.pl line 277.
>>
>> This seems to be because of the commit 
>> b67071653d3fc9f9b73aab3e7978f060728bf392.
>>
>> Any idea about the solution(s)?
> 
> Unfortunately, Evolution is a horribly broken email client
> for sending patches.
> 
> It's been fixed at least in Andrew Morton's mm, and it
> should be in -next soonish.
> 
> You could do a sed until then:
> 
> $ sed -i -e "s/\xA0/ /g" scripts/get_maintainer.pl

Ok, makes sense. Thanks.

> 

-- 
Vaishali


Re: Failing of the script get_maintainer.pl

2016-11-02 Thread Vaishali Thakkar


On Wednesday 02 November 2016 10:28 PM, Joe Perches wrote:
> On Wed, 2016-11-02 at 22:07 +0530, Vaishali Thakkar wrote:
>> Hi,
>>
>> The script get_maintainer.pl fails with the following message/warning:
>>
>> Unrecognized character \xA0; marked by <-- HERE after <-- HERE near column 1 
>> at scripts/get_maintainer.pl line 277.
>>
>> This seems to be because of the commit 
>> b67071653d3fc9f9b73aab3e7978f060728bf392.
>>
>> Any idea about the solution(s)?
> 
> Unfortunately, Evolution is a horribly broken email client
> for sending patches.
> 
> It's been fixed at least in Andrew Morton's mm, and it
> should be in -next soonish.
> 
> You could do a sed until then:
> 
> $ sed -i -e "s/\xA0/ /g" scripts/get_maintainer.pl

Ok, makes sense. Thanks.

> 

-- 
Vaishali


Failing of the script get_maintainer.pl

2016-11-02 Thread Vaishali Thakkar
Hi,

The script get_maintainer.pl fails with the following message/warning:

Unrecognized character \xA0; marked by <-- HERE after <-- HERE near column 1 at 
scripts/get_maintainer.pl line 277.

This seems to be because of the commit b67071653d3fc9f9b73aab3e7978f060728bf392.

Any idea about the solution(s)?

Thank you.


-- 
Vaishali


Failing of the script get_maintainer.pl

2016-11-02 Thread Vaishali Thakkar
Hi,

The script get_maintainer.pl fails with the following message/warning:

Unrecognized character \xA0; marked by <-- HERE after <-- HERE near column 1 at 
scripts/get_maintainer.pl line 277.

This seems to be because of the commit b67071653d3fc9f9b73aab3e7978f060728bf392.

Any idea about the solution(s)?

Thank you.


-- 
Vaishali


[PATCH v3 1/3] Coccinelle: misc: Improve the matching of rules

2016-10-24 Thread Vaishali Thakkar
Currently because of the left associativity of the operators, pattern
IRQF_ONESHOT | flags does not match with the pattern when we have more
than one flag after the disjunction. This eventually results in giving
false positives by the script. This patch eliminates these FPs by
improving the rule.

Signed-off-by: Vaishali Thakkar <vaishali.thak...@oracle.com>
---
Changes since v2:
- No change in this patch
Changes since v1:
- Splitted patch in the patchset
---
 scripts/coccinelle/misc/irqf_oneshot.cocci | 30 --
 1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/scripts/coccinelle/misc/irqf_oneshot.cocci 
b/scripts/coccinelle/misc/irqf_oneshot.cocci
index b421150..a8537fb 100644
--- a/scripts/coccinelle/misc/irqf_oneshot.cocci
+++ b/scripts/coccinelle/misc/irqf_oneshot.cocci
@@ -18,13 +18,12 @@ virtual report
 expression dev;
 expression irq;
 expression thread_fn;
-expression flags;
 position p;
 @@
 (
 request_threaded_irq@p(irq, NULL, thread_fn,
 (
-flags | IRQF_ONESHOT
+IRQF_ONESHOT | ...
 |
 IRQF_ONESHOT
 )
@@ -32,20 +31,39 @@ IRQF_ONESHOT
 |
 devm_request_threaded_irq@p(dev, irq, NULL, thread_fn,
 (
-flags | IRQF_ONESHOT
+IRQF_ONESHOT | ...
 |
 IRQF_ONESHOT
 )
 , ...)
 )
 
-@depends on patch@
+@r2@
 expression dev;
 expression irq;
 expression thread_fn;
 expression flags;
+expression ret;
 position p != r1.p;
 @@
+flags = IRQF_ONESHOT | ...;
+(
+ret = request_threaded_irq@p(irq, NULL, thread_fn, flags, ...);
+|
+ret = devm_request_threaded_irq@p(dev, irq, NULL, thread_fn, flags, ...);
+|
+return request_threaded_irq@p(irq, NULL, thread_fn, flags, ...);
+|
+return devm_request_threaded_irq@p(dev, irq, NULL, thread_fn, flags, ...);
+)
+
+@depends on patch@
+expression dev;
+expression irq;
+expression thread_fn;
+expression flags;
+position p != {r1.p,r2.p};
+@@
 (
 request_threaded_irq@p(irq, NULL, thread_fn,
 (
@@ -69,13 +87,13 @@ devm_request_threaded_irq@p(dev, irq, NULL, thread_fn,
 )
 
 @depends on context@
-position p != r1.p;
+position p != {r1.p,r2.p};
 @@
 *request_threaded_irq@p(...)
 
 @match depends on report || org@
 expression irq;
-position p != r1.p;
+position p != {r1.p,r2.p};
 @@
 request_threaded_irq@p(irq, NULL, ...)
 
-- 
2.1.4



[PATCH v3 1/3] Coccinelle: misc: Improve the matching of rules

2016-10-24 Thread Vaishali Thakkar
Currently because of the left associativity of the operators, pattern
IRQF_ONESHOT | flags does not match with the pattern when we have more
than one flag after the disjunction. This eventually results in giving
false positives by the script. This patch eliminates these FPs by
improving the rule.

Signed-off-by: Vaishali Thakkar 
---
Changes since v2:
- No change in this patch
Changes since v1:
- Splitted patch in the patchset
---
 scripts/coccinelle/misc/irqf_oneshot.cocci | 30 --
 1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/scripts/coccinelle/misc/irqf_oneshot.cocci 
b/scripts/coccinelle/misc/irqf_oneshot.cocci
index b421150..a8537fb 100644
--- a/scripts/coccinelle/misc/irqf_oneshot.cocci
+++ b/scripts/coccinelle/misc/irqf_oneshot.cocci
@@ -18,13 +18,12 @@ virtual report
 expression dev;
 expression irq;
 expression thread_fn;
-expression flags;
 position p;
 @@
 (
 request_threaded_irq@p(irq, NULL, thread_fn,
 (
-flags | IRQF_ONESHOT
+IRQF_ONESHOT | ...
 |
 IRQF_ONESHOT
 )
@@ -32,20 +31,39 @@ IRQF_ONESHOT
 |
 devm_request_threaded_irq@p(dev, irq, NULL, thread_fn,
 (
-flags | IRQF_ONESHOT
+IRQF_ONESHOT | ...
 |
 IRQF_ONESHOT
 )
 , ...)
 )
 
-@depends on patch@
+@r2@
 expression dev;
 expression irq;
 expression thread_fn;
 expression flags;
+expression ret;
 position p != r1.p;
 @@
+flags = IRQF_ONESHOT | ...;
+(
+ret = request_threaded_irq@p(irq, NULL, thread_fn, flags, ...);
+|
+ret = devm_request_threaded_irq@p(dev, irq, NULL, thread_fn, flags, ...);
+|
+return request_threaded_irq@p(irq, NULL, thread_fn, flags, ...);
+|
+return devm_request_threaded_irq@p(dev, irq, NULL, thread_fn, flags, ...);
+)
+
+@depends on patch@
+expression dev;
+expression irq;
+expression thread_fn;
+expression flags;
+position p != {r1.p,r2.p};
+@@
 (
 request_threaded_irq@p(irq, NULL, thread_fn,
 (
@@ -69,13 +87,13 @@ devm_request_threaded_irq@p(dev, irq, NULL, thread_fn,
 )
 
 @depends on context@
-position p != r1.p;
+position p != {r1.p,r2.p};
 @@
 *request_threaded_irq@p(...)
 
 @match depends on report || org@
 expression irq;
-position p != r1.p;
+position p != {r1.p,r2.p};
 @@
 request_threaded_irq@p(irq, NULL, ...)
 
-- 
2.1.4



[PATCH v3 3/3] Coccinelle: misc: Add support for devm variant in all modes

2016-10-24 Thread Vaishali Thakkar
Add missing support for the devm_request_threaded_irq in
the rules of context, report and org modes.

Misc:

To be consistent with other scripts, change confidence level
of the script to 'Moderate'.

Signed-off-by: Vaishali Thakkar <vaishali.thak...@oracle.com>
---
Changes since v2:
- Add missing initialization of metavariables
Changes since v1:
- Split patch in to the patchset
---
 scripts/coccinelle/misc/irqf_oneshot.cocci | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/scripts/coccinelle/misc/irqf_oneshot.cocci 
b/scripts/coccinelle/misc/irqf_oneshot.cocci
index e53372e..ca78125 100644
--- a/scripts/coccinelle/misc/irqf_oneshot.cocci
+++ b/scripts/coccinelle/misc/irqf_oneshot.cocci
@@ -5,7 +5,7 @@
 /// So pass the IRQF_ONESHOT flag in this case.
 ///
 //
-// Confidence: Good
+// Confidence: Moderate
 // Comments:
 // Options: --no-includes
 
@@ -87,16 +87,26 @@ devm_request_threaded_irq@p(dev, irq, NULL, thread_fn,
 )
 
 @depends on context@
+expression dev;
 expression irq;
 position p != {r1.p,r2.p};
 @@
+(
 *request_threaded_irq@p(irq, NULL, ...)
+|
+*devm_request_threaded_irq@p(dev, irq, NULL, ...)
+)
 
 @match depends on report || org@
+expression dev;
 expression irq;
 position p != {r1.p,r2.p};
 @@
+(
 request_threaded_irq@p(irq, NULL, ...)
+|
+devm_request_threaded_irq@p(dev, irq, NULL, ...)
+)
 
 @script:python depends on org@
 p << match.p;
-- 
2.1.4



[PATCH v3 3/3] Coccinelle: misc: Add support for devm variant in all modes

2016-10-24 Thread Vaishali Thakkar
Add missing support for the devm_request_threaded_irq in
the rules of context, report and org modes.

Misc:

To be consistent with other scripts, change confidence level
of the script to 'Moderate'.

Signed-off-by: Vaishali Thakkar 
---
Changes since v2:
- Add missing initialization of metavariables
Changes since v1:
- Split patch in to the patchset
---
 scripts/coccinelle/misc/irqf_oneshot.cocci | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/scripts/coccinelle/misc/irqf_oneshot.cocci 
b/scripts/coccinelle/misc/irqf_oneshot.cocci
index e53372e..ca78125 100644
--- a/scripts/coccinelle/misc/irqf_oneshot.cocci
+++ b/scripts/coccinelle/misc/irqf_oneshot.cocci
@@ -5,7 +5,7 @@
 /// So pass the IRQF_ONESHOT flag in this case.
 ///
 //
-// Confidence: Good
+// Confidence: Moderate
 // Comments:
 // Options: --no-includes
 
@@ -87,16 +87,26 @@ devm_request_threaded_irq@p(dev, irq, NULL, thread_fn,
 )
 
 @depends on context@
+expression dev;
 expression irq;
 position p != {r1.p,r2.p};
 @@
+(
 *request_threaded_irq@p(irq, NULL, ...)
+|
+*devm_request_threaded_irq@p(dev, irq, NULL, ...)
+)
 
 @match depends on report || org@
+expression dev;
 expression irq;
 position p != {r1.p,r2.p};
 @@
+(
 request_threaded_irq@p(irq, NULL, ...)
+|
+devm_request_threaded_irq@p(dev, irq, NULL, ...)
+)
 
 @script:python depends on org@
 p << match.p;
-- 
2.1.4



[PATCH v3 2/3] Coccinelle: misc: Improve the result given by context mode

2016-10-24 Thread Vaishali Thakkar
To eliminate false positives given by the context mode, add
necessary arguments for the function request_threaded_irq.

Signed-off-by: Vaishali Thakkar <vaishali.thak...@oracle.com>
---
Changes since v2:
- Add missing declaration of metavariable irq
Changes since v1:
- Split patch in to the patch set
---
 scripts/coccinelle/misc/irqf_oneshot.cocci | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/scripts/coccinelle/misc/irqf_oneshot.cocci 
b/scripts/coccinelle/misc/irqf_oneshot.cocci
index a8537fb..e53372e 100644
--- a/scripts/coccinelle/misc/irqf_oneshot.cocci
+++ b/scripts/coccinelle/misc/irqf_oneshot.cocci
@@ -87,9 +87,10 @@ devm_request_threaded_irq@p(dev, irq, NULL, thread_fn,
 )
 
 @depends on context@
+expression irq;
 position p != {r1.p,r2.p};
 @@
-*request_threaded_irq@p(...)
+*request_threaded_irq@p(irq, NULL, ...)
 
 @match depends on report || org@
 expression irq;
-- 
2.1.4



[PATCH v3 2/3] Coccinelle: misc: Improve the result given by context mode

2016-10-24 Thread Vaishali Thakkar
To eliminate false positives given by the context mode, add
necessary arguments for the function request_threaded_irq.

Signed-off-by: Vaishali Thakkar 
---
Changes since v2:
- Add missing declaration of metavariable irq
Changes since v1:
- Split patch in to the patch set
---
 scripts/coccinelle/misc/irqf_oneshot.cocci | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/scripts/coccinelle/misc/irqf_oneshot.cocci 
b/scripts/coccinelle/misc/irqf_oneshot.cocci
index a8537fb..e53372e 100644
--- a/scripts/coccinelle/misc/irqf_oneshot.cocci
+++ b/scripts/coccinelle/misc/irqf_oneshot.cocci
@@ -87,9 +87,10 @@ devm_request_threaded_irq@p(dev, irq, NULL, thread_fn,
 )
 
 @depends on context@
+expression irq;
 position p != {r1.p,r2.p};
 @@
-*request_threaded_irq@p(...)
+*request_threaded_irq@p(irq, NULL, ...)
 
 @match depends on report || org@
 expression irq;
-- 
2.1.4



[PATCH v3 0/3] Coccinelle: misc: Improve the script for more accurate results

2016-10-24 Thread Vaishali Thakkar
Few changes to improve the results given by the irqf_oneshot.cocci:

- Change in the matching rules to eliminate false postives in the
  patch mode
- Change in the context mode to eliminate false postives in the
  context mode
- Support for the missing devm_request_threaded_irq in context, report
  and org mode

Changes since v2:
- Add missing initialization of metavariables
Changes since v1:
- Split patch in to the patchset

Vaishali Thakkar (3):
  Coccinelle: misc: Improve the matching of rules
  Coccinelle: misc: Improve the result given by context mode
  Coccinelle: misc: Add support for devm variant in all modes

 scripts/coccinelle/misc/irqf_oneshot.cocci | 45 --
 1 file changed, 37 insertions(+), 8 deletions(-)

-- 
2.1.4



[PATCH v3 0/3] Coccinelle: misc: Improve the script for more accurate results

2016-10-24 Thread Vaishali Thakkar
Few changes to improve the results given by the irqf_oneshot.cocci:

- Change in the matching rules to eliminate false postives in the
  patch mode
- Change in the context mode to eliminate false postives in the
  context mode
- Support for the missing devm_request_threaded_irq in context, report
  and org mode

Changes since v2:
- Add missing initialization of metavariables
Changes since v1:
- Split patch in to the patchset

Vaishali Thakkar (3):
  Coccinelle: misc: Improve the matching of rules
  Coccinelle: misc: Improve the result given by context mode
  Coccinelle: misc: Add support for devm variant in all modes

 scripts/coccinelle/misc/irqf_oneshot.cocci | 45 --
 1 file changed, 37 insertions(+), 8 deletions(-)

-- 
2.1.4



Re: [PATCH v2 3/3] Coccinelle: misc: Add support for devm variant in all modes

2016-10-18 Thread Vaishali Thakkar


On Tuesday 18 October 2016 10:40 PM, Julia Lawall wrote:
> 
> 
> On Tue, 18 Oct 2016, Vaishali Thakkar wrote:
> 
>>
>>
>> On Sunday 16 October 2016 10:37 PM, Vaishali Thakkar wrote:
>>> Add missing support for the devm_request_threaded_irq in
>>> the rules of context, report and org modes.
>>>
>>> Misc:
>>> 
>>> To be consistent with other scripts, change confidence level
>>> of the script to 'Moderate'.
>>>
>>> Signed-off-by: Vaishali Thakkar <vaishali.thak...@oracle.com>
>>> ---
>>>  scripts/coccinelle/misc/irqf_oneshot.cocci | 10 +-
>>>  1 file changed, 9 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/scripts/coccinelle/misc/irqf_oneshot.cocci 
>>> b/scripts/coccinelle/misc/irqf_oneshot.cocci
>>> index 03b748d..f6c93fd 100644
>>> --- a/scripts/coccinelle/misc/irqf_oneshot.cocci
>>> +++ b/scripts/coccinelle/misc/irqf_oneshot.cocci
>>> @@ -5,7 +5,7 @@
>>>  /// So pass the IRQF_ONESHOT flag in this case.
>>>  ///
>>>  //
>>> -// Confidence: Good
>>> +// Confidence: Moderate
>>>  // Comments:
>>>  // Options: --no-includes
>>>
>>> @@ -89,13 +89,21 @@ devm_request_threaded_irq@p(dev, irq, NULL, thread_fn,
>>>  @depends on context@
>>>  position p != {r1.p,r2.p};
>>>  @@
>>> +(
>>>  *request_threaded_irq@p(irq, NULL, ...)
>>> +|
>>> +*devm_request_threaded_irq@p(dev, irq, NULL, ...)
>>> +)
>>>
>>>  @match depends on report || org@
>>>  expression irq;
>>>  position p != {r1.p,r2.p};
>>>  @@
>>> +(
>>>  request_threaded_irq@p(irq, NULL, ...)
>>> +|
>>> +devm_request_threaded_irq@p(dev, irq, NULL, ...)
>>> +)
>>
>> Oh, my bad here. :(
>>
>> Forgot the initialization of meta variables for the
>> arguments.
>>
>> But I am wondering why coccicheck didn't fail here.
>> Isn't it suppose to give parsing errors? Or it doesn't
>> do that?
> 
> It just give a warning, which I guess make coccicheck hides.  It is
> allowed to require an argument to be named dev, although it is nicer if
> one declares it with symbol in that case.

Ah, ok. The results were based on the names 'irq, dev etc', not on the
assumption for metavariables.
 
> julia
> 
>>
>> In any case, I am sorry for this. I'll send the revised
>> version of the patches.
>>
>>>  @script:python depends on org@
>>>  p << match.p;
>>>
>>
>> --
>> Vaishali
>>

-- 
Vaishali


Re: [PATCH v2 3/3] Coccinelle: misc: Add support for devm variant in all modes

2016-10-18 Thread Vaishali Thakkar


On Tuesday 18 October 2016 10:40 PM, Julia Lawall wrote:
> 
> 
> On Tue, 18 Oct 2016, Vaishali Thakkar wrote:
> 
>>
>>
>> On Sunday 16 October 2016 10:37 PM, Vaishali Thakkar wrote:
>>> Add missing support for the devm_request_threaded_irq in
>>> the rules of context, report and org modes.
>>>
>>> Misc:
>>> 
>>> To be consistent with other scripts, change confidence level
>>> of the script to 'Moderate'.
>>>
>>> Signed-off-by: Vaishali Thakkar 
>>> ---
>>>  scripts/coccinelle/misc/irqf_oneshot.cocci | 10 +-
>>>  1 file changed, 9 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/scripts/coccinelle/misc/irqf_oneshot.cocci 
>>> b/scripts/coccinelle/misc/irqf_oneshot.cocci
>>> index 03b748d..f6c93fd 100644
>>> --- a/scripts/coccinelle/misc/irqf_oneshot.cocci
>>> +++ b/scripts/coccinelle/misc/irqf_oneshot.cocci
>>> @@ -5,7 +5,7 @@
>>>  /// So pass the IRQF_ONESHOT flag in this case.
>>>  ///
>>>  //
>>> -// Confidence: Good
>>> +// Confidence: Moderate
>>>  // Comments:
>>>  // Options: --no-includes
>>>
>>> @@ -89,13 +89,21 @@ devm_request_threaded_irq@p(dev, irq, NULL, thread_fn,
>>>  @depends on context@
>>>  position p != {r1.p,r2.p};
>>>  @@
>>> +(
>>>  *request_threaded_irq@p(irq, NULL, ...)
>>> +|
>>> +*devm_request_threaded_irq@p(dev, irq, NULL, ...)
>>> +)
>>>
>>>  @match depends on report || org@
>>>  expression irq;
>>>  position p != {r1.p,r2.p};
>>>  @@
>>> +(
>>>  request_threaded_irq@p(irq, NULL, ...)
>>> +|
>>> +devm_request_threaded_irq@p(dev, irq, NULL, ...)
>>> +)
>>
>> Oh, my bad here. :(
>>
>> Forgot the initialization of meta variables for the
>> arguments.
>>
>> But I am wondering why coccicheck didn't fail here.
>> Isn't it suppose to give parsing errors? Or it doesn't
>> do that?
> 
> It just give a warning, which I guess make coccicheck hides.  It is
> allowed to require an argument to be named dev, although it is nicer if
> one declares it with symbol in that case.

Ah, ok. The results were based on the names 'irq, dev etc', not on the
assumption for metavariables.
 
> julia
> 
>>
>> In any case, I am sorry for this. I'll send the revised
>> version of the patches.
>>
>>>  @script:python depends on org@
>>>  p << match.p;
>>>
>>
>> --
>> Vaishali
>>

-- 
Vaishali


Re: [PATCH v2 0/3] Coccinelle: misc: Improve the script for more accurate results

2016-10-18 Thread Vaishali Thakkar


On Tuesday 18 October 2016 10:31 PM, Julia Lawall wrote:
> 
> 
> On Tue, 18 Oct 2016, Vaishali Thakkar wrote:
> 
>>
>>
>> On Tuesday 18 October 2016 10:04 PM, Julia Lawall wrote:
>>> I get the following in patch mode that I don't get in context mode:
>>
>> Hi,
>>
>> Are you getting same number of devm cases in your report for the context
>> and patch mode? [except this case]
> 
> The only devm case I get in context mode is:
> 
> diff -u -p /var/linuxes/linux-next/drivers/acpi/evged.c
> /tmp/nothing/drivers/ac\
> pi/evged.c
> --- /var/linuxes/linux-next/drivers/acpi/evged.c
> +++ /tmp/nothing/drivers/acpi/evged.c
> @@ -116,8 +116,6 @@ static acpi_status acpi_ged_request_inte
> if (r.flags & IORESOURCE_IRQ_SHAREABLE)
> irqflags |= IRQF_SHARED;
> 
> -   if (devm_request_threaded_irq(dev, irq, NULL, acpi_ged_irq_handler,
> - irqflags, "ACPI:Ged", event)) {
> dev_err(dev, "failed to setup event handler for irq %u\n", 
> irq);
> return AE_ERROR;
> }
> 
> This one has the property that the first argument is an identifier.  The
> other cases seem to have a & expression.  There are around 20 of them.

Although I got the issue with the patches, I am wondering why even context mode
gave result for the identifiers even though they are not initialized? Does that
mean it automatically assumes the type of meta variables even though they are 
not
initialized? I think spatch gives warnings for such cases. But I am not sure 
about
the coccicheck.
 
> julia
> 
> 
> 
>>
>>
>>> diff -u -p a/drivers/power/supply/tps65090-charger.c
>>> b/drivers/power/supply/tps\
>>> 65090-charger.c
>>> --- a/drivers/power/supply/tps65090-charger.c
>>> +++ b/drivers/power/supply/tps65090-charger.c
>>> @@ -311,7 +311,8 @@ static int tps65090_charger_probe(struct
>>>
>>> if (irq != -ENXIO) {
>>> ret = devm_request_threaded_irq(>dev, irq, NULL,
>>> -   tps65090_charger_isr, 0, "tps65090-charger", cdata);
>>> +   tps65090_charger_isr, IRQF_ONESHOT,
>>> +   "tps65090-charger", cdata);
>>> if (ret) {
>>> dev_err(cdata->dev,
>>> "Unable to register irq %d err %d\n", irq,
>>>
>>>
>>> julia
>>>
>>
>> --
>> Vaishali
>>

-- 
Vaishali


Re: [PATCH v2 0/3] Coccinelle: misc: Improve the script for more accurate results

2016-10-18 Thread Vaishali Thakkar


On Tuesday 18 October 2016 10:31 PM, Julia Lawall wrote:
> 
> 
> On Tue, 18 Oct 2016, Vaishali Thakkar wrote:
> 
>>
>>
>> On Tuesday 18 October 2016 10:04 PM, Julia Lawall wrote:
>>> I get the following in patch mode that I don't get in context mode:
>>
>> Hi,
>>
>> Are you getting same number of devm cases in your report for the context
>> and patch mode? [except this case]
> 
> The only devm case I get in context mode is:
> 
> diff -u -p /var/linuxes/linux-next/drivers/acpi/evged.c
> /tmp/nothing/drivers/ac\
> pi/evged.c
> --- /var/linuxes/linux-next/drivers/acpi/evged.c
> +++ /tmp/nothing/drivers/acpi/evged.c
> @@ -116,8 +116,6 @@ static acpi_status acpi_ged_request_inte
> if (r.flags & IORESOURCE_IRQ_SHAREABLE)
> irqflags |= IRQF_SHARED;
> 
> -   if (devm_request_threaded_irq(dev, irq, NULL, acpi_ged_irq_handler,
> - irqflags, "ACPI:Ged", event)) {
> dev_err(dev, "failed to setup event handler for irq %u\n", 
> irq);
> return AE_ERROR;
> }
> 
> This one has the property that the first argument is an identifier.  The
> other cases seem to have a & expression.  There are around 20 of them.

Although I got the issue with the patches, I am wondering why even context mode
gave result for the identifiers even though they are not initialized? Does that
mean it automatically assumes the type of meta variables even though they are 
not
initialized? I think spatch gives warnings for such cases. But I am not sure 
about
the coccicheck.
 
> julia
> 
> 
> 
>>
>>
>>> diff -u -p a/drivers/power/supply/tps65090-charger.c
>>> b/drivers/power/supply/tps\
>>> 65090-charger.c
>>> --- a/drivers/power/supply/tps65090-charger.c
>>> +++ b/drivers/power/supply/tps65090-charger.c
>>> @@ -311,7 +311,8 @@ static int tps65090_charger_probe(struct
>>>
>>> if (irq != -ENXIO) {
>>> ret = devm_request_threaded_irq(>dev, irq, NULL,
>>> -   tps65090_charger_isr, 0, "tps65090-charger", cdata);
>>> +   tps65090_charger_isr, IRQF_ONESHOT,
>>> +   "tps65090-charger", cdata);
>>> if (ret) {
>>> dev_err(cdata->dev,
>>> "Unable to register irq %d err %d\n", irq,
>>>
>>>
>>> julia
>>>
>>
>> --
>> Vaishali
>>

-- 
Vaishali


Re: [PATCH v2 3/3] Coccinelle: misc: Add support for devm variant in all modes

2016-10-18 Thread Vaishali Thakkar


On Sunday 16 October 2016 10:37 PM, Vaishali Thakkar wrote:
> Add missing support for the devm_request_threaded_irq in
> the rules of context, report and org modes.
> 
> Misc:
> 
> To be consistent with other scripts, change confidence level
> of the script to 'Moderate'.
> 
> Signed-off-by: Vaishali Thakkar <vaishali.thak...@oracle.com>
> ---
>  scripts/coccinelle/misc/irqf_oneshot.cocci | 10 +-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/scripts/coccinelle/misc/irqf_oneshot.cocci 
> b/scripts/coccinelle/misc/irqf_oneshot.cocci
> index 03b748d..f6c93fd 100644
> --- a/scripts/coccinelle/misc/irqf_oneshot.cocci
> +++ b/scripts/coccinelle/misc/irqf_oneshot.cocci
> @@ -5,7 +5,7 @@
>  /// So pass the IRQF_ONESHOT flag in this case.
>  ///
>  //
> -// Confidence: Good
> +// Confidence: Moderate
>  // Comments:
>  // Options: --no-includes
>  
> @@ -89,13 +89,21 @@ devm_request_threaded_irq@p(dev, irq, NULL, thread_fn,
>  @depends on context@
>  position p != {r1.p,r2.p};
>  @@
> +(
>  *request_threaded_irq@p(irq, NULL, ...)
> +|
> +*devm_request_threaded_irq@p(dev, irq, NULL, ...)
> +)
>  
>  @match depends on report || org@
>  expression irq;
>  position p != {r1.p,r2.p};
>  @@
> +(
>  request_threaded_irq@p(irq, NULL, ...)
> +|
> +devm_request_threaded_irq@p(dev, irq, NULL, ...)
> +)

Oh, my bad here. :(

Forgot the initialization of meta variables for the
arguments.

But I am wondering why coccicheck didn't fail here.
Isn't it suppose to give parsing errors? Or it doesn't
do that?

In any case, I am sorry for this. I'll send the revised
version of the patches.
 
>  @script:python depends on org@
>  p << match.p;
> 

-- 
Vaishali


  1   2   3   4   5   6   >