Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp2781992ybh; Mon, 5 Aug 2019 06:45:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqx04PFEKuiaZbTPYy4lkb1lBBjiY9mN4lAeECnMmHPvjPXAvs0OQOpiRQ65clNID6xiSgbO X-Received: by 2002:a62:e315:: with SMTP id g21mr75287518pfh.225.1565012758817; Mon, 05 Aug 2019 06:45:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565012758; cv=none; d=google.com; s=arc-20160816; b=K230f+cSI+vtUgRcq+HR/CpAPA3bNP5PMXWi/nS71nC1a56osObE8p/gw5KDJu+17y VliDaPIpA1jeNaSu4ntgB4u1QEo1l/4IPxc4aKZt2vqAt/lg5fUUcFI77OYAOL9f6981 1LhTO7i2qryUmV7SdhTrgtzGIQimzBmrVC7FfYgdVvgDiP4Zw2qKiRQKPPdzAGPOQo4w tY1MLko9Ou/ArM0andDrv2O3qNUMaf9T5YaSPEkXHUzGSq+n3cnGvhGU0LSTuxxzkzOX j8AwC3TO2sGwQG8WfuMbGDzClCFb7+xtkAEYymhyvRJDECj4VfG+B8w5C9ZfWy6ooRLp /Oyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:subject:message-id:date:from:reply-to :mime-version; bh=x7VfJVP5+ruIimo+5ByaWNiBxT5h/IzipEGHY2tidNw=; b=kYHZo7Il3WbiBdEnsRiYSPuMTYkoPdsaDNS6T5pLZKKvNKNpVqqsMr41+9u5yGclP4 lC09sWCwieSAtYW9zOgy9fIOZpE3rkfPFXuORUWQBgK/FUKkG09R4a4c1kLIe41l9JtQ qBEiGx0ITeXfqc9YY5m9+JWarleinCszevMuBsYW7Kngx+8Xz5d8f87AJwzDTc5DhRA4 1c5aTetjNMOPfY2tk1PkLrXibBLvAcfJaVLLT4LFCjkpkTSOO4cvo5j+M/S0lfpb7hec Qbnzo/emmc+CX2rSMCaeftIYiTrY0cqsE5c80KvV2RqrYSh3JZk7uAABPZKdE1mwfYt8 WQGg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 69si2819618pgc.40.2019.08.05.06.45.42; Mon, 05 Aug 2019 06:45:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730895AbfHENoH (ORCPT + 99 others); Mon, 5 Aug 2019 09:44:07 -0400 Received: from mail-vs1-f52.google.com ([209.85.217.52]:33074 "EHLO mail-vs1-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730813AbfHENoG (ORCPT ); Mon, 5 Aug 2019 09:44:06 -0400 Received: by mail-vs1-f52.google.com with SMTP id m8so56034167vsj.0 for ; Mon, 05 Aug 2019 06:44:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:reply-to:from:date:message-id :subject:to; bh=x7VfJVP5+ruIimo+5ByaWNiBxT5h/IzipEGHY2tidNw=; b=nL+3qgsu2nmgOdxpOq24hvSzyv66zwoGkvCTdNZfqvkfZOXBqKiE8JFZRxB9BmFBEl 1TBKqPREJarfBb+W3EYQ+PPHnDQWfKeXjpj9Mg22wHrXxF0tpQPlL5Apy9pVcYBqN2aB 3PAU8cTMwpc9Khcqn/aaMUJIuYrhrLzPmhV+Ka14iHl5dMEHpBdgTcWu8p24xQEmHRwP Kiew64K0Ms1xpZ+2J3h+pHscQM6VdWC4sGyBsOpts27kjLG2EMt1wYR5eBO8sajnDrc3 fs02/9OH3zL4OeyWOPkEbjOwSlxq7GzVoVJhl/NNjH/dTB1rF8TzkpqQi1tw52fzVdOt 5qrA== X-Gm-Message-State: APjAAAU6cssGHllQ7nHjSQGGA+1JJ/MvrDcaFhNHf05HJcC+p8m2wP6T j0nnI+d4GLENhYjeUq2z8dHh7qlnjBM= X-Received: by 2002:a67:fc50:: with SMTP id p16mr96613267vsq.79.1565012645141; Mon, 05 Aug 2019 06:44:05 -0700 (PDT) Received: from mail-vs1-f52.google.com (mail-vs1-f52.google.com. [209.85.217.52]) by smtp.gmail.com with ESMTPSA id s13sm16372072uaj.6.2019.08.05.06.44.04 for (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Mon, 05 Aug 2019 06:44:04 -0700 (PDT) Received: by mail-vs1-f52.google.com with SMTP id 190so55952379vsf.9 for ; Mon, 05 Aug 2019 06:44:04 -0700 (PDT) X-Received: by 2002:a67:8c84:: with SMTP id o126mr95423142vsd.122.1565012644482; Mon, 05 Aug 2019 06:44:04 -0700 (PDT) MIME-Version: 1.0 Reply-To: tanure@linux.com From: Lucas Tanure Date: Mon, 5 Aug 2019 14:43:53 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Question about mfd_add_devices and platform_data To: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, I would like to understand mfd_add_devices call and platform_data section. An mfd device can have platform_data, which is kmemdup at platform_device_add_data from platform_device_add_data call inside mfd_add_device. And after this kmemdup the new mfd device receives the clone memory and the pointer given to platform_device_add_data is freed. All the drivers I read the platform_data is static, which in my view can not be freed and kfrees says: "Don't free memory not originally allocated by kmalloc() or you will run into trouble." So, my questions is : Should my driver kmalloc platform_data first and then call mfd_add_devices ? Or it's fine to give static memory to it ? Example driver: drivers/mfd/vexpress-sysreg.c: static struct syscon_platform_data vexpress_sysreg_sys_id_pdata = { .label = "sys_id", }; static struct mfd_cell vexpress_sysreg_cells[] = { { .name = "syscon", .num_resources = 1, .resources = (struct resource []) { DEFINE_RES_MEM(SYS_ID, 0x4), }, .platform_data = &vexpress_sysreg_sys_id_pdata, .pdata_size = sizeof(vexpress_sysreg_sys_id_pdata), }, For this case mfd_add_devices will free vexpress_sysreg_sys_id_pdata, but it's static. Thanks Lucas